Monitoring Sensor Data on Android Phone

Cell phones are very common nowadays and every new technology is connecting and overlapping with the mobile domain these days. Even many embedded systems projects are under development, which involve the use of smartphones . This project deals with monitoring sensor data on an Android phone. The sensors used in the project are LDR and DHT 11, which allow monitoring light intensity, temperature and humidity. The sensors are interfaced to an Arduino Pro Mini which relays the data to an Android phone with the help of an HC-05 Bluetooth Module.
The project also involves the development of a mobile application built on MIT App Inventor. The software allows you to develop a mobile application just by creating the interface and integrating code blocks. The application developed for the project can be downloaded from Garagem dos Engenheiros.
The project's Arduino code reads the sensor data and transmits it to the Android phone via the Bluetooth module. HC-05 is a Bluetooth serial module that transmits or receives data serially. The data is displayed in a single activity app under the headings of temperature, humidity and light intensity. The same data is also displayed on an LCD display.

Required components –

• Arduino PRO MINI
•LCD 16×2
• HC-05 Bluetooth Module
• DTH 11 sensor
• LDR sensor
• 7805 voltage regulators
• 5mm LED
• 1K ohm resistor

Block diagram –

Diagrama de blocos do monitor de dados de sensor controlado por Bluetooth baseado em Arduino
Fig. 1: Block diagram of Arduino based Bluetooth controlled sensor data monitor

Circuit Connections –

Protótipo de monitor de dados de sensor controlado por Bluetooth baseado em Arduino

Fig. 2: Arduino-based Bluetooth controlled sensor data monitor prototype

The project involves an Arduino-based circuit and an Android phone. The Arduino based circuit is assembled as follows –

Power supply – Power is supplied by an 18V battery. The battery supply is regulated to 5V DC using the 7805 voltage regulator IC. The IC has three pins – pin 1 must be connected to the battery anode, pins 2 and 3 to the cathode (common ground). The 5V DC must be taken from pin 3 of the IC. An LED along with a 10K Ω pull-up resistor can also be connected between the common ground and the output pin to get a visual cue of power continuity.
16X2 LCD: 16X2 LCD display is used to display sensor data. It is connected to the Arduino board by connecting its data pins to pins 2 to 5 of the Arduino board. The RS and E pins of the LCD are connected to pins 13 and 12 of the Arduino UNO respectively. LCD RW pin is grounded.
Tabela listando conexões de circuito entre Arduino Uno e Character LCD
Fig. 3: Table listing circuit connections between Arduino Uno and Character LCD
The open source standard library for interfacing the LCD with the Arduino board is used in the project. The library works as expected and does not need any changes or modifications.
DHT-11 Temperature and Humidity Sensor – The DHT-11 sensor reads the ambient temperature and humidity and relays the data to the microcontroller as digital data. The data pin of the DHT11 temperature and humidity sensor is connected to the A0 pin of the Arduino Pro Mini, and the VCC and ground are connected to the common VCC and ground.
LDR sensor – The LDR is used to detect light intensity. The sensor is connected to pin A1 on the Arduino board. The sensor is connected to a potential divider circuit. The LDR provides an analog voltage that is converted to a digital readout by the built-in ADC.
HC-05 Bluetooth Module – The HC-05 Bluetooth module is a serial port protocol module. Operates in the 2.4 GHz ISM band with V2.0 + EDR (Enhanced Data Rate). It can work in Master and Slave modes. The Bluetooth module has six pins – Enable, VCC, Ground, Transmit Data (TxD), Receive Data (RxD) and State. The Enable and State pins are unused and therefore not connected to the circuit. The VCC and Ground pins are connected to common VCC and Ground. The TxD and RxD pins of the module are connected to pins 8 and 9 of the Arduino Pro Mini respectively.

How the circuit works –

Imagem do monitor de dados de sensor controlado por Bluetooth baseado em Arduino

Fig. 4: Image of Arduino-based Bluetooth-controlled sensor data monitor

When the circuit is turned on, the Arduino board loads the necessary libraries and starts fetching data from the DHT-11 temperature and humidity sensor and the LDR sensor. The DHT11 Temperature and Humidity Sensor is a digital sensor with a built-in capacitive humidity sensor and thermistor. It transmits a real-time temperature and humidity reading every 2 seconds. The sensor operates with a power supply of 3.5 to 5.5 V and can read temperatures between 0° C and 50° C and relative humidity between 20% and 95%.

