Download as pdf or txt
Download as pdf or txt
You are on page 1of 131

Robotics Kit

DIY Kit

PROJECT MANUAL

IOTtech Smart IN COLLABORATION WITH Rank2TOP


PRODUCTS PVT. LTD.

2
Assembly Instructions for Robotics Kit
Components Required:
Robotic PCB – Designed by Yantram
Free Wheel and Spacers
DC Gear Motor with Wheels
Ultrasonic Sensor with Frame
Servo Motor and Spacers
LCD Display and Spacers
ESP – 32 Module
Jumper Wires
Battery

1. Mount the Free Wheel and Free Spacers:


1 Free Wheel
4 5 mm M3 screws
4 M3 nuts

Determine the top of the baseplate; it is not symmetric.


Attach the swivel to the bottom of the baseplate using the screws and nuts.

2. Mount the DC Gear Motors with PCB and Wheels:


2 motors
2 10 cm wires, black
2 10 cm wires, red
4 acrylic tabs
4 30 mm M3 screws
4 M3 nuts 2 Wheels
Solder one red and one black wire to each motor. Either terminal can be either colour.
Place one tab in a slot down from the top of the baseplate, align the motor, and place the
other tab on the slot on the side of the baseplate.
Insert two screws from the outside tab through the motor and inside tab and connect the nuts.
Repeat the procedure for the other motor
Mount the wheels on the motors

2
3. Connect the Servo Motors:
Servo motor
18 mm pan-head screw
White two-arm servo
connector

Locate the servo motor between the freewheel and the PCB. Position the servo motor
underneath the PCB and secure it using screws (net bolts). This will help keep the servo
motor in place. This placement is important for the proper functioning of the robotic system.

Once the servo motor is set up, make sure to secure it further by screwing in the spacers
provided. This will provide additional stability and support for the servo motor.

4. Connect the LCD Display with Spacer:


For the LCD display (LCD–1) in the robotics kit, connect the male pins of the LCD to the
corresponding female sockets on our kit. You can use the spacers provided to secure the
LCD in place.

5. Connect ESP-32 Module:

Connect the ESP32 module to the designated space on the robotics kit. Ensure a secure
connection is made.

6. Connect Ultrasonic Sensor:

3
Ultrasonic sensor base Ultrasonic
sensor sides
23 mm self-tapping screws
27 mm self-tapping screws

7. Trouble Shooting:

Hold the robot off the ground and plug the USB cable between the ESP32 and your
computer.
You should see power lights on the ESP32 and the Sensor Shield. If you don’t see all three
lights, check the power wiring.
Shortly after the robot is turned on or reset, it centres the servo
If the servo does not move, verify you have connected the servo to location 11 and the orange
wire is connected to “S.”
If the servo moves but isn’t in the centre, remove the ultrasonic sensor mount from the board,
disconnect the servo from the base, and reattach the servo in the proper location.

Disconnect the robot from the computer, turn off the power switch, and plug in 4 AA
batteries to the holder on the bottom. Turn on the power switch.

4
Table of Content
S.No. Project Name Page No.

1 Bluetooth-Controlled Robot (Mobile App Based) 6 – 12

2 Wi-fi Controlled Robot (Mobile App Based) 13 – 19

3 Carbon Mono Oxide Reader through ESP32 (Mobile App Based) 20 – 24

4 Hydrogen reader through ESP32 (Mobile App Based) 25 – 29

5 LPG Reader through ESP32 (Mobile App Based) 30 – 35

6 Propane Reader through ESP32 (Mobile App Based) 36 – 41

7 Temperature & Humidity Reader (Mobile App Based) 42 – 45

8 Wi-Fi Robot with Voice Command (Mobile App Based) 46 – 52

9 Bluetooth Robot with Voice Command (Mobile App Based) 53 – 57

10 IR Sensor-Based Obstacle Detection (Mobile App-Based) 58 – 62

11 Servo Motor Control in Robotics (Mobile App Based) 63 – 68

12 Ultrasonic Distance Meter (Mobile App Based) 69 – 74

13 Gesture Control through Wi-Fi (Mobile App Based) 75– 81

14 Bluetooth Controlled robot with Seat Belt 82 – 90

15 Dancing Car 91 – 96

16 Line Follower Robot 97 – 101

17 Obstacle Avoiding Robot 102 – 110

18 Danger Detection Robot 111– 115

19 Robotic Radar 116 – 120

20 Accident Preventor with Pre-warning 121 – 130

5
Project-1
Bluetooth-Controlled Robot (Mobile App Based)
Introduction:
This project introduces a motor control system using an ESP32 development board, an LCD
display module, and the built-in Bluetooth functionality of the ESP32. The objective is to
wirelessly control the motor's direction and speed through a paired Bluetooth-enabled device.
The project offers a convenient and efficient solution for robotics and automation applications.
By leveraging the ESP32's capabilities, users can enjoy seamless wireless motor control.
Materials and Components:
To replicate this project, the following components are required:

1. ESP32 development board: The ESP32 serves as the main controller and utilizes its
built-in Bluetooth module for wireless communication.
2. LCD display module: An I2C-based LCD display provides visual feedback on the
motor's operation and the received Bluetooth commands.
3. Geared DC motor: The motor acts as the main actuator and is controlled based on
Bluetooth commands.
4. Jumper wires: Male-to-male and male-to-female jumper wires are used to establish
connections between the components.
5. USB cable: A USB cable (Type A to micro-USB or Type C) powers the ESP32
board and uploads the code.
Pin Configuration:
The pin configuration for this project is as follows:
LCD Display:

SDA (data) pin of the LCD display to any available GPIO pin on the ESP32 (e.g., pin
21).
SCL (clock) pin of the LCD display to any available GPIO pin on the ESP32 (e.g., pin
22).
Motor Control:

in1 pin of the motor driver module to ESP32 pin 27 (or any available GPIO pin).
in2 pin of the motor driver module to ESP32 pin 26 (or any available GPIO pin).
in3 pin of the motor driver module to ESP32 pin 25 (or any available GPIO pin).
in4 pin of the motor driver module to ESP32 pin 33 (or any available GPIO pin).

6
Libraries Used:
The project utilizes the following libraries:

1. Wire.h: This library enables I2C communication between the ESP32 and the LCD
display.
2. LiquidCrystal_I2C.h: This library facilitates the use of I2C-based LCD displays
with the ESP32.

Program:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f,16,2);

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)


#error Bluetooth is not enabled! Plear run make menuconfig to and enable it
#endif

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.

7
#endif

int ch=0;
BluetoothSerial SerialBT;

#define in1 27
#define in2 26
#define in3 25
#define in4 33

void setup()
{
lcd.begin();
lcd.clear();
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("**IOTTECH**");
lcd.setCursor(2,1);
lcd.print("SMART PRODUCTS");

delay(1500);

Serial.begin(115200);
SerialBT.begin("Rank2Top");
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
}
void loop()
{

//
char r;

if(SerialBT.available())
{
r=SerialBT.read();

if(r=='F')
{
ch=1;
lcd.clear();
lcd.backlight();
lcd.setCursor(4,0);
lcd.print("FORWARD");

8
//Serial.println("CH==1 means forward");
}
else if(r=='B')
{
ch=2;
lcd.clear();
lcd.backlight();
lcd.setCursor(4,0);
lcd.print("BACKWARD");
//Serial.println("CH==2 means backward");
}
else if(r=='R')
{
ch=3;
lcd.clear();
lcd.backlight();
lcd.setCursor(5,0);
lcd.print("RIGHT");
//Serial.println("CH==3 means right");
}
else if(r=='L')
{
ch=4;
lcd.clear();
lcd.backlight();
lcd.setCursor(6,0);
lcd.print("LEFT");
//Serial.println("CH==4 means left");
}
else if(r=='S')
{
ch=5;
lcd.clear();
lcd.backlight();
lcd.setCursor(6,0);
lcd.print("STOP");
//Serial.println("CH==5 means motor stopped");
}
}
delay(20);
switch(ch)
{

case 1: digitalWrite(in1, 0);


digitalWrite(in2, 1);
digitalWrite(in3, 0);
digitalWrite(in4, 1);

9
break;

case 2: digitalWrite(in1, 1);


digitalWrite(in2, 0);
digitalWrite(in3, 1);
digitalWrite(in4, 0);

break;

case 3: digitalWrite(in1,1);

digitalWrite(in2,0);

digitalWrite(in3, 0);

digitalWrite(in4, 1);

break;

case 4: digitalWrite(in1, 0);

digitalWrite(in2, 1);

digitalWrite(in3, 1);

digitalWrite(in4, 0);

break;

case 5: digitalWrite(in1,LOW);

digitalWrite(in2,LOW);

digitalWrite(in3,LOW);

digitalWrite(in4,LOW);

break;

default: break;
}
Serial.println(r);
delay(20);
}

10
Working:
1. Initialization:
The setup () function initializes the LCD display, Bluetooth
communication, and pin modes for motor control.
The LCD display is cleared, and a startup message is displayed to indicate the system's
readiness.
Serial communication is set up to enable monitoring of received Bluetooth commands.
The ESP32's built-in Bluetooth module is initialized, allowing it to pair with a
Bluetooth-enabled device.
The pin modes for motor control (in1, in2, in3, in4) are set to OUTPUT.

2. Loop Execution:
The loop () function continuously checks for available data from the ESP32's
Bluetooth module.
If data is received, it is processed to determine the corresponding motor action
(e.g., forward, backward, right, left, stop).
The LCD display is updated to reflect the current motor action for visual feedback.
Based on the motor action, the appropriate GPIO pins are set to control the motor's
behavior.
The motor moves accordingly based on the received command or stops when the
'S' command is received.
The received character is printed on the Serial Monitor for debugging purposes.

3. Motor Control:
The motor driver module receives the control signals from the ESP-32 board to control
the motor's behavior.
Depending on the received command, the appropriate GPIO pins (in1, in2, in3, in4) are
set to control the motor's direction and speed.
For example, to make the motor move forward, pins in1 and in4 are set to HIGH,
while pins in2 and in3 are set to LOW.
Different combinations of pin states are used to control other motor actions such as
backward, right, left, and stop.

4. LCD Display:

The LCD display module provides real-time visual feedback on the motor's operation
and the received Bluetooth commands.
The display is updated with the current motor action (e.g., FORWARD,
BACKWARD, RIGHT, LEFT) based on the received commands.
This allows users to clearly understand the motor's movement and the applied
commands.

11
5. Serial Monitor:
The Serial Monitor in the Arduino IDE is used to monitor the received character
('r') from the ESP32's Bluetooth module.
It displays the received character, verifying the correct interpretation of the received
commands and assisting in debugging, if necessary.
Conclusion:
In conclusion, this project demonstrates the implementation of a wireless motor control system
using an ESP32 board, an LCD display module, and built-in Bluetooth functionality. By
leveraging the ESP32's capabilities, users can wirelessly control the motor's direction and speed
using a paired Bluetooth-enabled device. The LCD display provides real-time feedback on the
motor's operation, enhancing the user experience and making it suitable for robotics and
automation projects.

12
Project-2
Wi-Fi Controlled Robot (Mobile App based)
Introduction:
The Smart Robocar project aims to create a remotely controlled car using ESP32, Firebase, and
motor control. The system allows users to control the car's movement (forward, backwards, left,
right, and stop) through a mobile application connected to the Firebase real-time database. The
ESP32 development board receives the control commands from Firebase and controls the geared
motors accordingly.
Apparatus Required:

ESP32 Development Board: The ESP32 serves as the main controller and provides the
necessary processing power and Wi-Fi connectivity.
Geared Motors: Geared motors are used to drive the car's wheels for movement.
Motor Control IC: A motor control IC is utilized to control the speed and direction of
the geared motors.
Custom Designed PCB: A custom-designed PCB is used for circuit
connections and mounting the components.
Liquid Crystal Display (LCD): An LCD display is used for visual feedback
and status display.

13
Libraries Used:

1. Wire.h: The library for I2C communication is used for connecting the LCD display.
2. LiquidCrystal_I2C.h: The library for controlling the LCD using the I2C
communication protocol.
3. FirebaseESP32.h: The Firebase library for interfacing with the Firebase real-time
database.

Program (Code):

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 16, 2);

#include "FirebaseESP32.h"

#define WIFI_SSID "Rank2Top"

#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"

#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

FirebaseData firebaseData;

#define in1 27

#define in2 26

#define in3 25

#define in4 33

int ch;

String your_ID = "9876543210";// your mobile number

void setup()

Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to Wi-Fi");

while (WiFi.status() != WL_CONNECTED)

Serial.print(".");

14
delay(300);

Serial.println();

Serial.print("Connected with IP: ");

Serial.println(WiFi.localIP());

Serial.println();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

lcd.begin();

lcd.clear();

lcd.backlight();

lcd.setCursor(2, 0);

lcd.print("**IOTTECH**");

lcd.setCursor(2, 1);

lcd.print("SMART PRODUCTS");

delay(2000);

Serial.println("The device started, now you can connect using Firebase!");

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT);

void loop()

String r;

Firebase.getString(firebaseData, "IOTtech/RoboKIT/"+your_ID+"/Robocar/State");

r = (firebaseData.stringData());

Serial.println(r);

if (r == "B")

15
ch = 2;

lcd.clear();

lcd.backlight();

lcd.setCursor(4, 0);

lcd.print("BACKWARD");

Serial.println("CH==2 means backward");

if (r == "F")

ch = 1;

lcd.clear();

lcd.backlight();

lcd.setCursor(4, 0);

lcd.print("FORWARD");

Serial.println("CH==1 means forward");

if (r == "L")

ch = 4;

lcd.clear();

lcd.backlight();

lcd.setCursor(6, 0);

lcd.print("LEFT");

Serial.println("CH==4 means left");

if (r == "R")

ch = 3;

lcd.clear();

lcd.backlight();

16
lcd.setCursor(5, 0);

lcd.print("RIGHT");

Serial.println("CH==3 means right");

if (r == "S")

ch = 5;

lcd.clear();

lcd.backlight();

lcd.setCursor(6, 0);

lcd.print("STOP");

Serial.println("CH==5 means motor stopped");


}
switch (ch)
{
case 1: digitalWrite(in1, 0);
digitalWrite(in2, 1);
digitalWrite(in3, 0);
digitalWrite(in4, 1);
break;

case 2: digitalWrite(in1, 1);


digitalWrite(in2, 0);
digitalWrite(in3, 1);
digitalWrite(in4, 0);

break;

case 3: digitalWrite(in1,1);

digitalWrite(in2,0);

digitalWrite(in3, 0);

digitalWrite(in4, 1);

break;

case 4: digitalWrite(in1, 0);

digitalWrite(in2, 1);

digitalWrite(in3, 1);

digitalWrite(in4, 0);

17
break;

case 5: digitalWrite(in1,LOW);

digitalWrite(in2,LOW);

digitalWrite(in3,LOW);

digitalWrite(in4,LOW);
break;

default: break;
}
}

Working:

