#6 Arduino Mega: IR Obstacle Counter displayed using Bluetooth Communication (HC-05) on Android Mobile

IoT Tutorial #6 [ Arduino Mega Tutorials #6 ]
Here I will demonstrate the mini project, Counting obstacles / people using IR sensor and displaying the counter on android mobile using Bluetooth communication through the HC-05 module using Arduino Mega (ATMega 2560).

Problem Statement:
Count the obstacles / people using IR sensor and display the counter on Android mobile using Bluetooth Communication.

- Arduino Mega (ATMega 2560)
- USB Cable (A to B)
- Digital IR Sensor Module (ACK-SENSOR-IR-OBS-ARD)
  (Output of Module: 0 -> Obstacle Detected, 1 -> No Obstacle)
- Android Mobile (with Bluetooth Terminal installed in it)
- 1 LED
- 1k Resistor
- Bread Board
- Male to Male wires (minimum 6)

Program Outcome:
Output is shown using LED
If Obstacle detected -> LED ON
If No Obstacle       -> LED OFF

> Counter is incremented by 1 for every obstacle. 
  (Irrespective of the time for which obstacle is present)

> If Obstacle is detected then message and counter 
  is displayed on Arduino Terminal on Desktop using 
  serial communication (Tx0 and Rx0).
Program is written in such that the counter gets incremented 
by 1 only for 1 obstacle irrespective of the duration for 
which obstacle is present.

> In technical terms, De-bouncing effect is removed.

Physical Connection:
Arduino Mega  ->  IR Module 
Vcc           ->  IR Vcc 
Pin 3         ->  IR Out
Gnd           ->  IR Gnd

Pin 7 -> LED+  
Gnd   -> LED-

Arduino Mega  ->  Bluetooth Module 
Pin 18 (Tx1)  ->  Rx
Pin 19 (Rx1)  ->  Tx
Gnd           ->  GND
Vcc           ->  VCC (+5V)

Serial Communication through Bluetooth Module HC-05 (Tx1 and Rx1)
1. Install Bluetooth Terminal app (By Juan Sebastian Ochoa Zambrano) 
   on Android mobile from Play Store.
2. Make Physical Connections of the BLuetooth Module (HC-05) as given above.
3. On Android mobile, Search for Bluetooth and Connect to HC-05 and 
   pair it using password "0000" or "1234".
4. Open Bluetooth Terminal App on the Mobile and connect to paired HC-05 module.
Download link is given in the Description of the YouTube video shown below.



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //Tx0 and Rx0  //Set Baud Rate to 9600 for Serial Communication Tx0 and Rx0
  Serial1.begin(9600);  //Tx1 and Rx1  //Connected to Bluetooth Module HC-05 (Bluetooth 2.0)
  //Serial2;  //Tx2 and Rx2
  //Serial3;  //Tx3 and Rx3

  pinMode(13, OUTPUT);  //Set Pin 13 as Output (Connected to LED)

  Serial.println("press \"a\" or \"A\" to switch ON the LED");  //To Desktop
  Serial.println("press \"b\" or \"B\" to switch OFF the LED");
  Serial1.println("press \"a\" or \"A\" to switch ON the LED"); //To mobile
  Serial1.println("press \"b\" or \"B\" to switch OFF the LED");

void loop() {
  // put your main code here, to run repeatedly:
    int buffer_value = Serial1.read();
    if(buffer_value == 'a' || buffer_value == 'A')
      digitalWrite(13, HIGH);    //Turn ON LED
      Serial.println("LED ON");  //Arduino Terminal of Desktop 
      Serial1.println("LED ON"); //Bluetooth Terminal on Mobile
    else if(buffer_value == 'b' || buffer_value == 'B')
      digitalWrite(13, LOW);      //Turn OFF LED
      Serial.println("LED OFF");  //Arduino Terminal on Desktop
      Serial1.println("LED OFF"); //Bluetooth Terminal on Mobile 

Click here to see more codes for Arduino Mega (ATMega 2560) and similar Family.

Feel free to ask doubts in the comment section. I will try my best to solve it.
If you find this helpful by any mean like, comment and share the post.
This is the simplest way to encourage me to keep doing such work.

Thanks and Regards,
-Akshay P. Daga
Post a Comment (0)
Previous Post Next Post