--> Project V - 32. Read Ultrasonic Sensor Value Data using Android Device (Arduino Based) | basic arduino tutorial

Thursday, August 10, 2017

Project V - 32. Read Ultrasonic Sensor Value Data using Android Device (Arduino Based)

| Thursday, August 10, 2017
Read Ultrasonic Sensor Value Data using Android Device




Arduino UNO is used to measure the distance using ultrasonic SR04 ultrasonic sensors. The measurement data is displayed on HP Android. Data is sent via bluetooth connection using HC05 bluetooth module in serial communication.


Hardware Requirement
  • Modul Arduino Uno
  • HC-05 Bluetooth Module
  • Ultrasonic Sensor HC-SR04
  • Power supply +5 Volt
  • Jumper



                    Ultrasonic HC-SR04 Sensor (Source)         Bluetooth HC-05 Sensor (Source)

Block Diagram


Schematic



Arduino - HC-SR04 Ultrasonic Sensor Wiring


Arduino - Bluetooth Module Wiring


Source Code/Sketch

#include <SoftwareSerial.h>
const int rxpin = 2;
const int txpin = 3;
SoftwareSerial hc05(rxpin, txpin);
int trig_pin = 8;
int echo_pin = 9;
long echotime;
float distance;
void setup() {
hc05.begin (9600);
pinMode(trig_pin, OUTPUT);
pinMode(echo_pin, INPUT);
digitalWrite(trig_pin, LOW);
}
void loop() {
digitalWrite(trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(trig_pin, LOW);
echotime= pulseIn(echo_pin, HIGH);
distance= 0.0001*((float)echotime*340.0)/2.0;
hc05.print("*T"+String(echotime)+"*");
hc05.print("*D"+String(distance,1)+"*");
if (distance<20) hc05.print("*LR255G0B0*"); //Red
if (distance>=20&&distance<=50) hc05.print("*LR255G200B0*"); //Orange
if (distance>50) hc05.print("*LR0G255B0*"); //Green
delay(100);
}


How it Works
1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino

4. Open the Android Bluetooth Electronics Apps
5. Connect bluetooth by select connect button on the top right corner


6. Select Discover tab > Pair > Select HC-05 > Connect > Done


    If the Bluetooth module can't read by Apps, try to connect it manually.(Default setting bluetooth)


7. Select Ultrasonic Distance Sensor panel and tap run button


8. The result measurements of the ultrasonic sensor will show in Time and distance data, and the
     circke on the right panel, the color will change depend by how far distance that measured.







Video for Project V - 32. Read Ultrasonic Sensor Value Data using Android Device (Arduino Based)





Required File


Related Posts

2 comments:

  1. i have follow your instruction, the bluetooth connected but the sensor seems got nothing, can you help me solve it?

    ReplyDelete
  2. Thank you very much for this informative instruction. It's working great!!

    ReplyDelete