1. Initialization: The ESP32 development board is initialized, and the necessary pins for
motor control are set as OUTPUT.
2. Wi-Fi Connection: The system connects to the specified Wi-Fi network using the provided
credentials.
3. Firebase Initialization: The Firebase real-time database is initialized with the specified
host and authentication details.
4. LCD Display: The LCD display is initialized and shows the startup message
"IOTTECH" and "SMART PRODUCTS."
5. Control Processing: The system continuously checks the Firebase database for the control
state of the Robocar. The control state is obtained as a string value.
6. Control Actions: Depending on the control state received from Firebase, the system
performs the corresponding motor control actions. For example, if the control state is "F"
(forward), the motors are controlled to move the car forward. Similarly, different control
states correspond to different motor actions (backward, left, right, stop).
7. LCD Feedback: The LCD display is updated with the current control state to provide
visual feedback.
8. Loop Continuation: The loop continues, continuously checking the Firebase database for
control state updates and performing the corresponding motor control actions.

18
Testing:

1. Connect the ESP32 development board to a power source and ensure it is properly
programmed with the provided code.
2. Make sure you have a stable Wi-Fi network available and update the WIFI_SSID and
WIFI_PASSWORD variables in the code with your network's SSID and password.

3. Connect the geared motors to the specified motor control pins (in1, in2, in3, in4) on the ESP32
board.Connect the LCD display to the I2C interface on the ESP32 board.

4. Power on the system and observe the LCD display.

5. The system should establish a Wi-Fi connection and display the startup message on the LCD.

6. Use a separate device with internet access to update the control state of the Robocar in the Firebase
database. You can set the control state to "F" for forward, "B" for backward, "L" for left, "R" for
right, or "S" for stop.

7. Observe the LCD display to verify that the control state is being updated and displayed correctly.
Conclusion:
The Smart Robocar project successfully integrates ESP32, Firebase, and motor control to create
a remotely controlled car. By connecting to the Firebase real-time database, users can control the
car's movement through a mobile application or any device with internet access.

19
Project-3
Carbon Mono Oxide Reader through ESP32
(Mobile App Based)
Introduction:
The Carbon Monoxide Monitoring System project aims to create a wireless system that can
monitor carbon monoxide levels and upload the data to a Firebase database for remote
monitoring and analysis. The system utilizes an ESP32 development board, a carbon monoxide
sensor, and Firebase's real-time database. The objective is to provide an efficient and reliable
solution for monitoring carbon monoxide levels in an environment.
Apparatus Required:

ESP32 Development Board: The ESP32 serves as the main controller and provides the
necessary processing power and Wi-Fi connectivity.
Carbon Monoxide Sensor: A carbon monoxide sensor is used to measure the
concentration of carbon monoxide in the environment.
Custom Designed PCB: A custom-designed PCB is used for circuit
connections and mounting the components.
Motor Control IC: A motor control IC is utilized to control the motors' speed and
direction. The specific IC used can be specified based on the design requirements.
Liquid Crystal Display (LCD): An LCD is used to display the carbon monoxide
readings.
Libraries Used:

1. Arduino.h: The standard Arduino library for general-purpose functions and