The sensor cannot be connected directly to a digital pin on the board, as it operates on the 1-wire protocol that must only be implemented in the firmware. First, the data pin is configured for input and a start signal is sent to it. The start signal comprises a LOW for 18 milliseconds followed by a HIGH for 20 to 40 microseconds followed by a LOW again for 80 microseconds and a HIGH for 80 microseconds.
After sending the start signal, the pin is configured for digital output and the 40-bit data consisting of temperature and humidity reading is locked. Of the 5-byte data, the first two bytes are the integer and decimal part of the relative humidity reading respectively, the third and fourth bytes are the integer and decimal part of the temperature reading, and the last is the checksum byte .
For Arduino, the standard library for the DHT-11 sensor is now available. Sensor data can be easily prepared by calling the read11 method of the DHT class.
The LDR sensor is connected to a potential divider circuit and inputs a voltage to the controller's analog input pin. The voltage is read and digitized using the built-in ADC channel.
The Arduino sketch stores the sensor data in a set of global variables and transfers it to the Bluetooth module in a formatted string via serial communication. The same data is sent to the LCD module for display. The mobile app on the Android phone must be paired with the Bluetooth module. The Bluetooth module used in the project had a Mac address 05 20:15:01:30:17:25 for its unique identification and a password 1234 for pairing. Other Bluetooth modules also have Mac addresses and passwords for identification and pairing with other devices respectively. After the Android phone is paired with the Bluetooth module in the circuit, the serially transmitted data from it will be displayed in the main activity of the custom application.
Sensor data transmission is maintained uninterrupted in the project and displays temperature, humidity, and light intensity headers in the main application activity.
Check out the program code to see how Arduino reads data from the DHT 11 and LDR sensor and transmits it serially through the Bluetooth module.

Programming guide –

The Arduino sketch imports the SoftwareSerial library for virtual serial communication with the Bluetooth module, the LiquidCrystal library for LCD interfacing, and DHT.h for handling temperature and humidity sensors. An LED pin is declared to test the transmission progress, and an object of type DHT is declared. An object for virtual serial communication is declared and mapped onto the pins connected to the Bluetooth module. An LCD-type object is instantiated and mapped with the respective Arduino pins. Variables to hold temperature, humidity, and light intensity values ​​are declared.
A setup function is called in which the baud rate for serial communication with the Bluetooth module and LCD is set to 9600 bits per second and some initial text strings are printed on the LCD module.
Captura de tela da função de inicialização e configuração no código Arduino para monitor de dados de sensor controlado por Bluetooth
Fig. 5: Screenshot of initialization and configuration function in Arduino code for Bluetooth controlled sensor data monitor
The loop function is called in which sensor data is read using standard library functions and stored in respective variables. Values ​​stored in variables are displayed on the LCD and serially transmitted to the Bluetooth module for sending to the mobile application. The mobile app receives the values ​​transmitted via Bluetooth and displays them in the main app activity.
Captura de tela da função Loop no monitor de dados do sensor controlado por Bluetooth
Fig. 6: Screenshot of the Loop function in the Bluetooth-controlled sensor data monitor
You will find the complete code for Sensor Data Monitoring in the Android Project in the source code tab.
Note: You can find the Sensor Data Mobile App rar file in the attachment below.

Project source code

###

 //Program to
 #include //Software Seral library

 #include

 #include

 const int ledPin = 13; // LED's

 dht DHT;

 #define dht_dpin A0

 SoftwareSerial BTserial(8,9); // RX TX

 LiquidCrystal lcd(13, 12.5, 4, 3.2);// Pins used for RS,E,D4,D5,D6,D7

 int humi,temp,data;

 void setup {

 Serial.begin(9600);

 BTserial.begin(9600);

 lcd.begin(16,2);

 lcd.setCursor(0,0);

 lcd.print("Engineers Garage");

 lcd.setCursor(0,1);

 lcd.print(" BT CONNECTION ");

 delay(3000);

 lcd.setCursor(0,1);

 lcd.print(" ");

 }



 void loop {

 digitalWrite(ledPin, HIGH);

 DHT.read11(dht_dpin); //read DTH11 data

 data = analogRead(A1);

 humi = DHT.humidity; // DTH11 Humidity sensor data

 temp = DHT.temperature; // DTH11 Temperature sensor data

 lcd.setCursor(0,1);

 lcd.print(humi);
 
lcd.setCursor(7,1);

 lcd.print(temp);

 lcd.setCursor(13,1);

 lcd.print(data);

 BTserial.println(humi);

 Serial.println(humi);

 BTserial.print(" ");

 BTserial.println(temp);

 Serial.println(temp);

 BTserial.print(" ");

 BTserial.println(data);

 Serial.println(data);

 delay(1000);

 digitalWrite(ledPin, LOW);

 delay(50);

 }

###

Project video

Back to the blog

Leave a comment

Comments need to be approved before publication.