communication with the ESP32 board.
2. WiFi.h: The library for connecting to a Wi-Fi network and establishing an internet
connection.
3. FirebaseESP32.h: The Firebase library for interfacing with the Firebase real-time
database.
4. LiquidCrystal_I2C.h: The library for controlling the LCD using the I2C
communication protocols.
5. Links: FirebaseESP32 library: [https://github.com/mobizt/Firebase-
ESP32](https://github.com/mobizt/Firebase-ESP32)

20
Working:
The Carbon Monoxide Monitoring System continuously monitors carbon monoxide levels and
uploads the data to a Firebase database for remote access and analysis.
Here's how it works:

Initialization: The ESP32 development board is initialized, and the necessary


pins are configured. Wi-Fi connectivity is established by connecting to the
specified network.
Sensor Reading: The carbon monoxide sensor's analog output is read using the
`analogRead()` function. The raw sensor value is then mapped to a meaningful range
using the `map()` function.
Data Upload: If the specified delay (5000 milliseconds) has elapsed, the current carbon
monoxide reading is uploaded to the Firebase database using the `Firebase.setInt()`
function.
Display: The carbon monoxide reading is displayed on the LCD screen using the
`lcd.print()` function.
Loop Continuation: The loop continuously monitors and uploads data at the
specified interval.

21
Program:

#include <Arduino.h>
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <LiquidCrystal_I2C.h>

/////////Change this ID before Uploading/////////////////////////////////////////////////////////


String your_ID = "9876543210";
//Definations
#define WIFI_SSID "Rank2Top" //WiFi Credentials
#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"


#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

//Pin
#define sensor_pin 34

//Objects
FirebaseData firebaseData;
LiquidCrystal_I2C lcd(0x3f, 16, 2);

//Variable
int sens_val;
const int delayp = 5000;
unsigned long time_now = 0;

void setup() {
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
pinMode(sensor_pin, INPUT);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(200);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

while (WiFi.status() != WL_CONNECTED)


{
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
lcd.print("Connected");

22
delay(2000);

// Print the IP address


/*Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");*/

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
lcd.clear();
}

void loop() {
sens_val = analogRead(sensor_pin);
sens_val = map(sens_val, 0, 4095, 200, 700);
if(millis() >= time_now + delayp){
time_now += delayp;
Firebase.setInt(firebaseData,"IOTtech/RoboKIT/" your_ID + "/Sensors/MQ7/Carbon_Monoxide",
sens_val);
}

lcd.setCursor(0,0);
lcd.print("Carbon Monoxide:-");
lcd.setCursor(0,1);
lcd.print(sens_val);
delay(500);
}

Testing:

1. Power up the system: Connect the power supply to the system and ensure that all
components are properly powered.
2. Wi-Fi connectivity: Verify that the system successfully connects to the specified
Wi-Fi network. Monitor the serial output to check for any error messages related to
Wi-Fi connectivity.
3. Sensor readings: Observe the LCD display to ensure that the carbon monoxide
readings are being displayed accurately. The readings should update every 5
seconds according to the specified delay.
4. Data upload: Monitor the serial output to check if the system successfully uploads the
carbon monoxide readings to the Firebase database. Cross- reference the readings
displayed on the LCD with the data stored in the Firebase database to verify their
accuracy.
5. Remote access: Access the Firebase database using the specified credentials and verify
that the carbon monoxide readings are being stored correctly. Check if the readings
correspond to the values displayed on the LCD.
6. Continuous monitoring: Keep the system running for an extended period of time and

23
observe its performance. Ensure that the system maintains stable Wi-Fi connectivity and
consistently uploads accurate carbon monoxide readings to the Firebase database.
7. System reliability: Test the system's reliability by subjecting it to different
environmental conditions and monitoring its performance. Introduce varying levels of
carbon monoxide in the vicinity of the sensor and verify if the system responds
accordingly and provides accurate readings.
8. User interface: Evaluate the user interface provided by the LCD display. Check if
the carbon monoxide readings are clearly visible and if the LCD backlight is
functioning properly.
9. Overall functionality: Assess the overall functionality of the Carbon Monoxide
Monitoring System by analyzing the accuracy of the readings, the stability of the Wi-Fi
connection, and the reliability of the data upload process.
Conclusion:
The Carbon Monoxide Monitoring System successfully monitors carbon monoxide levels and
provides real-time data upload to a Firebase database for remote monitoring and analysis. By
utilizing an ESP32 development board, a carbon monoxide sensor, and Firebase integration, the
system offers a reliable solution for monitoring carbon monoxide levels in an environment. The
working of the system ensures continuous monitoring, data collection, and display on the LCD
screen.
This project serves as a foundation for further enhancements and integrations to create a
comprehensive carbon monoxide monitoring and alert system.

24
Project-4
Hydrogen reader through ESP32
(Mobile App Based)

Introduction:
The Hydrogen Gas Monitoring System project aims to create a wireless system
that can monitor hydrogen gas levels and upload the data to a Firebase database for
remote monitoring and analysis. The system utilizes an ESP32 development board,
a hydrogen gas sensor, and Firebase's real-time database. The objective is to
provide an efficient and reliable solution for monitoring hydrogen gas levels in an
environment.
Apparatus Required:
1. ESP32 Development Board: The ESP32 serves as the main controller and
provides the necessary processing power and Wi-Fi connectivity.
2. Hydrogen Gas Sensor: A hydrogen gas sensor is used to measure the
concentration of hydrogen gas in the environment.
3. Custom-Designed PCB: A custom-designed PCB is used for circuit
connections and mounting the components.
4. Liquid Crystal Display (LCD): An LCD is used to display the hydrogen
gas readings.
Pin Configuration:
trigPin: Connected to pin 5 of the ESP32 board. It is set as an output pin to
send the trigger signal for the ultrasonic sensor.
echoPin: Connected to pin 18 of the ESP32 board. It is set as an input pin to
receive the echo signal from the ultrasonic sensor.
MOTOR1: Connected to pin 27 of the ESP32 board. It is set as an output pin to
control the direction of Motor 1.
MOTOR2: Connected to pin 26 of the ESP32 board. It is set as an output pin to
control the direction of Motor 2.
MOTOR3: Connected to pin 25 of the ESP32 board. It is set as an output pin to
control the direction of Motor 3.
MOTOR4: Connected to pin 33 of the ESP32 board. It is set as an output pin to
control the direction of Motor 4.
sensor_pin: Connected to pin 34 of the ESP32 board. It is set as an input pin to

25
read the analog output from the hydrogen gas sensor.

Libraries Used:
1. Arduino.h: The standard Arduino library for general-purpose functions and
communication with the ESP32 board.
2. WiFi.h: The library for connecting to a Wi-Fi network and establishing an
internet connection
3. FirebaseESP32.h: The Firebase library for interfacing with the Firebase
real-time database.

Program:

#include <Arduino.h>
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <LiquidCrystal_I2C.h>

/////////Change this ID before Uploading/////////////////////////////////////////////////////////


String your_ID = "9876543210";
//Definations
#define WIFI_SSID "Rank2Top" //WiFi Credentials
#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"


#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

26
//Pin
#define sensor_pin 34

//Objects
FirebaseData firebaseData;
LiquidCrystal_I2C lcd(0x3f, 16, 2);

//Variable
int sens_val;
const int delayp = 5000;
unsigned long time_now = 0;

void setup() {
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
pinMode(sensor_pin, INPUT);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(200);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

while (WiFi.status() != WL_CONNECTED)


{
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
lcd.print("Connected");
delay(2000);

// Print the IP address


/*Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");*/

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
lcd.clear();
}

void loop() {
sens_val = analogRead(sensor_pin);
sens_val = map(sens_val, 0, 4095, 200, 700);

27
if(millis() >= time_now + delayp){
time_now += delayp;
Firebase.setInt(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/Sensors/Hydrogen/value",
sens_val);
}

lcd.setCursor(0,0);
lcd.print("Hydrogen:-");
lcd.setCursor(0,1);
lcd.print(sens_val);
delay(500);
}

Working:
1. Initialization: The ESP32 development board is powered on and the necessary
pins are configured. Wi-Fi connectivity is established by connecting to the
specified network.
2. Sensor Reading: The hydrogen gas sensor's analog output is read using the
`analogRead()` function. The raw sensor value is then mapped to a meaningful
range of hydrogen gas concentrations.
3. Data Upload: If the specified delay has elapsed, the system uploads the
hydrogen gas reading to the Firebase database using the `Firebase.setInt()function.
This allows for real-time monitoring and analysis of the hydrogen gas levels.
4. LCD Display: The hydrogen gas reading is displayed on the LCD screen using
the `lcd.print()` function. The LCD backlight is also turned on using the
`lcd.backlight()` function.
5. Delay: The system waits for a specified delay of 500 milliseconds before
repeating the process.
By continuously reading the hydrogen gas sensor, uploading the data to Firebase,
and displaying the reading on the LCD screen, the system provides real-time
monitoring of hydrogen gas levels. The Firebase integration allows for remote
access and analysis of the data, making it a valuable tool for monitoring and
managing hydrogen gas environments.

6. Initialization: The ESP32 development board is powered on and the necessary


pins are configured. Wi-Fi connectivity is established by connecting to the
specified network.

7. Sensor Reading: The hydrogen gas sensor's analog output is read using the
`analogRead()` function. The raw sensor value is then mapped to a meaningful
range.
28
Testing:
To ensure the proper functioning of the Hydrogen Gas Monitoring System,
the following testing steps can be performed:
Power up the system: Connect the power supply to the system and ensure
that all components are properly powered.
Wi-Fi connectivity: Verify that the system successfully connects to the
specified Wi-Fi network. Monitor the serial output to check for any error
messages related to Wi-Fi connectivity.
Sensor readings: Observe the LCD display to ensure that the hydrogen gas
readings are being displayed accurately. The readings should update every 5
seconds according to the specified delay.
Data upload: Monitor the serial output to check if the system successfully
uploads the hydrogen gas readings to the Firebase database. Cross-reference
the readings displayed on the LCD with the data stored in the Firebase
database to verify their accuracy
Remote access: Access the Firebase database using the specified credentials
and verify that the hydrogen gas readings are being stored correctly. Check
if the readings correspond to the values displayed on the LCD.
Continuous monitoring: Keep the system running for an extended period of
time and observe its performance. Ensure that the system maintains stable
Wi-Fi connectivity and consistently uploads accurate hydrogen gas readings
to the Firebase database.
System reliability: Test the system's reliability by subjecting it to different
environmental conditions and monitoring its performance. Introduce varying
levels of hydrogen gas in the vicinity of the sensor and verify if the system
responds accordingly and provides accurate readings.
User interface: Evaluate the user interface provided by the LCD display.
Check if the hydrogen gas readings are clearly visible and if the LCD
backlight is functioning properly.

29
Project-5
LPG Reader through ESP32 (Mobile App Based)
Intro: LPG Monitoring System with Firebase Integration project aims to create a
wireless system that can monitor the LPG (liquefied petroleum gas) gas level in an
environment and upload the data to a Firebase database for remote monitoring and
analysis. The system utilizes an ESP32 development board, an LPG sensor, and the
Firebase real-time database. The objective is to provide an efficient and reliable
solution for monitoring LPG gas levels in order to ensure safety and enable
proactive maintenance.
Apparatus Required:
ESP32 Development Board: The ESP32 serves as the main controller and
provides the necessary processing power and Wi-Fi connectivity for data
transmission.
LPG Sensor: An LPG sensor is used to detect the LPG gas level in the
environment.
Custom Designed PCB: A custom-designed PCB can be used for circuit
connections and mounting the components, providing a compact and
organized setup.
Liquid Crystal Display (LCD): An LCD is used to display the LPG gas
level readings for local monitoring.
Libraries Used:
Arduino.h: The standard Arduino library for general-purpose functions and
communication with the ESP32 board.
WiFi.h: The library for connecting to a Wi-Fi network and establishing an
internet connection.
FirebaseESP32.h: The Firebase library for interfacing with the Firebase
real-time database.
LiquidCrystal_I2C.h: The library for controlling the LCD using the I2C
communication protocol.

30
Program (Code):

#include <Arduino.h>

#include <WiFi.h>

#include <FirebaseESP32.h>

#include <LiquidCrystal_I2C.h>

/////////Change this ID before Uploading/////////////////////////////////////////////////////////

String your_ID = "9876543210";

//Definations

#define WIFI_SSID "Rank2Top" //WiFi Credentials

#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"

#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

//Pin

31
#define sensor_pin 34

//Objects

FirebaseData firebaseData;

LiquidCrystal_I2C lcd(0x3f, 16, 2);

//Variable

int sens_val;

const int delayp = 5000;

unsigned long time_now = 0;

void setup() {

Serial.begin(9600);

lcd.begin();

lcd.backlight();

lcd.setCursor(0,0);

pinMode(sensor_pin, INPUT);

WiFi.mode(WIFI_STA);

WiFi.disconnect();

delay(200);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

while (WiFi.status() != WL_CONNECTED)

delay(500);

Serial.print("-");

32
Serial.println("");

Serial.println("WiFi Connected");

lcd.print("Connected");

delay(2000);

// Print the IP address

/*Serial.print("Use this URL to connect: ");

Serial.print("http://");

Serial.print(WiFi.localIP());

Serial.println("/");*/

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

Firebase.reconnectWiFi(true);

lcd.clear();

void loop() {

sens_val = analogRead(sensor_pin);

sens_val = map(sens_val, 0, 4095, 200, 700);

if(millis() >= time_now + delayp){

time_now += delayp;

Firebase.setInt(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/Sensors/LPG/value", sens_val);

lcd.setCursor(0,0);

lcd.print("LPG:-");

lcd.setCursor(0,1);

lcd.print(sens_val);

delay(500);

33
Working:
Initialization: The ESP32 development board is powered on, and the
necessary pins are configured. Wi-Fi connectivity is established by
connecting to the specified network.
Sensor Reading: The LPG sensor's analogue output is read using the
`analogRead()` function. The raw sensor value is then mapped to a
meaningful range using the `map()` function to obtain the LPG gas level.
Data Upload: If the specified delay has elapsed (every 5 seconds in this
case), the current LPG gas level reading is uploaded to the Firebase database
using the `Firebase.setInt()` function.
Display: The LPG gas level reading is displayed on the LCD using the
`lcd.print()` function for local monitoring.
Loop Continuation: The loop continues, and the process repeats, ensuring
continuous monitoring of the LPG gas level and data upload to Firebase.
Testing:
1. Connect the ESP32 development board to a power source and ensure it is
properly programmed with the provided code.
2. Ensure that the Wi-Fi credentials in the code are updated with your
network's SSID and password.
3. Connect the LPG sensor to the specified pin (sensor_pin) on the ESP32
board.
4. Connect the LCD display to the I2C interface on the ESP32 board.
5. Power on the system and observe the LCD display.
6. The system should establish a Wi-Fi connection and display "Connected" on
the LCD.
7. The LPG sensor will start reading the LPG gas level in the environment.
8. The LPG gas level reading will be displayed on the LCD as "LPG: [value]".
9. The LPG gas level reading will be uploaded to the specified Firebase
database every 5 seconds.
10. Monitor the Firebase database to ensure that the LPG gas level readings are
being uploaded correctly.
11. Observe the LCD display to verify that the LPG gas level readings are being
updated on the screen.
12. You can also use a separate device with internet access to view the Firebase
database and monitor the LPG gas level remotely.
13. Repeat the testing process in different environments to validate the system's
accuracy and reliability.

34
Conclusion:
The LPG Monitoring System with Firebase Integration successfully monitors the
LPG gas level and provides real-time data upload to a Firebase database for remote
monitoring and analysis. By utilizing an ESP32 development board, an LPG
sensor, and Firebase integration, the system offers a reliable solution for
monitoring LPG gas levels. The working of the system ensures continuous
monitoring, data collection, and display on the LCD screen.

35
Project-6
Propane Reader through ESP32 (Mobile App Based)

Introduction:
The Propane Gas Monitoring System with Firebase Integration project aims to
create a wireless system that can monitor the propane gas level in an environment
and upload the data to a Firebase database for remote monitoring and analysis. The
system utilizes an ESP32 development board, a propane gas sensor, and the
Firebase real-time database. The objective is to provide an efficient and reliable
solution for monitoring propane gas levels to ensure safety and enable proactive
maintenance.
Apparatus Required:
ESP32 Development Board: The ESP32 serves as the main controller and
provides the necessary processing power and Wi-Fi connectivity for data
transmission.
Propane Gas Sensor: A propane gas sensor is used to detect the propane
gas level in the environment.
Custom-Designed PCB: A custom-designed PCB can be used for circuit
connections and mounting the components, providing a compact and
organized setup.
Liquid Crystal Display (LCD): An LCD is used to display the propane gas
level readings for local monitoring.

36
Libraries Used:
1. WiFi.h: The library for connecting to a Wi-Fi network and establishing an
internet connection.=93.
2. FirebaseESP32.h: The Firebase library for interfacing with the Firebase
real-time database.
3. LiquidCrystal_I2C.h: The library for controlling the LCD using the I2C
communication protocol.
Program (Code):
#include <Arduino.h>
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <LiquidCrystal_I2C.h>

/////////Change this ID before Uploading/////////////////////////////////////////////////////////


String your_ID = "9876543210";
//Definations
#define WIFI_SSID "Rank2Top" //WiFi Credentials
#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"


#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

//Pin
#define sensor_pin 34

//Objects
FirebaseData firebaseData;
LiquidCrystal_I2C lcd(0x3f, 16, 2);

//Variable
int sens_val;

37
const int delayp = 5000;
unsigned long time_now = 0;

void setup() {
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
pinMode(sensor_pin, INPUT);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(200);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

while (WiFi.status() != WL_CONNECTED)


{
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
lcd.print("Connected");
delay(2000);

// Print the IP address


/*Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");*/

38
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
lcd.clear();
}
void loop() {
sens_val = analogRead(sensor_pin);
sens_val = map(sens_val, 0, 4095, 200, 700);
if(millis() >= time_now + delayp){
time_now += delayp;
Firebase.setInt(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/Sensors/Propane/value", sens_val);
}

lcd.setCursor(0,0);
lcd.print("Propane:-");
lcd.setCursor(0,1);
lcd.print(sens_val);
delay(500);
}

Working:
1. Initialization: The ESP32 development board is powered on and the
necessary pins are configured. Wi-Fi connectivity is established by
connecting to the specified network.

2. Sensor Reading: The propane gas sensor's analogue output is read using the
`analogRead()` function. The raw sensor value is then mapped to a
meaningful range using the `map()` function to obtain the propane gas level.

3. Data Upload: If the specified delay has elapsed (every 5 seconds in this
case), the current propane gas level reading is uploaded to the Firebase
database using the `Firebase.setInt()` function.

39
4. Display: The propane gas level reading is displayed on the LCD using the
`lcd.print()` function for local monitoring.

5. Loop Continuation: The loop continues, and the process repeats, ensuring
continuous monitoring of the propane gas level and data upload to Firebase.
Testing:
Connect the ESP32 development board to a power source and ensure it is
properly programmed with the provided code.
Update the Wi-Fi credentials in the code with your network's SSID and
password.
Connect the propane gas sensor to the specified pin (sensor_pin) on the
ESP32 board.
Connect the LCD display to the I2C interface on the ESP32 board.
Power on the system and observe the LCD display.
The system should establish a Wi-Fi connection and display "Connected" on
the LCD.
The propane gas sensor will start reading the propane gas level in the
environment.
The propane gas level reading will be displayed on the LCD as "Propane:
[value]".
The propane gas level reading will be uploaded to the specified Firebase
database every 5 seconds.
Monitor the Firebase database to ensure that the propane gas level readings
are being uploaded correctly.
Observe the LCD display to verify that the propane gas level readings are
being updated on the screen.
You can also use a separate device with internet access to view the Firebase
database and monitor the propane gas level remotely.
Repeat the testing process in different environments to validate the system's
accuracy and reliability.

40
Conclusion:
The Propane Gas Monitoring System with Firebase Integration successfully
monitors the propane gas level and provides real-time data upload to a Firebase
database for remote monitoring and analysis. By utilizing an ESP32 development
board, a propane gas sensor, and Firebase integration, the system offers a reliable
solution for monitoring propane gas levels. The working of the system ensures
continuous monitoring, data collection, and display on the LCD screen. This
project serves as a foundation for further enhancements and integrations to create a
comprehensive propane gas monitoring and alert system.

41
Project-7
Temperature & Humidity Reader (Mobile App Based)
Introduction:
The Temperature and Humidity Monitoring System project aims to create a
wireless system that can monitor temperature and humidity levels and upload the
data to a Firebase database for remote monitoring and analysis. The system utilizes
an ESP32 development board, a DHT11 sensor, and Firebase's real-time database.
The objective is to provide an efficient and reliable solution for monitoring
environmental conditions in real time.
Apparatus Required:
ESP32 Development Board: The ESP32 serves as the main controller and
provides the necessary processing power and Wi-Fi connectivity.
DHT11 Sensor: A DHT11 sensor is used to measure temperature and
humidity in the environment.
Custom-Designed PCB: A custom-designed PCB is used for circuit
connections and mounting the components.
Liquid Crystal Display (LCD): An LCD is used to display the temperature
and humidity readings.
Pin Configuration:
DHT11 Sensor:
Pin: 4 (Connected to the DHT11 sensor data pin)
LCD (LiquidCrystal_I2C):
I2C Address: 0x3F
Number of columns and rows: 16*2
Libraries Used:
1. Arduino.h: The standard Arduino library for general-purpose functions and
communication with the ESP32 board.
2. WiFi.h: The library for connecting to a Wi-Fi network and establishing an
internet connection.
3. FirebaseESP32.h: The Firebase library for interfacing with the Firebase real-
time database.

42
4. LiquidCrystal_I2C.h: The library for controlling the LCD using the I2C
communication protocol.
5. DHT.h: The library for interacting with the DHT11 sensor and reading
temperature and humidity values.

Program (Code):

#include <Arduino.h>
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>

/////////Change this ID before Uploading/////////////////////////////////////////////////////////


String your_ID = "9876543210";
//Definations
#define WIFI_SSID "Rank2Top" //WIFI CREDENTIALS
#define WIFI_PASSWORD "123456789"
#define DHTTYPE DHT11

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"


#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

//Pin
#define dht_pin 4

//Objects
FirebaseData firebaseData;
LiquidCrystal_I2C lcd(0x3f, 16, 2);
DHT dht(dht_pin, DHTTYPE);

43
//Variable
float temp_val;
float humid_val;
const int delayp = 5000;
unsigned long time_now = 0;

void setup() {
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
dht.begin();
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(200);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

while (WiFi.status() != WL_CONNECTED)


{
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
lcd.print("Connected");
delay(2000);

// Print the IP address


/*Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");*/

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
lcd.clear();
}

void loop() {
temp_val = dht.readTemperature();
humid_val = dht.readHumidity();
if (millis() >= time_now + delayp) {
time_now += delayp;
Firebase.setFloat(firebaseData, "IOTtech/RoboKIT/" + your_ID +
"/Sensors/DHT11/Temperature", temp_val);
Firebase.setFloat(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/Sensors/DHT11/Humidity",
humid_val);

44
}

lcd.setCursor(0, 0);
lcd.print("Temp:-");
lcd.setCursor(7, 0);
lcd.print(temp_val);
lcd.setCursor(0, 1);
lcd.print("Humidity:-");
lcd.setCursor(12, 1);
lcd.print(humid_val);

delay(500);
}

Working:
Initialization: The ESP32 development board is powered on and the
necessary pins are configured. Wi-Fi connectivity is established by
connecting to the specified network.
Sensor Reading: The DHT11 sensor is used to read the temperature and
humidity values using the `readTemperature()` and `readHumidity()`
functions.
Data Upload: If the specified delay has elapsed (every 5 seconds in this
case), the current temperature and humidity readings are uploaded to the
Firebase database using the `Firebase.setFloat()` function.
Display: The temperature and humidity readings are displayed on the LCD
using the `lcd.print()` and `lcd.setCursor()` functions.
Loop Continuation: The loop continues, and the process repeats, ensuring
continuous monitoring and data upload.
Conclusion:
The Temperature and Humidity Monitoring System successfully monitors
temperature and humidity levels and provides real-time data upload to a Firebase
database for remote monitoring and analysis. By utilizing an ESP32 development
board, a DHT11 sensor, and Firebase integration, the system offers a reliable
solution for monitoring environmental conditions. The working of the system
ensures continuous monitoring, data collection, and display on the LCD screen.
This project serves as a foundation for further enhancements and integrations to
create a comprehensive environmental monitoring system.

45
Project-8
Wi-Fi Robot with Voice Command (Mobile App Based)
Introduction:
The WiFi Robot with Voice Command Control project aims to develop a system
that allows users to control a robot wirelessly using voice commands. The project
integrates an Arduino board, an ESP8266 WiFi module, a voice recognition
module, and a motor driver module. The goal is to provide a user-friendly interface
for controlling the robot's movements and actions through voice commands sent
over a WiFi network.
Apparatus Required:
1. Arduino Board: The Arduino board acts as the main controller, providing
processing power and I/O capabilities.
2. ESP8266 WiFi Module: The WiFi module enables the Arduino to connect to
a WiFi network and communicate with other devices over the network.
3. Motor Driver IC: The motor driver module controls the robot's motors,
allowing it to move in different directions.
4. Robot Chassis and Motors: The robot chassis provides the structure for the
robot, and the motors enable its movement.

46
Pin Configuration:
ESP8266 WiFi Module: Connected to the Arduino's hardware serial pins (e.g.,
RX to Pin 0, TX to Pin 1).
Voice Recognition Module: Connected to the Arduino's digital pins (e.g.,
VoiceRX to Pin 10, VoiceTX to Pin 11).
Motor Driver Module: Connected to the Arduino's digital pins (e.g., IN1 to Pin
7, IN2 to Pin 4, IN3 to Pin 8, IN4 to Pin 9).
Library Used and Link:
Wire.h: This library allows communication with I2C devices, such as the LCD
display. It is a built-in library and does not require a separate download.
FirebaseESP8266.h: This library enables communication between the Arduino
and the Firebase platform. It can be found at:
[https://github.com/mobizt/Firebase-ESP8266]
(https://github.com/mobizt/Firebase-ESP8266)
SoftwareSerial.h: This library facilitates software serial communication,
necessary for communication with the voice recognition module. It is a built-in
library and does not require a separate download.
Program:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 16, 2);

#include "FirebaseESP32.h"

#define WIFI_SSID "Rank2Top"


#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"

#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

FirebaseData firebaseData;

47
#define in1 27
#define in2 26
#define in3 25
#define in4 33

int ch;
String your_ID = "9876543210";// your mobile number
void setup()
{
Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

lcd.begin();
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("**IOTTECH**");
lcd.setCursor(2, 1);

48
lcd.print("SMART PRODUCTS");
delay(2000);
Serial.println("The device started, now you can connect using Firebase!");
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

void loop()
{
String r;

Firebase.getString(firebaseData, "IOTtech/RoboKIT/"+your_ID+"/Robocar/State");
r = (firebaseData.stringData());
Serial.println(r);
if (r == "B")
{
ch = 2;
lcd.clear();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("BACKWARD");
Serial.println("CH==2 means backward");
}
if (r == "F")
{
ch = 1;
lcd.clear();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("FORWARD");

49
Serial.println("CH==1 means forward");
}

if (r == "L")
{
ch = 4;
lcd.clear();
lcd.backlight();
lcd.setCursor(6, 0);
lcd.print("LEFT");
Serial.println("CH==4 means left");
}

if (r == "R")
{
ch = 3;
lcd.clear();
lcd.backlight();
lcd.setCursor(5, 0);
lcd.print("RIGHT");
Serial.println("CH==3 means right");
}

if (r == "S")
{
ch = 5;
lcd.clear();
lcd.backlight();
lcd.setCursor(6, 0);
lcd.print("STOP");
Serial.println("CH==5 means motor stopped");

50
}
switch (ch)
{
case 1: digitalWrite(in1, 0);
digitalWrite(in2, 1);
digitalWrite(in3, 0);
digitalWrite(in4, 1);

break;

case 2: digitalWrite(in1, 1);


digitalWrite(in2, 0);
digitalWrite(in3, 1);
digitalWrite(in4, 0);

break;

case 3: digitalWrite(in1,1);
digitalWrite(in2,0);
digitalWrite(in3, 0);
digitalWrite(in4, 1);
break;

case 4: digitalWrite(in1, 0);


digitalWrite(in2, 1)
digitalWrite(in3, 1);
digitalWrite(in4, 0)
break;

case 5: digitalWrite(in1,LOW);

51
digitalWrite(in2,LOW);
digitalWrite(in3,LOW
digitalWrite(in4,LOW);
break;
default: break;
}
}

Working:
1. The system starts by initializing the required components and establishing a
WiFi connection.
2. The voice recognition module is configured using the SoftwareSerial library
to receive voice commands.
3. The Arduino continuously checks for available voice commands from the
voice recognition module.
4. When a voice command is received, it is compared to predefined commands
("forward", "backward", "left", "right", "stop").
5. Depending on the recognized command, the Arduino sends corresponding
signals to the motor driver module, controlling the robot's movement.
6. Additionally, the Firebase platform is utilized to store and update the current
command, allowing for remote monitoring and control of the robot.
Testing:
1. Upload the code to the Arduino board.
2. Connect the voice recognition module, motor driver module, and WiFi
module to the appropriate pins on the Arduino.
3. Connect the robot motors to the motor driver module.
4. Power up the Arduino and ensure that the WiFi connection is established.
5. Speak one of the predefined commands ("forward", "backward", "left",
"right", "stop") into the voice recognition module.
6. Observe the robot's movement according to the spoken command.
Conclusion:
The WiFi Robot with Voice Command Control project successfully demonstrates
the integration of voice recognition and WiFi communication for controlling a
robot.

52
Project-9
Bluetooth Robot with Voice Command (Mobile App Based)
Introduction:
The Bluetooth Controlled Car with LCD Display project aims to develop a system
that allows controlling a car wirelessly using a Bluetooth connection. The system
utilizes an Arduino board, a motor driver module, a Bluetooth module, and an
LCD display. The objective is to provide a convenient and intuitive way to control
the car's movement using a smartphone or other Bluetooth-enabled devices.
Apparatus Required:
1. Arduino Board: The Arduino board serves as the main controller and
provides the necessary processing power and I/O capabilities.
2. Motor Driver Module: The motor driver module is used to control the
motors of the car, enabling forward, backwards, left, and right movements.
3. Bluetooth Module: The Bluetooth module enables wireless communication
between the Arduino and the controlling device (e.g., smartphone).
4. LCD Display: The LCD display provides visual feedback and status
information about the car's movement.
5. Chassis and Wheels: The car chassis and wheels provide the physical
structure for the car.

53
Pin Configuration:
LCD I2C Module: Connected to the Arduino's I2C pins (SDA and SCL).
Motor Driver Module (IN1, IN2, IN3, IN4): Connected to the Arduino's digital
pins (e.g., IN1 to Pin 27, IN2 to Pin 26, IN3 to Pin 25, IN4 to Pin 33).
Library Used and Link:
Wire.h: This library enables communication with I2C devices such as the
LCD display. It is a built-in library and does not require a separate
download.
LiquidCrystal_I2C.h: This library provides functions to control the LCD
display using the I2C interface. It can be found at:
[https://github.com/johnrickman/LiquidCrystal_I2C]
(https://github.com/johnrickman/LiquidCrystal_I2C)
Bluetoothserial.h: This library facilitates communication over Bluetooth
with the connected device. It is specific to the ESP32 chip and may require
additional configurations.
Program:

#include <Wire.h>
#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x3f,16,2);
#include "BluetoothSerial.h"
int ch=0;
BluetoothSerial SerialBT;
#define in1 27
#define in2 26
#define in3 25
#define in4 33 void setup() { lcd.begin(16, 2);
lcd.clear(); lcd.backlight(); lcd.setCursor(2, 0);
lcd.print("***IOTTECH***"); lcd.setCursor(2, 1); lcd.print("SMART PRODUCTS");

delay(1500);
Serial.begin(115200);
SerialBT.begin("Rank2Top");
Serial.println("The device started, now you can pair it with Bluetooth!");
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop()
{
char r;
if (SerialBT.available())

54
{
r = SerialBT.read();
if (r == 'F')
{
ch = 1;
lcd.clear();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("FORWARD");
}
else if (r == 'B')
{
ch = 2;
lcd.clear();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("BACKWARD");
}
else if (r == 'R')
{
ch = 3;
lcd.clear();
lcd.backlight();
lcd.setCursor(5, 0);
lcd.print("RIGHT");
}
else if (r == 'L')
{
ch = 4;
lcd.clear();
lcd.backlight();
lcd.setCursor(6, 0);
lcd.print("LEFT");
}
else if (r == 'S')
{
ch = 5;
lcd.clear();
lcd.backlight();
lcd.setCursor(6, 0);
lcd.print("STOP");
}
}
delay(20); switch (ch)
{
case 1:

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);

55
digitalWrite(in4, HIGH);
break;

case 2:

digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
break;

case 3:

digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
break;

case 4:

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
break;

case 5:

digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
break;
default: break;

}
Serial.println(r); delay(20);
}

Working:
1. Initialization: The LCD display is initialized and a welcome message is
shown.
2. Bluetooth Setup: The Bluetooth module is initialized, and the device is set
to the discoverable mode for pairing.
3. Control Input: The system waits for input from the connected Bluetooth
device. The input characters received are interpreted as control commands.
56
4. Motor Control: Based on the received control commands, the appropriate
motor pins are set to control the movement of the car. Forward, backwards,
left, right, and stop actions can be performed.
5. LCD Display: The LCD display is updated with the current car movement
status.
6. Loop Continuation: The loop continues to receive input and control the
car's movement based on the received commands.

Testing:
1. Connect the Arduino board to a power source and ensure it is properly
programmed with the provided code.
2. Connect the motor driver module to the specified motor pins on the Arduino
board.
3. Connect the Bluetooth module to the Arduino board, ensuring the correct
connections for communication.
4. Connect the LCD display to the Arduino's I2C pins (SDA and SCL).
5. Power on the system and observe the LCD display.
6. Pair the Bluetooth module with your smartphone or other Bluetooth-enabled
device.
7. Open a serial communication terminal on the paired device and send the
control commands ('F' for forward, 'B' for backward, 'R' for right, 'L' for left,
'S' for stop) to control the car's movement.
8. Observe the LCD display for the updated car movement status and verify
that the motor actions are performed correctly.
9. Repeat the testing process with different control commands to ensure the
proper functioning of the system.

Conclusion:
The Bluetooth Controlled Car with LCD Display project successfully implements a
wireless control system for a car using Bluetooth communication. By utilizing an
Arduino board, a motor driver module, a Bluetooth module, and an LCD display,
the system provides convenient and intuitive control over the car's movement. The
integration of the LCD display enhances the user experience by providing real-time
feedback on the car's status. The system can be further enhanced by adding
additional features such as speed control or obstacle detection.

57
Project-10
IR Sensor-Based Obstacle Detection (Mobile App-Based)
Introduction:
The IR Obstacle Detection System with Firebase Integration project aims to create
a wireless system that can detect the presence of obstacles using an IR obstacle
avoidance sensor and upload the data to a Firebase database for remote monitoring
and analysis. The system utilizes an ESP32 development board, an IR obstacle
avoidance sensor, and the Firebase real-time database. The objective is to provide
an efficient and reliable solution for obstacle detection in an environment.
Apparatus Required:
ESP32 Development Board: The ESP32 serves as the main controller and
provides the necessary processing power and Wi-Fi connectivity.
IR Obstacle Avoidance Sensor: An IR obstacle avoidance sensor is used to
detect the presence of obstacles in the environment.
Custom-Designed PCB: A custom-designed PCB can be used for circuit
connections and mounting the components, providing a compact and
organized setup.
Liquid Crystal Display (LCD): An LCD is used to display the obstacle
detection status.
Libraries Used:
1. Arduino.h: The standard Arduino library for general-purpose functions and
communication with the ESP32 board.
2. WiFi.h: The library for connecting to a Wi-Fi network and establishing an
internet connection.
3. FirebaseESP32.h: The Firebase library for interfacing with the Firebase real-
time database.
4. Links: FirebaseESP32 library: [https://github.com/mobizt/Firebase-ESP32]
(https://github.com/mobizt/Firebase-ESP32)
5. LiquidCrystal_I2C.h: The library for controlling the LCD using the I2C
communication protocol.
Pin Configuration:
ESP32 Pin 18: Connects to the OUT pin of the IR obstacle avoidance sensor.

58
Additionally, the LiquidCrystal_I2C library is used to control the LCD display,
which is connected via I2C. The SDA (Serial Data) pin is connected to the
ESP32's SDA pin, and the SCL (Serial Clock) pin is connected to the ESP32's
SCL pin.

Program (Code):
#include "FirebaseESP32.h"

#define WIFI_SSID "Rank2Top"

#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"

#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

FirebaseData firebaseData;

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 16, 2);

#define SENSOR_PIN 18 // ESP32 pin GIOP18 connected to OUT pin of IR obstacle avoidance sensor

String your_ID = "987654321"; // your mobile number

void setup() {

Serial.begin(9600);

pinMode(SENSOR_PIN, INPUT);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to Wi-Fi");

59
while (WiFi.status() != WL_CONNECTED) {

Serial.print(".");

delay(300);

Serial.println();

Serial.print("Connected with IP: ");

Serial.println(WiFi.localIP());

Serial.println();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

lcd.begin();

lcd.clear();

lcd.backlight();

lcd.setCursor(2, 0);

lcd.print("***IOTTECH***");

lcd.setCursor(2, 1);

lcd.print("SMART PRODUCTS");

delay(2000);

void loop() {

int state = digitalRead(SENSOR_PIN);

if (state == LOW) {

Serial.println("The obstacle is present");

Firebase.setString(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/Sensors/IR/Obstacle", "Obstacle Present");

lcd.clear();

lcd.backlight();

lcd.setCursor(0, 0);

lcd.print("IR Sensor:");

lcd.setCursor(0, 1

lcd.print("obstacle present");

} else {

Serial.println("The obstacle is NOT present");

Firebase.setString(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/Sensors/IR/Obstacle", "No Obstacle");

lcd.clear();

60
lcd.backlight();

lcd.setCursor(0, 0);

lcd.print("IR Sensor:");

lcd.setCursor(0, 1);

lcd.print("No obstacle");

delay(1000);

Working:
1. Initialization: The ESP32 development board is initialized, and the necessary
pins are configured. Wi-Fi connectivity is established by connecting to the
specified network.
2. Sensor Reading: The state of the IR obstacle avoidance sensor connected to pin
18 is continuously monitored using the `digitalRead()` function. If the sensor
detects an obstacle (LOW state), the system sends the corresponding status to the
Firebase database and updates the LCD display accordingly.
3. Firebase Integration: The system utilizes the FirebaseESP32 library to connect
to the Firebase real-time database. It sends the status of the IR sensor (obstacle
present or no obstacle) to the specified location in the database.
4. LCD Display: The LCD display (I2C) is used to show the current status of the
obstacle detection. It displays messages such as "obstacle present" or "No obstacle"
based on the sensor readings.
5. Loop Continuation: The system continuously monitors the sensor and updates
the Firebase database and LCD display accordingly.
Testing:
1. Connect the IR obstacle avoidance sensor to pin 18 of the ESP32 development
board.
2. Connect the LCD display to the I2C interface of the ESP32 board.
3. Power on the system and ensure that the ESP32 is connected to the specified
Wi-Fi network.
4. Observe the LCD display. It should show the initial startup messages.
5. Place an obstacle in front of the IR sensor and verify that the LCD display and
serial monitor output show "The obstacle is present". The Firebase database
should also update with the corresponding status.

61
6. Remove the obstacle and verify that the LCD display and serial monitor output
show "The obstacle is NOT present". The Firebase database should update
accordingly.
7. Repeat the testing process with different obstacles to ensure accurate obstacle
detection.
Conclusion:
The IR Obstacle Detection System with Firebase Integration successfully detects
the presence of obstacles using an IR obstacle avoidance sensor. The system
provides real-time monitoring and updates the Firebase database with the obstacle
status. The LCD display shows the current status, allowing for local monitoring.
This project can be further enhanced and integrated into various applications that
require obstacle detection and monitoring.

62
Project-11
Servo Motor Control in Robotics (Mobile App Based)
Introduction:
The Servo Motor Control with Firebase Integration project aims to control a servo
motor's rotation and update the rotation status on a Firebase database. The system
utilizes an ESP32 microcontroller, a servo motor, a Wi-Fi module for internet
connectivity, and the Firebase real-time database. The objective is to provide
remote control and monitoring of the servo motor's rotation.
Apparatus Required:
ESP32 Microcontroller: The ESP32 serves as the main controller and provides
the necessary processing power and Wi-Fi connectivity.
Servo Motor: A servo motor is used to control the rotation angle based on the
input signals.
Wi-Fi Module: A Wi-Fi module is used to establish an internet connection and
communicate with the Firebase database.
Liquid Crystal Display (LCD): An LCD is used to provide visual
feedback and display the rotation status.

63
Library Used:
1. ESP32Servo.h: The library for controlling servo motors on the ESP32.
2. FirebaseESP32.h: The Firebase library for interfacing with the Firebase
real-time database.
3. Wire.h: The library for I2C communication.
4. LiquidCrystal_I2C.h: The library for controlling the LCD using the I2C
communication protocol.
Library Links:
ESP32Servo library: [https://github.com/jkb-git/ESP32Servo]
(https://github.com/jkb-git/ESP32Servo)
FirebaseESP32 library: [https://github.com/mobizt/Firebase-ESP32]
(https://github.com/mobizt/Firebase-ESP32)
Pin Configuration:
Servo Motor: Connect the signal pin of the servo motor to the specified ESP32
pin (SERVO_PIN).
Program (Code):
#include <ESP32Servo.h>

Servo servoMotor;

int pos = 0;

#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)

int servoPin = 17;

#elif defined(CONFIG_IDF_TARGET_ESP32C3)

int servoPin = 7;

#else

int SERVO_PIN = 18;

#endif

#include "FirebaseESP32.h"

#define WIFI_SSID "Rank2Top"

#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"

#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

64
String your_ID = "9876543210";// your mobile number

FirebaseData firebaseData

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 16, 2);

void setup() {

Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to Wi-Fi");

while (WiFi.status() != WL_CONNECTED)

Serial.print(".");

delay(300);

Serial.println();

Serial.print("Connected with IP: ");

Serial.println(WiFi.localIP());

Serial.println();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

ESP32PWM::allocateTimer(0);

ESP32PWM::allocateTimer(1);

ESP32PWM::allocateTimer(2);

ESP32PWM::allocateTimer(3);

servoMotor.setPeriodHertz(50); // standard 50 hz servo

//servoMotor.attach(SERVO_PIN); // attaches the servo on ESP32 pin

servoMotor.attach(SERVO_PIN, 1000, 2000); // attaches the servo on pin 18 to the servo object

// using default min/max of 1000us and 2000us

lcd.begin();

lcd.clear();

lcd.backlight();

lcd.setCursor(2, 0);

lcd.print("**IOTTECH**");

lcd.setCursor(2, 1);

lcd.print("SMART PRODUCTS");

65
delay(2000);

void loop() {

delay(4000);

Firebase.setString(firebaseData, "IOTtech/RoboKIT/"+your_ID+"/Sensors/Servo/Rotation", "AntiClockwise");

lcd.clear();

lcd.backlight();

lcd.setCursor(0, 0);

lcd.print("Servo:");

lcd.setCursor(0, 1);

lcd.print("AntiClockwise");

delay(15);

servoMotor.write(0);

delay(15);

servoMotor.write(45);

delay(15);

servoMotor.write(90);

delay(15);

servoMotor.write(135);

delay(15);

servoMotor.write(180);

delay(4000);

Firebase.setString(firebaseData, "IOTtech/RoboKIT/"+your_ID+"/Sensors/Servo/Rotation", "Clockwise");

lcd.clear();

lcd.backlight();

lcd.setCursor(0, 0);

lcd.print("Servo:");

lcd.setCursor(0, 1);

lcd.print("Clockwise");

delay(15);

servoMotor.write(180);

delay(15);

servoMotor.write(135);

66
delay(15);

servoMotor.write(90);

delay(15);

servoMotor.write(45);

delay(15);

servoMotor.write(0);

Working:
1. Initialization: The ESP32 microcontroller is initialized, and the necessary
pins and modules are configured. Wi-Fi connectivity is established by
connecting to the specified network.
2. Firebase Connection: The Firebase database is connected using the
FirebaseESP32 library. This allows communication with the Firebase
database for data storage and retrieval.
3. Servo Motor Setup: The servo motor is set up using the ESP32Servo
library. The servo motor is attached to the specified ESP32 pin
(SERVO_PIN) using the `servoMotor.attach()` function.
4. LCD Initialization: The LCD display is initialized using the
LiquidCrystal_I2C library. This allows for displaying the servo motor's
rotation status.
5. AntiClockwise Rotation: The servo motor is set to rotate in an
anticlockwise direction. The rotation status is updated on the Firebase
database, and the LCD display is updated to show "AntiClockwise".
6. Clockwise Rotation: After a delay, the servo motor is set to rotate in a
clockwise direction. The rotation status is updated on the Firebase database,
and the LCD display is updated to show "Clockwise".
7. Loop Continuation: The loop continues to repeat the rotation sequence and
updates the rotation status on the Firebase database and LCD display.
Testing:
1. Connect the ESP32 microcontroller to a power source and ensure it is
properly programmed with the provided code.
2. Ensure that the Wi-Fi credentials in the code are updated with your
network's SSID and password.
3. Connect the servo motor to the specified ESP32 pin (SERVO_PIN) for
controlling the rotation.
4. Connect the LCD display to the I2C pins on the ESP32.
5. Power on the system and observe the LCD display.

67
6. The system should establish a Wi-Fi connection and display
"**IOTTECH**" and "SMART PRODUCTS" on the LCD.
7. The servo motor will start rotating in an anticlockwise direction, and the
rotation status will be updated on the Firebase database and displayed on the
LCD.
8. After a delay, the servo motor will rotate in a clockwise direction, and the
rotation status will be updated and displayed accordingly.
9. Monitor the Firebase database to ensure that the rotation status is being
updated correctly.
10. Observe the LCD display to verify that the rotation status is being updated
and displayed correctly.
11. Repeat the testing process to validate the system's accuracy and reliability.
Conclusion:
The Servo Motor Control with Firebase Integration project provides remote control
and monitoring of a servo motor using an ESP32 microcontroller. By incorporating
the ESP32Servo library, Wi-Fi connectivity, and the Firebase real-time database,
the system allows for convenient control and monitoring of the servo motor's
rotation. The LCD display provides real-time feedback on the rotation status, while
the Firebase integration enables data storage and retrieval for further analysis.

68
Project-12
Ultrasonic Distance Meter (Mobile App Based)
Introduction:
The Ultrasonic Distance Measurement project aims to create a system that can
measure distances using an ultrasonic sensor and upload the data to a Firebase
database for remote monitoring and analysis. The system utilizes an ESP32
development board, an ultrasonic sensor, and the Firebase real-time database. The
objective is to provide an efficient and reliable solution for distance measurement
and enable remote access to the measured data.
Apparatus Required:
1. ESP32 Development Board: The ESP32 serves as the main controller and
provides the necessary processing power and Wi-Fi connectivity.
2. Ultrasonic Sensor: An ultrasonic sensor is used to measure distances based on
the time it takes for sound waves to bounce back.
3. Custom-Designed PCB: A custom-designed PCB is used for circuit
connections and mounting the components.
4. Liquid Crystal Display (LCD): An LCD display is used to display the
measured distance.

69
Pin Configuration:
ESP32 Development Board:
No specific pins are mentioned in the code provided. Please ensure that the
ESP32 board is properly connected to power and programmed correctly.
Ultrasonic Sensor:
Trig Pin: Connected to pin 5 of the ESP32 (trigPin = 5)
Echo Pin: Connected to pin 18 of the ESP32 (echoPin = 18)
LCD Display (I2C):
SDA Pin: Connected to the I2C data pin of the ESP32 (typically GPIO 21)
SCL Pin: Connected to the I2C clock pin of the ESP32 (typically GPIO 22)
Libraries Used:
FirebaseESP32.h: The Firebase library for interfacing with the Firebase
real-time database.
FirebaseESP32 library: [https://github.com/mobizt/Firebase-ESP32]
(https://github.com/mobizt/Firebase-ESP32)
Wire.h: The library for I2C communication used by the LiquidCrystal_I2C
library.
LiquidCrystal_I2C.h: The library for controlling the LCD using the I2C
communication protocol.
Program (Code):
#include "FirebaseESP32.h"

#define WIFI_SSID "Rank2Top"

#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"

#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com

FirebaseData firebaseData;

const int trigPin = 5;

const int echoPin = 18;

#define SOUND_SPEED 0.034

#define CM_TO_INCH 0.393701

long duration;

float distanceCm;

70
float distanceInch;

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 16, 2);

String your_ID = "9876543210";// your mobile number

void setup() {

Serial.begin(9600); // Starts the serial communication

pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

pinMode(echoPin, INPUT); // Sets the echoPin as an Input

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to Wi-Fi");

while (WiFi.status() != WL_CONNECTED)

Serial.print(".");

delay(300);

Serial.println();

Serial.print("Connected with IP: ");

Serial.println(WiFi.localIP());

Serial.println();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

lcd.begin();

lcd.clear();

lcd.backlight();

lcd.setCursor(2, 0);

lcd.print("**IOTTECH**");

lcd.setCursor(2, 1);

lcd.print("SMART PRODUCTS");

delay(2000);

void loop() {

71
// Clears the trigPin

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

Firebase.setString(firebaseData, "IOTtech/RoboKIT/" +your_ID+ "/Sensors/Ultrasonic/DistanceInCm", distanceCm);

// Calculate the distance

distanceCm = duration * SOUND_SPEED / 2;

// Convert to inches

distanceInch = distanceCm * CM_TO_INCH;

// Prints the distance in the Serial Monitor

Serial.print("Distance (cm): ");

Serial.println(distanceCm);

Serial.print("Distance (inch): ");

Serial.println(distanceInch);

lcd.clear();

lcd.backlight();

lcd.setCursor(0, 0);

lcd.print("Distance(cm):");

lcd.setCursor(0, 1);

lcd.print(distanceCm);

delay(6000);

72
Working:
1. Initialization: The ESP32 development board is initialized, and the necessary
pins are configured for the ultrasonic sensor and LCD display. Wi-Fi
connectivity is established by connecting to the specified network.
2. Distance Measurement: The ultrasonic sensor is used to measure the
distance by sending sound waves and calculating the time it takes for the
waves to bounce back. The duration is obtained using the `pulseIn()`
function.
3. Firebase Integration: The measured distance in centimeters is uploaded to
the Firebase database using the `Firebase.setString()` function.
4. Display: The measured distance in centimeters is displayed on the LCD
using the `lcd.print()` function for local monitoring.
5. Loop Continuation: The loop continues, and the process repeats, ensuring
continuous distance measurement and data upload to Firebase.

Testing:
1. Connect the ESP32 development board to a power source and ensure it is
properly programmed with the provided code.
2. Ensure that the Wi-Fi credentials in the code are updated with your network's
SSID and password.
3. Connect the ultrasonic sensor to the specified trigPin and echoPin on the ESP32
board.
4. Connect the LCD display to the I2C interface on the ESP32 board.
5. Power on the system and observe the LCD display.
6. The system should establish a Wi-Fi connection and display the startup message
on the LCD.
7. The ultrasonic sensor will start measuring the distance.
8. The measured distance in centimetres will be displayed on the LCD.
9. The measured distance will be uploaded to the specified Firebase database.
10. Monitor the Firebase database to ensure that the distance measurements are
being uploaded correctly.
11. Observe the LCD display to verify that the distance measurements are being

73
updated on the screen.
12. Repeat the testing process in different scenarios to validate the accuracy and
reliability of the distance measurement.

Conclusion:
The Ultrasonic Distance Measurement with Firebase Integration project
successfully measures distances using an ultrasonic sensor and uploads the data to
a Firebase database for remote monitoring and analysis. By utilizing an ESP32
development board, an ultrasonic sensor, and Firebase integration, the system
provides an efficient solution for distance measurement. The working of the
system ensures continuous measurement, data collection, and display on the LCD
screen. This project serves as a foundation for further enhancements and
integrations to create comprehensive distance monitoring and analysis applications.

74
Project-13
Gesture Control through Wi-Fi (Mobile App Based)
Introduction:
The Gesture Control by Wi-Fi project aims to develop a system that allows users to
control a robot using hand gestures through a Wi-Fi network. The project utilizes
an Arduino board, an ESP32 Wi-Fi module, and a set of sensors to detect hand
gestures. The goal is to provide an intuitive and interactive method for controlling
the robot's movements remotely.
Apparatus Required:
1. Arduino Board: The Arduino board acts as the main controller, providing
processing power and I/O capabilities.
2. ESP32 Wi-Fi Module: The Wi-Fi module enables the Arduino to connect to
a Wi-Fi network and communicate with other devices over the network.
3. Gesture Recognition Sensors: The project incorporates sensors such as
accelerometers or flex sensors to detect hand gestures.
4. Motor Driver Module: The motor driver module controls the robot's
motors, allowing it to move in different directions.
5. Robot Chassis and Motors: The robot chassis provides the structure for the
robot, and the motors enable its movement.
line

75
Pin Configuration:
ESP32 Wi-Fi Module: Connected to the Arduino's hardware serial pins
(e.g., RX to Pin 0, TX to Pin 1).
Gesture Recognition Sensors: Connected to the Arduino's analog or digital
pins, depending on the type of sensor used.
Motor Driver IC: Connected to the Arduino's digital pins (e.g., IN1 to Pin
27, IN2 to Pin 26, IN3 to Pin 25, IN4 to Pin 33).
Library Used and Link:
FirebaseESP32.h: This library enables communication between the Arduino and
the Firebase platform.
Program:
#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 16, 2);

#include "FirebaseESP32.h"

#define WIFI_SSID "Rank2Top"

#define WIFI_PASSWORD "123456789"

#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"

#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"

FirebaseData firebaseData;

#define in1 27

#define in2 26

#define in3 25

#define in4 33

int ch;

String your_ID = "9876543210";// your mobile number

void setup()

Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to Wi-Fi");

while (WiFi.status() != WL_CONNECTED)

76
Serial.print(".");

delay(300);

Serial.println();

Serial.print("Connected with IP: ");

Serial.println(WiFi.localIP());

Serial.println();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

lcd.begin();

lcd.clear();

lcd.backlight();

lcd.setCursor(2, 0);

lcd.print("**IOTTECH**");

lcd.setCursor(2, 1);

lcd.print("SMART PRODUCTS");

delay(2000);

Serial.println("The device started, now you can connect using Firebase!");

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT)

void loop()

String

Firebase.getString(firebaseData, "IOTtech/RoboKIT/"+your_ID+"/Robocar/State");

r = (firebaseData.stringData());

Serial.println(r);

if (r == "B")

ch = 2;

lcd.clear();

lcd.backlight();

lcd.setCursor(4, 0);

lcd.print("BACKWARD");

77
Serial.println("CH==2 means backward");

if (r == "F")

ch = 1;

lcd.clear();

lcd.backlight();

lcd.setCursor(4, 0);

lcd.print("FORWARD");

Serial.println("CH==1 means forward");

if (r == "L")

ch = 4;

lcd.clear();

lcd.backlight();

lcd.setCursor(6, 0);

lcd.print("LEFT");

Serial.println("CH==4 means left");

if (r == "R")

ch = 3;

lcd.clear();

lcd.backlight();

lcd.setCursor(5, 0);

lcd.print("RIGHT");

Serial.println("CH==3 means right");

if (r == "S")

ch = 5;

78
lcd.clear();

lcd.backlight();

lcd.setCursor(6, 0);

lcd.print("STOP");

Serial.println("CH==5 means motor stopped");

switch (ch)

case 1:

digitalWrite(in1, 0);

digitalWrite(in2, 1);

digitalWrite(in3, 0);

digitalWrite(in4, 1);

Serial.print("ch:");

Serial.println(ch);

break;

case 2: digitalWrite(in1, 1);

digitalWrite(in2, 0);

digitalWrite(in3, 1);

digitalWrite(in4, 0);

Serial.print("ch:");

Serial.println(ch);

break;

case 3: digitalWrite(in1, 1);

digitalWrite(in2, 0);

digitalWrite(in3, 0);

digitalWrite(in4, 1);

Serial.print("ch:");

Serial.println(ch);

break;

79
case 4: digitalWrite(in1, 0);

digitalWrite(in2, 1);

digitalWrite(in3, 1);

digitalWrite(in4, 0);

Serial.print("ch:");

Serial.println(ch);

break;

case 5: digitalWrite(in1, LOW);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, LOW);

Serial.print("ch:");

Serial.println(ch);

break;

default: break;

Working:
1. The system starts by initializing the required components and establishing a
WiFi connection.
2. The LCD display is initialized and shows the startup message.
3. The Arduino continuously checks for the command received from the
Firebase platform using the FirebaseESP32 library.
4. The received command is compared to predefined commands ("F" for
forward, "B" for backward, "L" for left, "R" for right, "S" for stop).
5. Depending on the received command, the Arduino sets the corresponding
motor control pins to control the robot's movement.
6. The LCD display updates with the current movement direction.
Testing:
1. Upload the code to the Arduino board.
2. Connect the robot chassis and motors to the motor driver module.
3. Connect the motor driver module to the appropriate digital pins on the

80
Arduino.
4. Power up the Arduino and ensure that the WiFi connection is established.
5. Use a mobile device or computer to update the "Robocar/State" value in the
Firebase database with one of the predefined commands ("F", "B", "L",”R”).
Conclusion:
The WiFi Robot with Voice Command Control project successfully demonstrates
the integration of voice recognition and WiFi communication for controlling a
robot. By using voice commands, users can easily maneuver the robot in different
directions. The Firebase platform enables remote monitoring and control of the
robot's actions, providing an additional layer of convenience and accessibility.

81
Project-14
Bluetooth Controlled robot with Seat Belt
Introduction:
The Bluetooth-Controlled Robot with Seat Belt Safety project aims to create a robot that
can be controlled via Bluetooth commands while incorporating a safety feature that
ensures the robot remains stationary unless the seat belt is fastened. This project
combines motor control, Bluetooth communication, and a safety mechanism to promote
responsible and secure operation of the robot.

Apparatus Required:
a) ESP32 Development Board
Serves as the main controller, providing processing power and Bluetooth
connectivity.
b) Bluetooth Module
Utilizes the Bluetooth Serial library for communication with a paired mobile
device.
c) Liquid Crystal Display (LCD)
A 16x2 I2C LCD is employed for displaying system status and directions.
d) Motor Driver Components
Four digital output pins (in1, in2, in3, in4) control the robot's movement.

Libraries Used:
Wire.h
Enables I2C communication, essential for controlling the LCD.
LiquidCrystal_I2C.h
Library for controlling the LCD using I2C communication protocols.

82
BluetoothSerial.h

Enables Bluetooth communication, allowing the robot to receive commands from a paired
mobile device.
Pin Configuration:
LCD I2C Module: Connected to the Arduino's I2C pins (SDA and SCL).
Motor Driver Module (IN1, IN2, IN3, IN4): Connected to the Arduino's digital
pins (e.g., IN1 to Pin 27, IN2 to Pin 26, IN3 to Pin 25, IN4 to Pin 33).
Program:
#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f,16,2);

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)

#error Bluetooth is not enabled! Plear run make menuconfig to and enable it

#endif

#if !defined(CONFIG_BT_SPP_ENABLED)

#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.

#endif

int ch=0;

83
BluetoothSerial SerialBT;

#define Seat_belt_pin 2

int Seat_belt_data;

#define in1 27

#define in2 26

#define in3 25

#define in4 33

void setup()

lcd.begin();

lcd.clear();

lcd.backlight();

lcd.setCursor(2,0);

lcd.print("**IOTTECH**");

lcd.setCursor(2,1);

lcd.print("SMART PRODUCTS");

delay(1500);

Serial.begin(115200);

SerialBT.begin("Rank2Top");

Serial.println("The device started, now you can pair it with bluetooth!");

pinMode(Seat_belt_pin,INPUT);

pinMode(in1,OUTPUT);

pinMode(in2,OUTPUT);

pinMode(in3,OUTPUT);

pinMode(in4,OUTPUT);

void loop()

Seat_belt_data = digitalRead(Seat_belt_pin);

Serial.println("Seat_belt_data : ");

Serial.print(Seat_belt_data);

char r;

if(Seat_belt_data == 1)

84
Serial.println("if_tyagi");

if(SerialBT.available())

r=SerialBT.read();

if(r=='F')

ch=1;

lcd.clear();

lcd.backlight();

lcd.setCursor(4,0);

lcd.print("FORWARD");

//Serial.println("CH==1 means forward");

else if(r=='B')

ch=2;

lcd.clear();

lcd.backlight();

lcd.setCursor(4,0);

lcd.print("BACKWARD");

//Serial.println("CH==2 means backward");

else if(r=='R')

ch=3;

lcd.clear();

lcd.backlight();

lcd.setCursor(5,0);

lcd.print("RIGHT");

//Serial.println("CH==3 means right");

else if(r=='L')

ch=4;

85
lcd.clear();

lcd.backlight();

lcd.setCursor(6,0);

lcd.print("LEFT");

//Serial.println("CH==4 means left");

else if(r=='S')

ch=5;

lcd.clear();

lcd.backlight();

lcd.setCursor(6,0);

lcd.print("STOP");

//Serial.println("CH==5 means motor stopped");

delay(20);

switch(ch)

case 1: digitalWrite(in1, 0);

digitalWrite(in2, 1);

digitalWrite(in3, 0);

digitalWrite(in4, 1);

break;

case 2: digitalWrite(in1, 1);

digitalWrite(in2, 0);

digitalWrite(in3, 1);

digitalWrite(in4, 0);

break;

case 3: digitalWrite(in1,1);

digitalWrite(in2,0);

86
digitalWrite(in3, 0);

digitalWrite(in4, 1);

break;

case 4: digitalWrite(in1, 0);

digitalWrite(in2, 1);

digitalWrite(in3, 1);

digitalWrite(in4, 0);

break;

case 5: digitalWrite(in1,LOW);

digitalWrite(in2,LOW);

digitalWrite(in3,LOW);

digitalWrite(in4,LOW);

break;

default: break;

else

Serial.println("else_tyagi");

ch=6;

lcd.clear();

lcd.backlight();

lcd.setCursor(6,0);

lcd.print("STOP");

87
digitalWrite(in1,LOW);

digitalWrite(in2,LOW);

digitalWrite(in3,LOW);

digitalWrite(in4,LOW);

Serial.println(r);

delay(20);

Working:
The Bluetooth-Controlled Robot with Seat Belt Safety project operates based on the
following principles:
1.) Initialization:
The system initializes the LCD, Bluetooth, and pin configurations during the setup
phase.
2.) Bluetooth Communication:
The BluetoothSerial library is utilized to establish communication between the robot
and a paired mobile device.
3.) Seat Belt Sensing:
The state of the seat belt is continuously monitored using the digitalRead() function on
the specified pin (Seat_belt_pin).
4.) Bluetooth Commands Processing:
If the seat belt is fastened (Seat_belt_data == 1), the system checks for available
Bluetooth data using SerialBT.available().
5.) Motor Control:
Based on the received Bluetooth command (r), the system sets the variable ch to a
corresponding value.
A switch-case statement controls the motors (connected to pins in1, in2, in3, and in4)
based on the value of ch.
6.) Display Feedback:
The LCD display is updated to show the current operation status, such as
"FORWARD," "BACKWARD," "RIGHT," "LEFT," or "STOP."
7.) Safety Feature:
If the seat belt is unfastened, the system sets ch to 6, indicating a stop condition, and

88
displays "STOP" on the LCD.
8.) Continuous Loop:
The loop continues to execute, ensuring real-time monitoring of seat belt status and
processing of Bluetooth commands.
This working mechanism ensures that the robot's movement is contingent upon the
seat belt being fastened, promoting a safety-conscious approach to controlling the
robot via Bluetooth. The LCD provides visual feedback about the robot's state, and the
safety feature prevents movement when the seat belt is not securely fastened.
Testing
The testing phase for the Bluetooth-Controlled Robot with Seat Belt Safety project
involves various scenarios to ensure proper functionality and adherence to safety
measures.
a) Power Up:
Connect the power supply to the robot and verify that all components are receiving
power.
b) Bluetooth Connectivity:
Pair the mobile device with the robot's Bluetooth module.
c) Seat Belt Sensing:
Test the system's response to the seat belt sensor by fastening and unfastening the seat
belt.
Confirm that the robot's motors only respond when the seat belt is securely fastened.
d) Bluetooth Control:
Send Bluetooth commands (F for forward, B for backward, R for right, L for left, S for
stop) from the mobile device.
Verify that the robot responds correctly to each command, adjusting its movement
accordingly.
e) Safety Feature:
Unfasten the seat belt while the robot is in motion.
Confirm that the robot stops immediately and displays "STOP" on the LCD.
f) Real-time Feedback:
Observe the LCD display for real-time feedback on the robot's status and direction
during Bluetooth control.

89
g) Multiple Commands:

Send a sequence of commands to test the robot's ability to execute a series of movements.
Ensure that the robot responds accurately and promptly to each command.
h) Repeated Testing:
Perform the above steps multiple times to validate the reliability and consistency of the
system's behavior.
i) Edge Cases:
Test the system under various conditions, such as rapid command inputs, intermittent
Bluetooth connectivity, or simulated disturbances, to assess its robustness.
j) Overall Performance:
Evaluate the overall performance of the Bluetooth-controlled robot, considering
responsiveness, accuracy, and adherence to safety protocols.

Conclusion
The Bluetooth-Controlled Robot with Seat Belt Safety project achieves a harmonious
blend of Bluetooth control, motor functionality, and safety measures. By enforcing seat
belt usage through a dedicated sensor, the robot promotes responsible operation. The real-
time feedback on the LCD and the seamless integration of Bluetooth commands showcases
its user-friendly design. Successful testing validates the system's reliability, making it a
valuable foundation for future robotics projects.

90
Project-15
Dancing Car

Introduction:
This project introduces a Dancing Car that utilizes an ultrasonic sensor for distance
measurement and controls four motors based on the measured values. The Dancing
Car can detect obstacles and perform predefined dance movements. The project
incorporates an ESP32 development board, an ultrasonic sensor, and motor driver
modules. The objective is to create an interactive and entertaining robot that can
move in various directions and dance when an obstacle is detected.
Materials and Components:
ESP32 development board
Ultrasonic sensor (e.g., HC-SR04)
Geared DC motors (Quantity: 4)
Motor driver modules (e.g., L298N)
Jumper wires (male-to-male and male-to-female)
Breadboard or custom PCB for circuit connections

91
Pin Configuration:
1. Ultrasonic Sensor:
Trig pin: Connect the ultrasonic sensor's Trig pin to ESP32 pin 5.
Echo pin: Connect the ultrasonic sensor's Echo pin to ESP32 pin 18.
2. Motor Control:
MOTOR1: Connect the control pin of motor 1 to ESP32 pin 27.
MOTOR2: Connect the control pin of motor 2 to ESP32 pin 26.
MOTOR3: Connect the control pin of motor 3 to ESP32 pin 25.
MOTOR4: Connect the control pin of motor 4 to ESP32 pin 33.

Program:
const int trigPin = 5;
const int echoPin = 18;
const int IN1 = 27;
const int IN2 = 26;
const int IN3 = 25;
const int IN4 = 33;

//define sound speed in cm/uS


#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701
const int DISTANCE_THRESHOLD = 50; // centimeters

long duration;
float distanceCm;
float distanceInch;

void setup() {
Serial.begin(115200); // Starts the serial communication
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(IN1, OUTPUT); // set arduino pin to output mode
pinMode(IN2, OUTPUT); // set arduino pin to output mode
pinMode(IN3, OUTPUT); // set arduino pin to output mode
pinMode(IN4, OUTPUT); // set arduino pin to output mode
}

92
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculate the distance


distanceCm = duration * SOUND_SPEED/2;

// Convert to inches
distanceInch = distanceCm * CM_TO_INCH;

// Prints the distance in the Serial Monitor


Serial.print("Distance (cm): ");
Serial.println(distanceCm);
Serial.print("Distance (inch): ");
Serial.println(distanceInch);
if( distanceCm < DISTANCE_THRESHOLD)
{
digitalWrite(IN1, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN4, HIGH);

delay(1000);

digitalWrite(IN2, HIGH);
digitalWrite(IN4, HIGH);
digitalWrite(IN1,LOW);
digitalWrite(IN3, LOW);

93
delay(1000);

digitalWrite(IN1, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN4, LOW);

delay(1000);

digitalWrite(IN2, HIGH);
digitalWrite(IN4, HIGH);
digitalWrite(IN1,LOW);
digitalWrite(IN3, LOW);

delay(1000);

digitalWrite(IN1, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN4, HIGH);
delay(1000);

digitalWrite(IN1, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN2,HIGH);
digitalWrite(IN4, LOW);

delay(1000);

else
{

digitalWrite(IN1, LOW);
digitalWrite(IN3, LOW);

94
digitalWrite(IN2, HIGH);
digitalWrite(IN4, HIGH);

delay(100);
}

Working:
1. Initialization:
The setup () function initializes the serial communication, sets the pin
modes, and prepares the system for operation.
Serial communication is initialized at a baud rate of 115200 to enable
communication with the Serial Monitor.
The pin modes for the ultrasonic sensor's trigPin and echoPin are set to
OUTPUT and INPUT, respectively.
The pin modes for the motor control pins (MOTOR1, MOTOR2, MOTOR3,
MOTOR4) are set to OUTPUT.
2. Distance Measurement and Motor Control:
The loop () function continuously executes the distance measurement and
motor control logic.
The trigPin is cleared, and a 2 microseconds delay is applied.
The trigPin is set to HIGH for 10 microseconds to trigger the ultrasonic
sensor.
The trigPin is then cleared.
The duration of the pulse received on the echoPin is measured using the
pulseIn() function, providing the sound wave travel time.
The distance in centimetres (distanceCm) is calculated based on the duration
and the speed of sound.
The distance in inches (distanceInch) is obtained by converting the
centimeters to inches.
The distance values are printed to the Serial Monitor for monitoring and
debugging purposes.
3. Dance Movement:

95
If the measured distance (distanceCm) is less than the defined distance
threshold (DISTANCE_THRESHOLD), the Dancing Car performs a dance
movement.
The dance movement consists of a predefined sequence of motor actions.
Motor1 and Motor3 are set to HIGH, while Motor2 and Motor4 are set to
LOW, causing the motors to move forward.
A delay of 1 second is introduced to maintain the forward motion.
Motor2 and Motor4 are then set to HIGH, while Motor1 and Motor3 are set
to LOW, enabling backward motion.
Another delay of 1 second is introduced to maintain the backward motion.
The above steps are repeated twice to perform a forward-backward
movement sequence.
Conclusion:
The Dancing Car project demonstrates the integration of an ultrasonic sensor, an
ESP32 development board, and motor driver modules to create an interactive robot
that can detect obstacles and perform dance movements. By utilizing the ESP32's
capabilities, the project enables precise distance measurement using the ultrasonic
sensor and precise motor control to achieve various movements. The
implementation of the dance sequence adds entertainment value to the project. The
provided pin configuration and code can be used as a starting point for building
your own Dancing Car. Feel free to customize the movements, add additional
sensors or features, and explore different dance sequences to make the project even
more interesting.

96
Project-16
Line Follower Robot
Introduction:
The Line Follower Robot with IR Sensors - Motor Control System project aims to
create an autonomous robot capable of following a line using infrared (IR) sensors
for line detection. The robot is controlled by an ESP32 development board and a
custom motor control circuit utilizing an IC for motor control. The objective is to
develop a line-following robot that can navigate a predefined path accurately and
autonomously.
Materials and Components:
ESP32 Development Board: The ESP32 serves as the main controller and
provides the necessary processing power and communication capabilities.
Infrared (IR) Sensors: Two IR sensors are used for line detection. These
sensors emit infrared light and measure the reflected light to determine the
Colour of the surface beneath the robot.
Geared DC Motors: The robot's movement is controlled by two geared DC
motors. These motors provide the necessary propulsion to follow the line.
Custom Motor Control Circuit: A custom motor control circuit utilizing
an IC (such as L293D or similar) is soldered onto a PCB to control the
motors' speed and direction.
Jumper Wires: Male-to-male and male-to-female jumper wires are used to
establish the connections between the components.
Breadboard or Custom PCB: A breadboard or custom PCB can be used
for the circuit connections, providing a convenient and organized layout.
Libraries Used: The project does not require any external libraries.
Pin Configuration:
IR Sensors:
Right IR Sensor: Connect the right IR sensor to ESP32 pin 13 (R_S).
Left IR Sensor: Connect the left IR sensor to ESP32 pin 14 (L_S).
Motor Control:
Motor 1 (Right Motor):
in1 pin: Connect the IC's input pin 1 (in1) to the ESP32 pin 27.

97
in2 pin: Connect the IC's input pin 2 (in2) to the ESP32 pin 26.
Motor 2 (Left Motor):
in3 pin: Connect the IC's input pin 3 (in3) to the ESP32 pin 25.
in4 pin: Connect the IC's input pin 4 (in4) to the ESP32 pin 33.

Working Principle:
Initialization: The ESP32 development board is powered on and the
necessary pins for IR sensors and motor control are configured as inputs and
outputs using the pinMode() function.
Loop Execution: The main functionality of the robot is implemented in the
loop() function, which runs repeatedly.
Line Detection: The robot checks the status of the IR sensors using
digitalRead() function. If both sensors detect a black line (low signal), the
robot moves forward.
Turning-1: If the right IR sensor detects a white surface (high signal) while
the left IR sensor detects a black line, the robot turns right by executing the
turnRight() function.
Turning-2: If the left IR sensor detects a white surface while the right IR
sensor detects a black line, the robot turns left by executing the turnLeft()
function.
Stop: If both sensors detect a white surface, the robot stops by executing the
stop () function.

98
Motor Control: The motor control functions (forward (), turnRight(),
turnLeft(), and stop()) set the appropriate pin values to control the direction
and speed of the motors connected to the motor control IC. This allows the
robot to move in the desired direction based on the IR sensor readings.
Loop Continuation: After executing the corresponding action based on the
IR sensor readings, the loop continues, and the robot repeats the line
detection and motor control steps to maintain its line-following behaviour.
Program:
#define in1 27 // Motor1 L293 Pin in1

#define in2 26 // Motor1 L293 Pin in2

#define in3 25 // Motor2 L293 Pin in3

#define in4 33 // Motor2 L293 Pin in4

#define R_S 13 // IR sensor Right

#define L_S 14 // IR sensor Left

void setup() {

pinMode(R_S, INPUT);

pinMode(L_S, INPUT);

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT);

delay(1000);

void loop()

if (digitalRead(R_S) == 0 && digitalRead(L_S) == 0)

forward();

else if (digitalRead(R_S) == 1 && digitalRead(L_S) == 0)

turnRight();

99
else if (digitalRead(R_S) == 0 && digitalRead(L_S) == 1)

turnLeft();

else if (digitalRead(R_S) == 1 && digitalRead(L_S) == 1)

stop();

void forward()

digitalWrite(in1, HIGH); // Right Motor forward Pin

digitalWrite(in2, LOW); // Right Motor backward Pin

digitalWrite(in3, LOW); // Left Motor backward Pin

digitalWrite(in4, HIGH); // Left Motor forward Pin

void turnRight() {

digitalWrite(in1, LOW); // Right Motor forward Pin

digitalWrite(in2, HIGH); // Right Motor backward Pin

digitalWrite(in3, LOW); // Left Motor backward Pin

digitalWrite(in4, HIGH); // Left Motor forward Pin

void turnLeft() {

digitalWrite(in1, HIGH); // Right Motor forward Pin

digitalWrite(in2, LOW); // Right Motor backward Pin

digitalWrite(in3, HIGH); // Left Motor backward Pin

digitalWrite(in4, LOW); // Left Motor forward Pin

void stop() {

digitalWrite(in1, LOW); // Right Motor forward Pin

digitalWrite(in2, LOW); // Right Motor backward Pin

digitalWrite(in3, LOW); // Left Motor backward Pin

digitalWrite(in4, LOW); // Left Motor forward Pin

100
}

Conclusion:
The Line Follower Robot with IR Sensors - Motor Control System project
demonstrates the implementation of a line-following robot using IR sensors and an
ESP32 development board. The robot can autonomously follow a predefined line
path by detecting the colour contrast between the line and the surrounding surface.
The

101
Project-17
Obstacle-Avoiding Robot
Introduction:
The Autonomous Obstacle-Avoiding Robot with Ultrasonic Sensor project aims to
develop a robotic system capable of autonomously navigating its environment
while avoiding obstacles. The robot utilizes an ESP32 development board, a
custom motor control circuit with an IC for motor control, and an ultrasonic sensor
for obstacle detection. The objective is to create a versatile and intelligent robot
that can safely manoeuvre through various environments by detecting and avoiding
obstacles in real time.
Materials and Components:
ESP32 Development Board: The ESP32 serves as the main controller,
providing the necessary processing power and communication capabilities.
Ultrasonic Sensor: An ultrasonic sensor is used for obstacle detection. It
emits ultrasonic waves and measures the time taken for the waves to bounce
back, allowing the robot to calculate the distance to nearby objects.
Geared DC Motors: The robot's movement is controlled by two geared DC
motors. These motors provide the necessary propulsion for forward and
backward motion, as well as turning.
Custom Motor Control Circuit: A custom motor control circuit utilizing
an IC, such as L293D or a similar motor driver IC, is soldered onto a PCB.
This circuit controls the speed and direction of the motors based on input
signals from the ESP32.
Jumper Wires: Male-to-male and male-to-female jumper wires are used to
establish the necessary connections between the components.
Libraries Used:
ESP32Servo: This library enables control of servo motors and is used to
control the position of the ultrasonic sensor.
NewPing: This library provides functions for interfacing with ultrasonic
sensors and is used to read distance measurements from the ultrasonic
sensor.

102
Pin Configuration:
Motor Control:
LeftMotorForward: Connect to the appropriate GPIO pin of the ESP32
(e.g., pin 27).
LeftMotorBackward: Connect to the appropriate GPIO pin of the ESP32
(e.g., pin 26).
RightMotorForward: Connect to the appropriate GPIO pin of the ESP32
(e.g., pin 25).
RightMotorBackward: Connect to the appropriate GPIO pin of the ESP32
(e.g., pin 33).
Ultrasonic Sensor:
trig_pin: Connect to the appropriate GPIO pin of the ESP32 (e.g., pin 5).
echo_pin: Connect to the appropriate GPIO pin of the ESP32 (e.g., pin 18).

103
Working Principle:
Initialization:
The setup() function initializes the system by setting the pin modes and
configuring the servo motor.
Pin modes are set for the motor control pins (LeftMotorForward,
LeftMotorBackward, RightMotorForward, RightMotorBackward) as
OUTPUT.
The servo motor is attached to the specified pin (15), and its initial position
is set to 115 degrees.
The ultrasonic sensor (sonar) is also initialized with the trig_pin and
echo_pin values.

Main Loop:
Distance Measurement:
The readPing() function is called to measure the distance using the ultrasonic
sensor.
The measured distance is stored in the distance variable.

Obstacle Detection and Navigation:


If the measured distance is less than or equal to 20 (indicating an obstacle is
nearby), the robot enters the obstacle avoidance mode.
The moveStop() function is called to stop the robot's movement.
The moveBackward() function is called to make the robot move backward.
After a specific delay, the robot stops again using moveStop() and measures
the distances to the right and left sides using the lookRight() and lookLeft()
functions, respectively.
Based on the measured distances, the robot decides whether to turn right or
left to avoid the obstacle.
The appropriate turnRight() or turnLeft() function is called to perform the
respective maneuver.
Finally, moveStop() is called to stop the robot's movement after completing
the turn.

104
Normal Operation:
If no obstacle is detected (distance greater than 20), the robot continues
moving forward using the moveForward() function.
Servo Motor Control:
The lookRight() and lookLeft() functions control the servo motor's position
to scan the surroundings.
The servo_motor.write() function is used to set the servo motor's angle to 50
degrees (lookRight()) or 170 degrees (lookLeft).
After a specific delay, the servo motor is reset to the center position (115
degrees) using servo_motor.write().
Ultrasonic Sensor Measurement:
The readPing() function sends a ping signal using the ultrasonic sensor and
calculates the distance based on the return time of the echo signal.
A delay is introduced before reading the sensor to ensure accurate
measurements.
If the measured distance is 0 (no echo received), a default value of 250 is
assigned to avoid erroneous readings.
Motor Control:
The moveStop() function sets all motor control pins (LeftMotorForward,
LeftMotorBackward, RightMotorForward, RightMotorBackward) to LOW,
effectively stopping the motors.
The moveForward() function sets the appropriate pin states to make the
robot move forward.
The moveBackward() function sets the appropriate pin states to make the
robot move backward.
The turnRight() function sets the appropriate pin states to make the robot
turn right.
The turnLeft() function sets the appropriate pin states to make the robot turn
left.
Program:
#include <ESP32Servo.h>

#include <NewPing.h>

// L298N motor control pins

const int LeftMotorForward = 27;

105
const int LeftMotorBackward = 26;

const int RightMotorForward = 25;

const int RightMotorBackward = 33;

// Sensor pins

#define trig_pin 5

#define echo_pin 18

#define maximum_distance 200

boolean goesForward = false;

int distance = 100;

NewPing sonar(trig_pin, echo_pin, maximum_distance);

Servo servo_motor;

void setup() {

pinMode(LeftMotorForward, OUTPUT);

pinMode(LeftMotorBackward, OUTPUT);

pinMode(RightMotorForward, OUTPUT);

pinMode(RightMotorBackward, OUTPUT);

servo_motor.attach(15);

servo_motor.write(115);

delay(2000);

distance = readPing();

delay(100);

distance = readPing();

delay(100);

distance = readPing();

delay(100);

distance = readPing();

delay(100);

void loop() {

int distanceRight = 0;

int distanceLeft = 0;

delay(50);

if (distance <= 20) {

moveStop();

106
delay(300);

moveBackward();

delay(400);

moveStop();

delay(300);

distanceRight = lookRight();

delay(300);

distanceLeft = lookLeft();

delay(300);

if (distance >= distanceLeft) {

turnRight();

moveStop();

} else {

turnLeft();

moveStop();

} else {

moveForward();

distance = readPing();

int lookRight() {

servo_motor.write(50);

delay(500);

int distance = readPing();

delay(100);

servo_motor.write(115);

return distance;

int lookLeft() {

servo_motor.write(170);

delay(500);

int distance = readPing();

107
delay(100);

servo_motor.write(115);

return distance;

delay(100);

int readPing() {

delay(70);

int cm = sonar.ping_cm();

if (cm == 0) {

cm = 250;

return cm;

void moveStop() {

digitalWrite(RightMotorForward, LOW);

digitalWrite(LeftMotorForward, LOW);

digitalWrite(RightMotorBackward, LOW);

digitalWrite(LeftMotorBackward, LOW);

void moveForward() {

if (!goesForward) {

goesForward = true;

digitalWrite(LeftMotorForward, HIGH);

digitalWrite(RightMotorForward, HIGH);

digitalWrite(LeftMotorBackward, LOW);

digitalWrite(RightMotorBackward, LOW);

}}

void moveBackward() {

goesForward = false;

digitalWrite(LeftMotorBackward, HIGH);

digitalWrite(RightMotorBackward, HIGH);

digitalWrite(LeftMotorForward, LOW);

digitalWrite(RightMotorForward, LOW);

108
void turnRight() {

digitalWrite(LeftMotorForward, HIGH);

digitalWrite(RightMotorBackward, HIGH);

digitalWrite(LeftMotorBackward, LOW);

digitalWrite(RightMotorForward, LOW);

delay(500);

digitalWrite(LeftMotorForward, HIGH);

digitalWrite(RightMotorForward, HIGH);

digitalWrite(LeftMotorBackward, LOW);

digitalWrite(RightMotorBackward, LOW);

void turnLeft() {

digitalWrite(LeftMotorBackward, HIGH);

digitalWrite(RightMotorForward, HIGH);

digitalWrite(LeftMotorForward, LOW);

digitalWrite(RightMotorBackward, LOW);

delay(500);

digitalWrite(LeftMotorForward, HIGH);

digitalWrite(RightMotorForward, HIGH);

digitalWrite(LeftMotorBackward, LOW);

digitalWrite(RightMotorBackward, LOW); }

Testing:
1. Ensure all the necessary connections are properly made.
2. Upload the code to the ESP32 development board.
3. Power on the robot and place it in an environment with obstacles.
4. Observe the robot's behavior as it navigates the environment.
5. Verify that the robot detects obstacles using the ultrasonic sensor.
6. Verify that the robot successfully stops when an obstacle is detected,
turns in the correct direction to avoid it, and resumes moving forward
once the obstacle is cleared.
7. Test the robot's ability to navigate different environments with
varying obstacles and distances.
8. Make any necessary adjustments to the code or sensor parameters to
optimize the robot's performance.

109
Conclusion:
The Autonomous Obstacle-Avoiding Robot with Ultrasonic Sensor project
demonstrates the implementation of an intelligent robot capable of autonomously
navigating its environment while avoiding obstacles. By utilizing an ESP32
development board, a custom motor control circuit with an IC, and an ultrasonic
sensor, the robot can detect obstacles in real time and adjust its movement to avoid
collisions.

110
Project-18
Danger Detection Robot
Introduction:
The Ultrasonic Sensor-based Obstacle Avoidance Robot project aims to build a
robot capable of detecting obstacles using an ultrasonic sensor and avoiding them
by changing its direction. The robot is equipped with an Arduino board, an
ultrasonic sensor, and motor drivers to control the movement of the robot. The
objective is to create an autonomous robot that can navigate its environment while
avoiding obstacles.
Apparatus Required:
Arduino Board: An Arduino board serves as the main controller for the
robot.
Ultrasonic Sensor: An ultrasonic sensor is used to detect the distance to
obstacles.
Motor Drivers: Motor driver modules are used to control the movement of
the robot motors.
DC Motors: Two DC motors are used to drive the wheels of the robot.
Chassis: A chassis is used to provide structural support for mounting the
components.

111
Pin Configuration:
Connect the trigPin of the ultrasonic sensor to the Arduino pin 5.
Connect the echoPin of the ultrasonic sensor to the Arduino pin 18.
Connect the motor driver pins (MOTOR1, MOTOR2, MOTOR3,
MOTOR4) to the appropriate motor control pins on the Arduino board.
Make sure the ultrasonic sensor and motors are properly powered and
connected.
Libraries Used:
The project does not require any external libraries. It uses the standard Arduino.h
library for general-purpose functions and communication with the Arduino board.
Program (Code):
const int trigPin = 5;
const int echoPin = 18;
const int MOTOR1 = 27;
const int MOTOR2 = 26;
const int MOTOR3 = 25;
const int MOTOR4 = 33;

//define sound speed in cm/uS


#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701
const int DISTANCE_THRESHOLD = 50; // centimeters

long duration;
float distanceCm;
float distanceInch;

void setup() {
Serial.begin(115200); // Starts the serial communication
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(MOTOR1, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR2, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR3, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR4, OUTPUT); // set arduino pin to output mode

112
}

void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculate the distance


distanceCm = duration * SOUND_SPEED/2;

// Convert to inches
distanceInch = distanceCm * CM_TO_INCH;

// Prints the distance in the Serial Monitor


Serial.print("Distance (cm): ");
Serial.println(distanceCm);
Serial.print("Distance (inch): ");
Serial.println(distanceInch);
if( distanceCm < DISTANCE_THRESHOLD)
{
digitalWrite(MOTOR1, LOW);
digitalWrite(MOTOR3, LOW);

digitalWrite(MOTOR2, HIGH);
digitalWrite(MOTOR4, HIGH);
delay(1000);

113
else
{

digitalWrite(MOTOR1,HIGH);
digitalWrite(MOTOR3,HIGH);
digitalWrite(MOTOR2,LOW);
digitalWrite(MOTOR4,LOW);

delay(100);
}

Working: Collision Avoidance Robot successfully detects obstacles using an


ultrasonic sensor and adjusts its movement to avoid collisions. Here's a step-by-
step description of its working:
1. Initialization: The Arduino board is powered on, and the necessary pins are
configured for input and output.
2. Ultrasonic Sensor: The ultrasonic sensor is used to measure the distance to
obstacles. The trigPin is set as an output to send a signal, and the echoPin is
set as an input to receive the echo.
3. Distance Calculation: The duration of the echo pulse is measured using the
`pulseIn()` function, which returns the sound wave travel time in
microseconds. The distance is calculated by multiplying the duration by the
speed of sound divided by 2.
4. Conversion to Inches: The calculated distance in centimeters is then
converted to inches using the conversion factor.
5. Serial Output: The measured distance in centimeters and inches is
displayed on the Serial Monitor for monitoring and debugging purposes.
6. Motor Control: Based on the measured distance, if it is less than the
predefined threshold distance, the motors are controlled to change the
direction of the robot and avoid the obstacle. If the distance is greater than
the threshold, the motors continue to move forward.
7. Delay: A small delay of 100 milliseconds is added to allow for continuous
measurement and adjustment of the robot's movement.

114
Conclusion:
The Ultrasonic Sensor-based Obstacle Avoidance Robot demonstrates the
successful implementation of an obstacle avoidance mechanism using an ultrasonic
sensor and motor control. By accurately measuring the distance to obstacles, the
robot can make real-time decisions to navigate its environment safely. The project
showcases the use of an Arduino board and basic components to create an
autonomous robot capable of obstacle avoidance. With further enhancements and
integration, this project can serve as a foundation for developing more advanced
robotic systems in various applications.

115
Project-19
Robotic Radar
Introduction:
The Robo-Radar project aims to create a distance measurement system using an
ultrasonic sensor and servo motor. The system utilizes an ESP32 development
board, an ultrasonic sensor, a servo motor, and an LCD. It rotates the ultrasonic
sensor using the servo motor to measure distances in different directions. The
objective is to provide an efficient and accurate distance measurement system for
various applications.
Apparatus Required:
ESP32 Development Board: The ESP32 serves as the main controller and
provides the necessary processing power and I/O capabilities.
Ultrasonic Sensor: An ultrasonic sensor is used to measure the distance to
objects.
Servo Motor: A servo motor is used to rotate the ultrasonic sensor for
distance measurements in different directions.
Liquid Crystal Display (LCD): An LCD is used to display the measured
distances.

116
Pin Configuration:
Ultrasonic Sensor:
Trig Pin: Connected to pin 5 of the ESP32 (configurable)
Echo Pin: Connected to pin 18 of the ESP32 (configurable)
Servo Motor:
Signal Pin: Connected to pin 15 of the ESP32
LCD:
I2C SDA Pin: Connected to the corresponding SDA pin on the ESP32
(usually pin 21)
I2C SCL Pin: Connected to the corresponding SCL pin on the ESP32
(usually pin 22)

Libraries Used:
ESP32Servo.h: The library for controlling servo motors on the ESP32.
LiquidCrystal_I2C.h: The library for controlling LCDs using the I2C
communication protocol.
Program (Code):
#include <Arduino.h>

#include <ESP32Servo.h>

#include <LiquidCrystal_I2C.h>

const int trigPin = 5;

const int echoPin = 18;

long duration;

int distance;

int delayp = 2000;

unsigned long time_now = 0;

Servo myServo;

LiquidCrystal_I2C lcd(0x3f, 16, 2);

void setup() {

117
pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

Serial.begin(9600);

lcd.begin();

lcd.backlight();

lcd.setCursor(0, 0);

myServo.attach(15);

lcd.print("ROBO-RADAR");

delay(2000);

lcd.clear();

void loop() {

for (int i = 15; i <= 165; i++) {

myServo.write(i);

delay(30);

distance = calculateDistance();

Serial.print(i);

Serial.print(",");

Serial.print(distance);

Serial.print(".");

lcd.setCursor(0, 0);

lcd.print("Distance:-");

lcd.setCursor(0, 1);

lcd.print(distance);

if (millis() >= time_now + delayp) {

time_now += delayp;

lcd.clear();

for (int i = 165; i > 15; i--)

118
{

myServo.write(i);

delay(30);

distance = calculateDistance();

Serial.print(i);

Serial.print(",");

Serial.print(distance);

Serial.print(".");

lcd.setCursor(0, 0);

lcd.print("Distance:-");

lcd.setCursor(0, 1);

lcd.print(distance);

if (millis() >= time_now + delayp) {

time_now += delayp;

lcd.clear();

int calculateDistance() {

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = duration * 0.034 / 2;

return distance;

Working:
1. Initialization: The pins for the ultrasonic sensor, servo motor, and LCD are
set up. The servo motor is attached to the specified pin, and the LCD is
initialized.

119
2. Distance Measurement: The system rotates the servo motor from 15 to 165
degrees. For each degree, it measures the distance using the ultrasonic sensor
and calculates the distance in centimeters.
3. Serial Communication and LCD Display: The degree and distance values
are sent via serial communication for monitoring. The measured distance is
also displayed on the LCD.
4. Delay and Clearing: After a specified delay, the LCD display is cleared to
prepare for the next measurement.
5. Reversing Direction: The system then reverses the servo motor rotation,
measuring the distance from 165 to 15 degrees in the same manner.
6. Loop Continuation: The process repeats continuously, providing
continuous distance measurements and updating the LCD display.
Testing:
1. Connect the ultrasonic sensor, servo motor, and LCD to the ESP32
development board as per the pin configuration mentioned above.
2. Upload the provided code to the ESP32 board.
3. Power up the system and observe the LCD display.
4. The LCD will show the title "ROBO-RADAR" for 2 seconds and then
clear the display.
5. The servo motor will start rotating from 15 to 165 degrees in steps of 1
degree, measuring the distance using the ultrasonic sensor.
6. The measured distance, along with the corresponding degree, will be
displayed on the serial monitor.
7. Simultaneously, the LCD display will show the current distance
measurement.
8. After a specified delay, the LCD display will be cleared, preparing for the
next measurement.
9. The servo motor will then reverse its rotation direction, measuring the
distance from 165 to 15 degrees.
10. Repeat the testing process to ensure continuous and accurate distance
measurements.
Conclusion:
The Robo-Radar project successfully measures distances using an ultrasonic sensor
and displays the results on an LCD. By utilizing an ESP32 development board,
servo motor, and LCD, the system provides a reliable and interactive distance
measurement solution. Through proper testing and calibration, the system can be
fine-tuned for various applications requiring distance measurements

120
Project-20
Accident Preventor with Pre-Warning
Introduction:
The Accident Preventor with Pre-Warning project aims to develop a system that
can detect potential accidents and provide pre-warning signals to prevent them.
The system utilizes various sensors, including ultrasonic sensors and motor
controllers, along with an ESP32 microcontroller and the Firebase real-time
database. The objective is to create an intelligent system that can detect obstacles
or hazardous conditions in real time and take preventive actions to avoid accidents.
Apparatus Required:
1. ESP32 Microcontroller: The ESP32 serves as the main controller and
provides the necessary processing power and Wi-Fi connectivity.
2. Ultrasonic Sensors: Ultrasonic sensors are used to measure distances and
detect obstacles in the surroundings.
3. Motor Controllers: Motor controllers are used to control the movement of
motors or actuators for accident prevention.
4. Custom-Designed PCB: A custom-designed PCB can be used for circuit
connections and mounting the components, providing a compact and
organized setup.
5. Firebase Real-time Database: The Firebase database is utilized for storing
and accessing real-time data from the system.

121
Pin Configuration:
Ultrasonic Sensor:
Trig Pin: Connected to a digital pin of the ESP32 (e.g., Pin 5).
Echo Pin: Connected to a digital pin of the ESP32 (e.g., Pin 18).
Motor Pin:
Motor 1 Pin: Connected to a digital pin of the ESP32 (e.g., Pin 27).
Motor 2 Pin: Connected to a digital pin of the ESP32 (e.g., Pin 26).
Motor 3 Pin: Connected to a digital pin of the ESP32 (e.g., Pin 33).
Motor 4 Pin: Connected to a digital pin of the ESP32 (e.g., Pin 25).
Library Used and Link: The project utilizes the following library:
FirebaseESP32.h: This library enables communication with the Firebase
real-time database. The library can be found at:
Program:
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <LiquidCrystal_I2C.h>
/////////Change this ID before Uploading/////////////////////////////////////////////////////////
String your_ID = "9876543210";
//Definations
#define WIFI_SSID "Rank2Top" //WiFi Credentials
#define WIFI_PASSWORD "123456789"
#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"
#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"
const int trigPin = 5;
const int echoPin = 18;
const int MOTOR1 = 27;
const int MOTOR2 = 26;
const int MOTOR3 = 25;
const int MOTOR4 = 33;
FirebaseData firebaseData;
LiquidCrystal_I2C lcd(0x3f, 16, 2);

122
//define sound speed in cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701
const int DISTANCE_THRESHOLD = 50; // centimeters
long duration;
float distanceCm;
float distanceInch;
void setup() {
Serial.begin(115200); // Starts the serial communication
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(MOTOR1, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR2, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR3, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR4, OUTPUT); // set arduino pin to output mode
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
lcd.print("Connected");
delay(2000);

123
// Print the IP address
/*Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");*/
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
lcd.clear();
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculate the distance
distanceCm = duration * SOUND_SPEED / 2;
// Convert to inches
distanceInch = distanceCm * CM_TO_INCH;
// Prints the distance in the Serial Monitor
Serial.print("Distance (cm): ");
Serial.println(distanceCm);
Serial.print("Distance (inch): ");
Serial.println(distanceInch);
if ( distanceCm >= 100)
{
digitalWrite(MOTOR1, LOW);
digitalWrite(MOTOR3, HIGH);

124
digitalWrite(MOTOR2, HIGH);
digitalWrite(MOTOR4, LOW);
Firebase.setString(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/RoboDetection/Value", "driving");
delay(1000);

else if (distanceCm < 100 && distanceCm > 30)


{
digitalWrite(MOTOR1, HIGH);
digitalWrite(MOTOR3, LOW);
digitalWrite(MOTOR2, LOW);
digitalWrite(MOTOR4, HIGH);
Firebase.setString(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/RoboDetection/Value", "danger");
}
else if (distanceCm <= 20)
{
digitalWrite(MOTOR1, LOW);
digitalWrite(MOTOR3, LOW);
digitalWrite(MOTOR2, LOW);
digitalWrite(MOTOR4, LOW);
Firebase.setString(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/RoboDetection/Value", "crashed");
}
delay(100);
}
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <LiquidCrystal_I2C.h>

/////////Change this ID before Uploading/////////////////////////////////////////////////////////


String your_ID = "9876543210";

125
//Definations
#define WIFI_SSID "Rank2Top" //WiFi Credentials
#define WIFI_PASSWORD "123456789"
#define FIREBASE_AUTH "OBjSvYLgZr3hPxT4DBozCwnOdMNdjn7J0ixx0jsU"
#define FIREBASE_HOST "eduproject-656d8-default-rtdb.firebaseio.com"
const int trigPin = 5;
const int echoPin = 18;
const int MOTOR1 = 27;
const int MOTOR2 = 26;
const int MOTOR3 = 25;
const int MOTOR4 = 33;
FirebaseData firebaseData;
LiquidCrystal_I2C lcd(0x3f, 16, 2);

//define sound speed in cm/uS


#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701
const int DISTANCE_THRESHOLD = 50; // centimeters
long duration;
float distanceCm;
float distanceInch;
void setup() {
Serial.begin(115200); // Starts the serial communication
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(MOTOR1, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR2, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR3, OUTPUT); // set arduino pin to output mode
pinMode(MOTOR4, OUTPUT); // set arduino pin to output mode

126
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
lcd.print("Connected");
delay(2000);
// Print the IP address
/*Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");*/
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
lcd.clear();
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

127
duration = pulseIn(echoPin, HIGH);

// Calculate the distance


distanceCm = duration * SOUND_SPEED / 2;

// Convert to inches
distanceInch = distanceCm * CM_TO_INCH;

// Prints the distance in the Serial Monitor


Serial.print("Distance (cm): ");
Serial.println(distanceCm);
Serial.print("Distance (inch): ");
Serial.println(distanceInch);
if ( distanceCm >= 100)
{
digitalWrite(MOTOR1, LOW);
digitalWrite(MOTOR3, HIGH);
digitalWrite(MOTOR2, HIGH);
digitalWrite(MOTOR4, LOW);
Firebase.setString(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/RoboDetection/Value", "driving");
delay(1000);
}
else if (distanceCm < 100 && distanceCm > 30)
{
digitalWrite(MOTOR1, HIGH);
digitalWrite(MOTOR3, LOW);
digitalWrite(MOTOR2, LOW);
digitalWrite(MOTOR4, HIGH);
Firebase.setString(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/RoboDetection/Value", "danger");
}
else if (distanceCm <= 20)
{

128
digitalWrite(MOTOR1, LOW);
digitalWrite(MOTOR3, LOW);
digitalWrite(MOTOR2, LOW);
digitalWrite(MOTOR4, LOW);
Firebase.setString(firebaseData, "IOTtech/RoboKIT/" + your_ID + "/RoboDetection/Value", "crashed");
}
delay(100);
}

Working:
1. Initialization: The ESP32 microcontroller is initialized, and the necessary
pins are configured. Wi-Fi connectivity is established by connecting to the
specified network.
2. Ultrasonic Sensor: The ultrasonic sensor is used to measure distances by
sending and receiving sound waves. The distance to the nearest obstacle is
calculated based on the time taken for the sound wave to travel.
3. Accident Prevention Actions: Based on the distance measured, the system
performs different actions to prevent accidents. If the distance is above 100
cm, the system moves forward. If the distance is between 30 cm and 100 cm,
a pre-warning signal is activated. If the distance is below 20 cm, an
emergency stop is initiated.
4. Firebase Integration: The system updates the Firebase real-time database
with the current status of accident prevention actions.
5. Loop Continuation: The loop continues, continuously measuring distances
and performing accident prevention actions based on real-time data.

Testing:
1. Connect the ESP32 microcontroller to a power source and ensure it is properly
programmed with the provided code.
2. Ensure that the Wi-Fi credentials in the code are updated with your network's
SSID and password.
3. Connect.

129
4. the motor controllers to the corresponding motor pins on the ESP32 board.
5. Power on the system and observe the LCD display (if included).
6. The system will start measuring distances using the ultrasonic sensor.
7. Depending on the distance measured, the system will perform different actions:
moving forward, activating a pre-warning signal, or initiating an emergency
stop.
8. Monitor the Firebase real-time database to ensure that the accident prevention
actions are being updated correctly.
9. Observe the motor behavior and the displayed status on the LCD (if included)
to verify that the system is functioning as expected.
Conclusion:
The Accident Preventor with Pre-Warning system successfully detects potential
accidents and takes preventive actions to ensure safety. By utilizing ultrasonic
sensors, motor controllers, and the Firebase real-time database, the system provides
real-time monitoring and updates of accident prevention actions. The integration of
the ESP32 microcontroller enables intelligent decision-making based on distance
measurements. The system can be further enhanced and customized to meet
specific application requirements. Overall, the Accident Preventor with Pre-
Warning project serves as a foundation for developing advanced accident
prevention systems in various domains.

130
IOTtech Smart
PRODUCTS PVT. LTD.

op.com
2t
k
www.ran

Plot No. 13, 3rd Floor, Pocket B, Sector 17 Dwarka, New Delhi,
Delhi 110075
www.rank2top.com, www.yantram.online 2

You might also like