Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
42 views

Basic Top 10 Arduino Based Projects - 10 Arduino Projects

This document provides an introduction to and overview of 10 basic Arduino projects for students. It includes a dedication to helping students learn Arduino basics. The 10 projects are then listed and described briefly, including an Arduino-based motion detection system using a PIR sensor. The document also provides the code for controlling an LED based on the PIR sensor's output as the first of the 10 basic projects.

Uploaded by

djedaiy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Basic Top 10 Arduino Based Projects - 10 Arduino Projects

This document provides an introduction to and overview of 10 basic Arduino projects for students. It includes a dedication to helping students learn Arduino basics. The 10 projects are then listed and described briefly, including an Arduino-based motion detection system using a PIR sensor. The document also provides the code for controlling an LED based on the PIR sensor's output as the first of the 10 basic projects.

Uploaded by

djedaiy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Basic Top 10

Arduino Based Project


This book teaches how to make basic top 10 arduino based
projects. And then students can make more advanced
projects with the help of these projects.

Author
Vijay Verma
(Programmer & Projects Designer)

Dedication
This book is for all those students who want to learn how
to make Arduino based projects. And if you want to make
projects based on your ideas, then all of them can take
help of this book. With the help of this book, from 8 class
students to 12 class students, it can get the basic
knowledge of Arduino projects. This book is also for all
those students. Those who either doing engineering or
want to do engineering (Electronics Engineering,
Electronics Communication Engineering, Computer
Science Engineering, Information Technology
Engineering). This book will help them to complete their
basic for all of them. After reading this book and using all
its formulas, you will found the increment in your
knowledge, And I can say this with conviction.

Introduction
In this book, ten basic projects of Arduino have been taught
to make. With the help of which students will be able to
complete their base. And with the help of these projects,
students can also design projects based on their ideas. And
you can submit the projects you have created in school and
college and also in exhibition. The program of all these ten
basic projects has also been taught to make correct, so that
you can develop the program further on the basis of your
ideas.

Basic Top 10 Projects List


1. Arduino Based PIR Sensor System
2. Arduino Based LDR Security System
3. IR Sensor Based Security System
4. Moisture Detector System
5. Fire Alarm System
6. Arduino and Ultrasonic Sensor Based Security
System
7. Arduino Control Servo Motor
8. Arduino Based Ultrasonic Control Servo Motor
9. Arduino Control Liquid Crystal Display
10. Arduino Based Temperature & Humidity Control
System

1- Arduino Based PIR Sensor System


Material List-
1- Arduino UNO
2- PIR Sensor
3- LED
4- Jumper Wires
5- Breadboard
6- USB
7- System(PC/Laptop)

Important Components-
PIR Sensor- PIR sensors allow you to sense motion,
almost always used to detect whether a human has moved in or out
of the sensors range. They are small, inexpensive, low-power, easy
to use and don't wear out. ... They are often referred to as PIR,
"Passive Infrared", "Pyroelectric", or "IR motion" sensors.
Project Working-
“Through this system we will turn ON and OFF the LED from
the PIR sensor. And we can build security system with the help of
this system. And we can build home automation with the help of
this system. And by looking at this circuit, we will make
connections to all these components.”

Circuit Diagram-

Now, we make a program of Arduino to operate this system.


And we will make the program as well as understand it.

Through this program, we will turn the LED ON and OFF with the
PIR sensor. So for this, we have to declare the PIR sensor in the
declaration statement and the pins for the LED. And if PIR Sensor
is a sensor, then we will declare a variable for the value of its
sensor and if the value of the sensor is first placed on the LOW,
then we will also declare a variable for this, so we can also keep
the value of the sensor at HIGH. But for now we will keep the
sensor value at LOW and for this we will declare the variable. So
first we will declare the pin for LED like we did in the previous
program - int LED = 13; This is fixed to the 13 number pin LED,
after this, we will declare the pin for the PIR sensor, for this we
will write - int pir_pin = 7; In this way, pin 7 is fixed for the
sensor. We know that LED is used only in the output mode and we
had understood that all sensors are used in the input mode, so we
will write the mode input of the PIR sensor. And all the sensors
we use have values in 0 and 1 state and 0 means low state and 1
means high state. Now we will declare a variable to keep the value
of the sensor zero - int value = 0 ; This will cause the sensor value
to be 0 in the starting and then we will loop in the program and
change the value of the sensor to 0 and 1 again and again as if the
value of the sensor is now 0, its state will be LOW, then we will
also declare a variable for its state.- int pirState = LOW; Our
declaration statement for this program has been completed. Now
we will complete the void setup part of this program, so in this, we
have to first see how many components we are using in our
program. And how many components have been declared variable
like we have done two components in this program right now.
LED and PIR sensor then we will write the pin mode statement. So
we know that for LED we keep the pin output (OUTPUT). Then
we will write- pinMode(LED,OUTPUT); And we will keep the
pinnode input (INPUT) for the PIR sensor then we will write. -
pinMode (pir_pin, INPUT); After this, we have to set the baud rate
in the program for the speed at which data is to be communicated
to our Arduino and system via USB. Use the serial begin
(Serial.begin) command to set the baud rate. What do we need to
keep the baud rate in our program. We will know this only from
our Arduino software and according to the baud rate given in the
software, we keep the baud rate in our program. Now we will write
the baud rate in our program - Serial.begin (9600); And all the
statements that we have written in the voice setup will be written
inside the curly bracket {.....}, now we will write the program in
void loop, in this we will also program curly bracket {.....} }
Inside. In this, we will first read the value of the sensor, for this we
write a statement. Right now the sensor will connect to the digital
pin 7 of Arduino so we will write in it- value = digitaRead
(pir_pin); In this, we have used digitalRead () command to read the
value of the PIR sensor. We know that whatever statement is
written in the void loop will be repeated. Now we have written a
statement to read the value of the sensor. If the value of the sensor
is 1 i.e. High (HIGH) then the LED will also be in High state
(HIGH) i.e. LED will also be ON and if the value of the sensor is
not 1 ie Low then the LED will remain in the LOW state. That is,
the LED will be off. We have to use ifelse loop to apply this
condition in the program, then let us see how we will use it. If the
sensor value is high then this statement will execute.

If the sensor value is not high then this statement will execute.

Now understand why this is written. digitalWrite () is a function /


command This function is used to write a higher or lower value to
a digital pin. If the pin is configured as an OUTPUT with pinmod
(), then its voltage will be set to this value: after this our program is
complete, now we will upload this program to Arduino. And then
according to the program, we connect all the components to the
Arduino. Now as soon as we move an object in front of the PIR
sensor or if an object comes in front of it, the LED will be turned
on. This is happening becausearrival of an object in front of the
sensor, the value of the sensor is getting high (HIGH), then the
condition with if will run at this time and when an object is not in
front of it, then its value will remain low (LOW) and it will remain
in the LED OFF state, then this time the condition with else will
run. And thus the loop of ifelse will continue in this way. Now we
make the complete program.

Program-
int LED = 13;
int pir_pin = 7;
int value = 0;
int pirState = LOW;
void setup() {
pinMode(LED, OUTPUT);
pinMode(pir_pin, INPUT);
Serial.begin(9600);
}
void loop() {
value = digitalRead(pir_pin);
if (value == HIGH) {
digitalWrite(LED, HIGH);
}
else{
digitalWrite(LED, LOW);
}
}

2- Arduino Based LDR Security System


Material List-
1- Arduino UNO
2- LDR
3- LED
4- 1k OHM Resistance
5- Jumper Wires
6- Breadboard
7- USB
8- System(PC/Laptop)
Important Component-
LDR- A Light Dependent Resistor (LDR) is also called a
photoresistor or a cadmium sulfide (CdS) cell. ... It is basically a
photocell that works on the principle of photoconductivity. The
passive component is basically a resistor whose resistance value
decreases when the intensity of light decreases.
Project Working-
“Through this system we will turn ON and OFF the LED from the
LDR sensor. And we can build security system with the help of
this system. With the help of this system we can also build
automatic ON and OFF street light system. And by looking at this
circuit, we will make connections to all these components.”

Circuit Diagram-

Now, we make a program of Arduino to operate this system.


And we will make the program as well as understand it.
Through this program, we will turn the LED ON and OFF with the
LDR (Light Depand Resistor) sensor. So for this, we have to
declare the LDR sensor and the pins for the LED in the declaration
statement. So first we will declare the pin for LED like we did in
the previous program - int LED = 13; This is fixed to the 13
number pin LED, after this we will declare the pin for the LDR
sensor, then we will write for it- int LDR = A0; In this way, pin A0
for the sensor is fixed, we have declared A0 for LDR i.e. Analog
Pin. We know that LED is used only in the output mode and we
had understood that all sensors are used in the input mode, so we
will write the mode input of the LDR sensor as the LDR is a light
demand register, so the value of this resistor depends on the light
of the light If it does, then as the light on this sensor slows down,
then this sensor will turn on the LED after a time. So we have to
set a value for this sensor which will depend on its darkness that
when it is dark on the LDR, then when the value of this resistor
becomes light on (ON) we will change the value of this sensor to
the part with void loop. Now we will complete the void setup part
of this program, so in this, we have to first see how many
components we are using in our program. And how many
components have been declared variable like we have just used
two components in this program. LED and LDR sensor, then we
will write the pin mode statement. So we know that for LED we
keep the pin output (OUTPUT). So we will write - pinMode (LED,
OUTPUT); And we'll keep the pinnode input (INPUT) for the
LDR sensor, then we'll write. PinMode (LDR, INPUT); After this,
how much speed we have to communicate with our Arduino and
system via USB. For this, we have to set the baud rate in the
program. Use the serial begin (Serial.begin) command to set the
baud rate. What we want to keep the baud rate in our program, we
will know from our Arduino software itself and according to the
baud rate given in the software, we keep the baud rate in our
program. Now we will write the baud rate in our program-
Serial.begin(9600); And all the statements that we have written in
voice setup, all of them must be written inside the curly bracket
{.....}. Now we will write the program in void loop, in this we also
write the program inside curly bracket {.....}, in this we will first
read the value of the sensor, for this we write the statement. Right
now the sensor will connect to Arduino's analog pin A0 so we will
write in it-int LDRStatus =analogRead (LDR); In this we have
used digitalRead () command to read the value of LDR sensor. We
know that whatever statement is written in void loop will be
repeated again and again. Now we have write a statement to read
the value of the sensor. If the value of the sensor is 1 i.e. High
(HIGH) then the LED will also be in High state (HIGH) i.e. LED
will also be ON and if the value of the sensor is not 1 i.e. Low then
the LED will remain in the LOW state. That is, the LED will be
off. We have to use ifelse loop to apply this condition in the
program, then let us see how we will use it. If the sensor value is
high then this statement will execute. We will use the ifelse loop in
this program and we will write a value of the sensor in the if
statement itself. Now we write in the if block of the loop if-if
(LDRStatus <= 300); If the value of the LDR sensor or the status
of the LDR sensor is equal to or less than 300, then the statement
of the BALLE block will be executed. And when the program of
the block with if is executed then the statement to turn the LED on
is written in it. digitalWrite(LED, HIGH); If that statement is
executed then LED will be turned on and when LED is on, then we
want to print a message on the serial monitor of Arduino also, for
this we will use the Serial.println () function. And inside its
parenthesis, we will write the message that we have to print, then
we will write- Serial.println("LDR is DARK, LED is ON"); And if
the value of the LDR sensor or the status of the LDR sensor is
more than 300, then the else block will execute. In this, the
statement of LED being off is written - digitalWrite (LED, LOW);
So this statement will be executed. Then the LED will be OFF and
when the LED is OFF then we want to print another message on
the serial monitor of Arduino again, then we will write that
message inside the parenthesis of the function- Serial.println("LDR
is Light, LED is OFF"); So in this way we have made a program of
LED with LDR, when we use this project, when the LDR is dark
on the sensor, the LED will automatically turn ON. And when the
light is on the LDR, the LED will be off and thus the ifelse loop
will continue in this way. We can create many projects through this
program, such as - security system, Home Automation System,
Automatic Night Lamp, etc. Now we make the complete program.
Program-
int LED = 13;
int LDR = A0;
void setup() {
pinMode(LED, OUTPUT);
pinMode(LDR, INPUT);
Serial.begin(9600);
}
void loop() {
int LDRStatus = analogRead(LDR);
if (LDRStatus <=300) {
digitalWrite(LED, HIGH);
Serial.println("LDR is DARK, LED is ON");
}
else {
digitalWrite(LED, LOW);
Serial.println("LDR is Light, LED is OFF");
}
}

3- IR Sensor Based Security System


Material List-
1- Arduino UNO
2- IR Sensor
3- 5v Relay Kit
4- Buzzer
5- Jumper Wire
6- Breadboard
7- USB
8- System(PC/Laptop)

Important Component-
IR Sensor- IR sensor is an electronic device, that emits the
light in order to sense some object of the surroundings. An IR
sensor can measure the heat of an object as well as detects the
motion. Usually, in the infrared spectrum, all the objects radiate
some form of thermal radiation.
Project Working-
“Through this system we will Operate the Relay and Buzzer from
the IR sensor. And we can build security system and object
detection system and automatic hand wash system with the help of
this system. And we can build automation Project with the help of
this system. And by looking at this circuit, we will make
connections to all these components.”

Circuit Diagram-
Now, we make a program of Arduino to operate this system.
And we will make the program as well as understand it.

Through this program, we will operate Relay and Buzzer from IR


sensor. So for this, we have to declare the IR sensor in the
declaration statement and the pins for Relay and Buzzer. So first
we will declare PIN for Relay, then we know how to declare, then
we will write - int Relay = 13; We can keep more than the variable
name relay (Relay), now the number 13 pin has been fixed for
relay (Relay). Now we will declare the variable for Buzzer and for
that we will define the pin. - int Buzzer = 7; Right now the
number 7 pin has been fixed for the buzzer. After this, we will
declare the pin for the IR sensor, for this we will write - int IR =
A0; In this way, pin A0 for the sensor is fixed. We have declared
A0 for Analog pin ie IR. All the sensors that we use have values in
0 and 1 state and 0 means low state and 1 means high state. Now
we will declare a variable to keep the value of the sensor zero. int
sensorValue=0; With this, the sensor value will remain 0 in the
starting and then we will loop the program and change the value of
the sensor to 0 and 1 again and again as the value of the sensor is 0
then its state will be LOW. Now we will complete the void setup
part of this program, so in this, we have to first see how many
components we are using in our program. And how many
components have been declared variable like we have just used
three components in this program. Relay and Buzzer and IR sensor
then we will write PIN mode statement. So for Relay and Buzzer
we keep PinMode output (OUTPUT). So we will write for Relay-
pinMode (Relay, OUTPUT); And for Buzzer we will write-
pinMode (Relay, OUTPUT); And we will keep the pinnode input
(INPUT) for the IR sensor, then we will write.- pinMode(IR,
INPUT); After this, we have to set the baud rate in the program
for the speed at which data is to be communicated to our Arduino
and system via USB. Use the serial begin (Serial.begin) command
to set the baud rate. What we want to keep the baud rate in our
program, we will know from our Arduino software itself and
according to the baud rate given in the software, we keep the baud
rate in our program. Now we will write the baud rate in our
program. - Serial.begin(9600); And all the statements that we have
written in void setup will all be written inside curly bracket {.....}
Now we will write the program in void loop, in this we will also
program curly bracket {..... }, We will first read the value of the
sensor in it, for this we write the statement. Right now the sensor is
connected to Analog pin A0 of Arduino.So we will write in-int
sensorValue = analogRead (IR); In this, we have used the
analogRead () command to read the value of the IR sensor. We
know that whatever statement is written in the voice loop will be
repeated. Now we have written a statement to read the value of the
sensor. If the value of the sensor is 1 ie High (HIGH) then Relay
and Buzzer will also be in high state (HIGH) i.e. Relay and Buzzer
will also become ON and if the sensor does not have a value of 1 ie
Low then Relay and Buzzer will remain in LOW state i.e. Relay
and Buzzer will remain off. We have to use ifelse loop to apply
this condition in the program, then let us see how we will use it. If
the sensor value is high then this statement will execute. We will
use the ifelse loop in this program and we will write a value of the
sensor itself in the statement of if. 200); In starting, the value of IR
sensor will be 0 and in this statement the value of sensor is set to
200. If the value of the sensor is greater than 0 and is less than 200
or equal to 200, then the statement of the if block will be executed.
And when the program of the block with if is executed, then it has
written a statement to turn Relay and Buzzer ON, then it will write
a statement to turn relay (ON) to Relay, digitalWrite (Relay,
HIGH); And the statement to turn the buzzer ON will write -
digitalWrite (Buzzer, HIGH); And both these statements will be
written inside the same Curly bracket. And if the block of this
Curly bracket is executed if the condition is true, then the relay
will be turned ON and the buzzer will also be ON. And if the
condition written in parentheses of if is false then the statement of
the block containing else will be executed and in the block of else
the statement of keeping relay (Relay) and Buzzer off is written.
So the statement to turn off relay (Relay) will say - digitalWrite
(Relay, LOW); And the statement to turn off the buzzer will say -
digitalWrite (Buzzer, LOW); So when the program of the else
block executes, the relay will be OFF and the buzzer will also be
OFF. Accordingly to this system, when an object goes in front of
the IR sensor, the relay will turn ON and the buzzer will also be
ON. And if there is no object in front of the sensor, then the lead
will remain off and in this way the loop of ifelse will continue in
this way. We can create many projects through this program, such
as - security system, Home Automation System, Automatic, etc.
Now we make the complete program

Program-
int Relay =13;
int Buzzer = 7;
int IR = A0;
int sensorValue = 0;
void setup() {
pinMode(IR, INPUT);
pinMode(Relay, OUTPUT);
pinMode(Buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(IR);
if(sensorValue<=200)
{
digitalWrite(Relay, HIGH);
digitalWrite(Buzzer, HIGH);
}
else
{
digitalWrite(Relay, LOW);
digitalWrite(Buzzer, LOW);
}
}

4- Moisture Detector System


Material List-
1- Arduino UNO
2- Soil Moisture Sensor
3- 5v Relay Kit
4- Jumper Wires
5- Breadboard
6- USB
7- System(PC/Laptop)

Important Component-
Soil Moisture Sensor- The Soil Moisture
Sensor uses capacitance to measure the water content of soil (by
measuring the dielectric permittivity of the soil, which is a function
of the water content). Simply insert this rugged sensor into
the soil to be tested, and the volumetric water content of the soil is
reported in percent.

Project Working-
“ Through this system, we will now operate the relay and buzzer
with the Soil Moisture Sensor. And we can build Automatic Water
Irrigation system and automatic water level controller for water
pump with the help of this system.”

Circuit Diagram-
Now, we make a program of Arduino to operate this system.
And we will make the program as well as understand it.

Right now we are making a program for Soil Moisture Detection,


through this program we will relay on and off with the help of Soil
Moisture Sensor. In this project, as long as there is no moisture on
the sensor, the relay will remain off and when there is no moisture
on the sensor, then the relay will remain on and the loop of ON and
OFF of the relay will continue. In this program, we first write the
declaration statement, that is, we select the PIN for Relay and
Sensor. On which pin of Arduino do we have to connect Relay and
Sensor. Like we have to connect Relay on the 13 number pin in
Arduino. And to connect the Sensor to the 8 number pin in the
Arduino. So we write for relay (int Relay = 13); And will write for
Sensor-int sensor = 8; So we have declared the variables for the
relay and the sensor, if the sensor we are using will have some
value, then we will also declare a variable to store the value of the
sensor. So we will write-int val; If we write anything next to it
after putting (double backshlash) // in our program, then that
comment will not be added to the program and these comments are
written just to understand the program like –

Now after this we go to void setup (). Now we will complete the
void setup part of this program, so in this we have to first see how
many components we are using in our program. And how many
components have been declared variable like we have just used
two components in this program. Relay and soil moisture sensor
then we will write the pin mode statement. So for Relay, we keep
the Pinod output (OUTPUT). So we will write for Relay- pinMode
(13, OUTPUT); We inside pinMode's parenthesis (13, OUTPUT);
Replace (Relay, OUTPUT); Can also write It will not matter and if
we keep the pinMode input (INPUT) for the moisture sensor then
we will write. - pinMode (8, INPUT); In this we also (8, INPUT)
inside the parenthesis of PinMode; Replace (sensor, INPUT); Can
also write. After this, we have to set the baud rate in the program
for the speed at which data is to be communicated to our Arduino
and system via USB. Use the serial begin (Serial.begin) command
to set the baud rate. What we want to keep the baud rate in our
program, we will know from our Arduino software itself and
according to the baud rate given in the software, we keep the baud
rate in our program. Now we will write the baud rate in our
program- Serial.begin(9600); And all the statements that we have
written in void setup will all be written inside curly bracket {.....}
Now we will write the program in void loop, in this we will also
program curly bracket {..... } Inside. In this, we will first read the
value of the sensor, for this we write a statement. Right now the
sensor is connected to the digital pin 8 of the Arduino. So we will
write in it- value = digitaRead(8); In its bracket also, we can write
sensor instead of 8, it will not make any difference. In this, we
have used digitalRead () command to read the value of the sensor.
We know that whatever statement is written in the void loop will
be repeated. Now we have written a statement to read the value of
the sensor. We will turn the relay on and off by Soil Moisture
Sensor. In this project the relay will be off as long as there is
moisture on the sensor. And when there is no moisture on the
sensor, the relay will remain on if the value of the sensor is high
(HIGH) ie when there is no moisture on the sensor then the Relay
will also be in the high state (HIGH) i.e. if the sensor is turned ON
and if the sensor is turned on The value is not high, that is, when
there is moisture on the sensor, then the Relay will remain in the
LOW state, ie the Relay will be off. We have to use ifelse loop to
apply this condition in the program, then let us see how we will
use it. If the sensor value is low (LOW) then this statement will
execute.

If the sensor value is high then this statement will execute.

Now understand why this is written. digitalWrite () is a function /


command This function is used to write a higher or lower value to
a digital pin. If the pin is configured as an OUTPUT with pinmod
(), then its voltage will be set to this value: after this our program is
complete, now we will upload this program to Arduino. And then
according to the program, we connect all the components to the
Arduino. Now as soon as we turn ON this project, the relay will
become ON and as soon as there is moisture on the sensor then the
relay will be off. This is happening because if the value of the
sensor decreases when the sensor is damp, then the condition of if
will run at this time, and when there is no moisture on the sensor,
then its value will remain HIGH and it will remain in the ON ON
state, then this time the else The condition will run and thus the
loop of ifelse will continue in this way. Now we make the
complete program.
Program-
int Relay = 13;
int sensor = 8; // Use soil moisture sensor
int value; //This variable stores the value received from Soil
moisture sensor.
void setup() {
pinMode(13,OUTPUT); //Set pin 13 as OUTPUT pin, to send
signal to relay
pinMode(8,INPUT); //Set pin 8 as input pin, to receive data from
Soil moisture sensor.
}
void loop() {
value = digitalRead(8); //Read data from soil moisture sensor
if(value == LOW)
{
digitalWrite(13,LOW); //if soil moisture sensor provides LOW
value send LOW value to relay
}
else
{
digitalWrite(13,HIGH); //if soil moisture sensor provides HIGH
value send HIGH value to relay
}
}
5- Arduino Based Fire Alarm System
Material List-
1- Arduino UNO
2- Fire Sensor
3- Buzzer
4- LED
5- Jumper Wires
6- Breadboard
7- USB
8- System(PC/Laptop)

Important Component-
Fire Sensor- A sensor which is most sensitive to a normal
light is known as a flame sensor. That's why this sensor module is
used in flame alarms. This sensor detects flame otherwise
wavelength within the range of 760 nm – 1100 nm from the light
source. ... The output of this sensor is an analog signal or digital
signal.
Project Working-
“Through this system, we will now operate the LED and Buzzer
with the help of Fire Sensor. And we can build Automatic Fire
Control system and Flame Detection and Fire alert System with the
help of this system.”

Circuit Diagram-
Now, we make a program of Arduino to operate this system.
And we will make the program as well as understand it.

Right now we are making a program of Fire Alarm System.


Through this program we will turn on LED and Buzzer with the
help of Fire Sensor. In this project, LED and Buzzer will remain on
as long as the Fire Flame is on the sensor and when the Fire Flame
is not on the sensor, the LED and Buzzer will remain off. In this
program, we first write the declaration statement, that is, we select
the PIN for LED and Buzzer and Sensor. That is, let's define. On
which pin of Arduino we have to connect LED and Buzzer and
Sensor. Like we have to connect the LED on the number 13 pin in
the Arduino. And to connect Buzzer to the 12 number pin in the
Arduino. And to connect the sensor to the number 11 pin in the
Arduino. So for LED we will write - int LED = 13; And will write
for Buzzer-int Buzzer = 12; And will write for Sensor- int
sensorPin = 11; So we have declared the variables for LED,
Buzzer and sensor. If the sensor we are using will have some
value, then we will also declare a variable to store the value of the
sensor. So we'll write-int sensorState; The value of sensors is only
in the count of 0 and 1 i.e. 0 means Low (LOW) state and 1 means
HIGH state. Now after this we go to void setup ().Now we will
complete the void setup part of this program, so in this we have to
first see how many components we are using in our program. And
how many components have been declared variable, just as we
have used three components in this program. LED, Buzzer and Fire
sensor then we will write the pin mode statement. So for the LED,
we keep the pin output (OUTPUT). So we will write the pinMode
statement for LED - pinMode (LED, OUTPUT); Inside the
parenthesis of pinMode (LED, OUTPUT); Replace (13,
OUTPUT); Can also write It will not matter, we will also write a
pinMode statement for Buzzer- pinMode (Buzzer, OUTPUT); We
inside the parenthesis of pinMode (Buzzer, OUTPUT); Replace
(12, OUTPUT); Can also write. It will not make any difference
and we will keep pinMode input (INPUT) for Fire Sensor, then we
will write pinMode statement for Sensor. - pinMode (sensor,
INPUT); In this also, we inside the parenthesis of pinMode
(sensor, INPUT); Replace (11, INPUT); Can also write After this,
how much speed we have to communicate with our Arduino and
system via USB. For this, we have to set the baud rate in the
program. Use the serial begin (Serial.begin) command to set the
baud rate. What we want to keep the baud rate in our program, we
will know from our Arduino software itself and according to the
baud rate given in the software, we keep the baud rate in our
program. Now we will write the baud rate in our program -
Serial.begin (9600); And all the statements that we have written in
void setup will all be written inside curly bracket {.....} Now we
will write the program in void loop, in this we will also program
curly bracket {..... }, We will first read the value of the sensor in it,
for this we write the statement. Right now the sensor is connected
to the digital pin 11 of the Arduino. So we will write in it- value =
digitaRead(11); In its bracket also, we can write sensorPin instead
of 11, it will not matter. In this, we have used digitalRead ()
command to read the value of the sensor. We know that whatever
statement is written in the void loop will be repeated. Now we
have written a statement to read the value of the sensor. We will
turn on and off the LED, Buzzer through the Fire Sensor. In this
project, LED and Buzzer will remain on as long as the Fire Flame
is on the sensor and when the Fire Flame is not on the sensor, the
LED and Buzzer will be off. If the value of the sensor is high
(HIGH) i.e. when the sensor has a Fire Flame then the LED,
Buzzer will also be in high state (HIGH) i.e. LED, Buzzer will also
become ON and if the value of the sensor is not high ie when If
there is no Fire Flame on the sensor, the LED will remain in the
Buzzer LOW state, ie the LED and Buzzer will be off. We have to
use ifelse loop to apply this condition in the program, then let us
see how we will use it. So we have read the value of the sensor, if
the value of the sensor is high then this statement will execute.

If the sensor value is LOW then this statement will execute.

Now understand why this is written. digitalWrite () is a function /


command This function is used to write a higher or lower value to
a digital pin. If the pin is configured as an OUTPUT with pinmod
(), then its voltage will be set to this value: after this our program is
complete, now we will upload this program to Arduino. And then
according to the program, we connect all the components to the
Arduino. Now after turning this project ON, as soon as we move
the Fire Flame to the Fire Sensor, the LED will become Buzzer
ON and when the Fire Sensor has the Fire Flame If not, then the
LED, Buzzer will be off. This is happening because if the value of
the sensor becomes HIGH when the Fire Flame comes on the
sensor, then the condition with if will run at this time. And when
there is no Fire Flame on the sensor, then its value will remain
LOW and because of this, the LED, Buzzer will remain in the OFF
state, then the condition of the else will run at this time and the
loop of ifelse will continue in this way. Now we make the
complete program.

Program-
int LED = 13;
int Buzzer = 12;
int sensorPin = 11;
int sensorState;
void setup() {
pinMode(LED, OUTPUT);
pinMode(Buzzer,OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
sensorState = digitalRead(sensorPin);
if (sensorState == HIGH) {
digitalWrite(LED, HIGH);
digitalWrite(Buzzer, HIGH);
}
else{
digitalWrite(LED, LOW);
digitalWrite(Buzzer, LOW);
}
}

6- Arduino and Ultrasonic Sensor Based


Security System
Material List-
1- Arduino UNO
2- Ultrasonic Sensor
3- Buzzer
4- LED
5- Jumper Wires
6- Breadboard
7- USB
8- System(PC/Laptop)

Important Component-
Ultrasonic Sensor- An ultrasonic sensor is an electronic
device that measures the distance of a target object by
emitting ultrasonic sound waves, and converts the reflected sound
into an electrical signal. Ultrasonic waves travel faster than the
speed of audible sound (i.e. the sound that humans can hear).
Project Working-
“Through this system, we will now operate the LED and Buzzer
with the help of Ultrasonic Sensor. And we can build security
system and object detection system and automatic hand wash
system and automatic water dispenser machine and automatic open
and close smart dustbin with the help of this system. And we can
build automation Project with the help of this system. And by
looking at this circuit, we will make connections to all these
components.”

Circuit Diagram-

Now, we make a program of Arduino to operate this system.


And we will make the program as well as understand it.

Through this program, we will turn LED and Buzzer on and off
with the help of Ultrasonic Sensor. In this program, we will set a
distance value of the ultrasonic sensor, according to this program,
if an object comes within that distance value in front of the
ultrasonic sensor in the project, then LED and Buzzer will become
ON. In this program, we first write the declaration statement, that
is, we select the PIN for LED and Buzzer and Sensor. That is, let's
define. Here we will define two pins for ultrasonic sensors. One
for the Triger pin and one for the echo pin where the trigger pin
will be the output pin. And the echo pin will be the input pin. Like
we have to connect the LED on the number 13 pin in the Arduino.
So we will write for LED - int LED = 13;. And to connect Buzzer
to the 7 number pin in the Arduino. So we will write for Buzzer-
int Buzzer = 7; Now we have to connect the sensor's trigger and
echo pin to the Arduino. So we will connect the trigger pin to pin
number 4 of Arduino. And connect the echo pin to Arduino's pin
number 5. So for the trigger pin we will write- int trigPin = 4; And
for echo pin we will write int int echoPin = 5; So we have declared
the variables for LED, Buzzer and sensor. Ultrasonic sensor works
on duration and distance. So to store its duration and distance, we
also have to declare a variable. So we will write for the duration-
long duration; And will write for distance- int distance;
Ultrasonic sensors emit sound waves. And these waves are
reflected by the object that is inside our distance value and when
these waves are reflected, it makes the echo pin high. Then LED
and Buzzer become ON. The value of sensors is only in the count
of 0 and 1 i.e. 0 means Low (LOW) state and 1 means HIGH
state. Now after this we go to void setup (). Now we will complete
the void setup part of this program, so in this, we have to first see
how many components we are using in our program. And how
many components have been declared variable like we have just
used three components in this program. LED, Buzzer and
Ultrasonic sensor then we will write the pin mode statement. So for
the LED, we keep the pin output (OUTPUT). So we will write the
pinMode statement for LED - pinMode(LED,OUTPUT); We will
also write the pinMode statement for Buzzer- pinMode (Buzzer,
OUTPUT); And we will also write the pinMode statement for the
Ultrasonic Sensor but it has two pins, the trigger pin and the echo
pin in which the trigger pin works in the output mode and the echo
pin works in the input mode. Then we will write the Pinmode
statement for the trigger pin.- pinMode(trigPin,OUTPUT); And
for the echo pin, PinMode will write the statement - pinMode
(echoPin, INPUT); After this, we have to set the baud rate in the
program for the speed at which data is to be communicated to our
Arduino and system via USB. Use the serial begin (Serial.begin)
command to set the baud rate. What we want to keep the baud rate
in our program, we will know from our Arduino software itself and
according to the baud rate given in the software, we keep the baud
rate in our program. Now we will write the baud rate in our
program- Serial.begin(9600); And all the statements that we have
written in void setup will all be written within curly bracket {.....}
Now we will write the program in void loop, in this we will also
program curly bracket {..... } Inside it, we will keep the trigger pin
as low (LOW) for the first 2 microseconds, then see what
statement we will write for it.

After this, we will keep the trigger pin high for 10 microseconds
and will be lowered again (LOW). Now, let us see how this
statement will be written.

Now understand why this is written. digitalWrite () is a function /


command This function is used to write a higher or lower value to
a digital pin. If the pin is configured as an OUTPUT with pinmod
(), its voltage will be set to this value. In this, the trigger pin
emitted sound waves for up to 10 microseconds and then these
waves were reflected from an object when it comes back. The echo
pin goes high. In this the pulseIn () function is used to detect the
value of the echo pin. The value of is LOW. Or HIGH. And this is
equal to duration. Then we calculate the distance with the help of
duration. Now we write these statements.
Now we will do a loop of ifelse. And in the condition of if, we will
set the value of distance at which distance we have to detect an
object, then we have written in the block with if.- if (distance <=
25); This means if the object placed in front of the ultrasonic
sensor is placed 25 centimeter apart or less than the sensor, then
the echo pin will be high. Then LED and buzzer will become ON.
And if the object is placed more than 25 centimeter distance from
the sensor. Then then the block with else runs, then the LED and
buzzer remain off. So we will first write a statement of the block
containing if. Which you have already learned from the program
and how to write it. Then we will write-

Now we will write the statement of the else block.

After this, if we have to find out that the object we are detecting
with the help of ultrasonic is at a distance from the ultrasonic
sensor. So for this we will write the command Serial.println ().
And inside its parenthesis, if we write (distance), then we will see
how we write this statement.- Serial.println(distance);
And if we want to print that distance value, then for this we will
write the command Serial.print (). And inside its parenthesis we
will write ("Distance:"). You know that if we want to print
anything, we write it in double court, so we have written the
distance in double court. Now we write this statement-
Serial.print(“Distance:”) In this way our program becomes
complete. Now we make the complete program.

Program-
int LED = 13;
int Buzzer = 7;
int trigPin = 4;
int echoPin = 5;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(LED, OUTPUT);
pinMode(Buzzer,OUTPUT);
Serial.begin(9600); // Starts the serial communication
}
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);
// Calculating the distance
distance= duration*0.034/2;
if (distance <=25){
digitalWrite(LED, HIGH);
digitalWrite(Buzzer,HIGH);
}
else{
digitalWrite(LED, LOW);
digitalWrite(Buzzer,LOW);
}
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}

7- Arduino Control Servo Motor


Material List-
1- Arduino UNO
2- Servo Motor
3- Jumper Wires
4- USB
5- System(PC/Laptop)

Important Componant-
Servo Motor- A servomotor is a rotary actuator or linear
actuator that allows for precise control of angular or linear
position, velocity and acceleration. It consists of a
suitable motor coupled to a sensor for position feedback.
... Servomotors are used in applications such as robotics, CNC
machinery or automated manufacturing.

Project Working-
“Through this system, we will now operate the servo motor with
the help of arduino. And we can build barior system with the help
of this system. And we can build automation Project with the help
of this system. And by looking at this circuit, we will make
connections to all these components.”

Circuit Diagram-

Now, we make a program of Arduino to operate this system.


And we will make the program as well as understand it.

Through this program, we will first rotate the servo motor from 0
degree to 180 degree and then rotate it from 180 to 0 degree and
this loop will continue, so to make this program, first of all we
need to have the header of the servo motor. The file has to be
included like - #include <Servo.h> Now let's understand what the
header file is and why are they included. The header file is an
extension file. It has an extension of (.h) . In which a particular
topic has all the information store such as its definition and its
function and all the information related to it, such as <stdio.h>,
<conio.h>, <iostream.h> these are all header files. Like Servo.h is
also a header file. In which the servo motor will have all the
information about what to do. If we do not want to include the
header file in our program. So we have to write all the information
that is written in the header file in our program. So we add the
header file to make our program simple. And let's see how to write
it. - #include <Servo.h> Then after this we created a data type to
Servo and with this we created myservo a variable which will store
the information of servo motor. So we will write this statement. -
Servo myservo; Our servo motor will rotate from 0 degree to 180
degree and then when the again comes back, we will also create a
variable to store its position value - int pos = 0; Initially we will
keep the angle of the servo motor at 0 so we have kept its position
at 0, after that we will complete the voiced setup part of the
program. In this we will write a statement to connect the out put
pin of the servo motor to pin 9 of the Arduino but in this we will
not use the pinMode command. For this, we will use the attach
method and inside its parenthesis we will write the pin number to
which the servo motor will connect. Then write it-
myservo.attach(9); Within the voice setup, we write all the
statements inside the Curly bracket, after which we will complete
the void loop part, in this we will use the for loop. You know that
three statements are written inside the for loop. In its first
statement, we will write the first position of the servo - pos = 0;
Then in the second statement the position is checked if the servo
position is less than or equal to 180- pos <= 180; If this statement
is correct, then the control will move to the third statement and
then in the third statement the position of the servo will increase by
an angle, for this we will use the increment operator - pos + = 1

After all these processing is done, the statement written in the


Curly bracket of for will be executed once, in which the statement
to write the position of the servo motor is written. Once this
statement is run, the servo motor will take a delay time of 15
microseconds.

And after this the control will again reach the first statement of
Curly Bracket of the for (for) loop but this time it's position will be
1 and again the position will be checked in the second statement
and if the position is true this time then the control will be near the
third statement Go and then the position of the servo will increase
by an angle in the third statement, for this we will use the
increment operator - pos+=1 After all these processing is done, the
statement written in the Curly bracket of (FOR) will now be
executed once again and after that the control will again reach the
first statement of the Curly bracket of FOR loop but this time its
position will be 2 and again the second statement I will have the
position checked, and if the position is true this time, then the
control will go to the third statement and so this loop will continue
until pos<=180; This statement does not become False and this
position will only be False when the Servo turns 180 degrees and
if the position is False, then the control will of this for loop and
then the second of the control void loop Will execute the
statement. And we have also used the for loop in the second
statement but in this we will reduce the position of the servo one
by one as if the position of the servo would be 180- pos=180; Then
the second condition will be checked after this- pos>=0; If this
statement is correct then the control will go to the third statement
and then in the third statement the position of the servo will be
reduced by an angle, for this we will use the decree operator - pos-
=1

After all these processing has been done, the statement written in
the Curly bracket of (For) will be executed once. In this, statement
to write in the position of the servo motor is written. Once these
statements run the servo motor has a delay time of 15
microseconds. Will take

And after that the control will again reach the first statement of
parentheses of the (For) loop but this time its position will be 179
and again the position will be checked in the second statement and
if the position is true this time also, the control will go to the third
statement and then the third statement, the position of the servo
will be reduced by an angle and for this we will use the decreement
operator - pos-=1 After all these processing is done, the statement
written in the Curly bracket of (For) will be executed once and
after that the control will again reach the first statement of the
parenthesis of the for (for) loop, but this time its position will be
178 and then From the second statement, the position will be
checked and if this time also the position is true then the control
will go to the third statement and so this loop will continue till
pos>=0; This statement does not become False and it will be False
only when the Servo is rotated 0 degrees and then the position will
be False, then the control will come out of this for loop if After
this there is no more statement in the voice loop, then again the
control will go to the first statement of the void loop. And this way
this loop will continue. And in this way, the servo motor will rotate
from 0 degree to 180 degree and 180 degree to 0 degree like this,
now we make a complete program for it.

Program-
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo
object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to
180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in
variable 'pos'
delay(15); // waits 15ms for the servo to reach the
position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to
0 degrees
myservo.write(pos); // tell servo to go to position in
variable 'pos'
delay(15); // waits 15ms for the servo to reach the
position
}
}

8- Arduino Based Ultrasonic Sensor Control


Servo Motor
Matrerial List-
1- Arduino UNO
2- Ultrasonic Sensor
3- Servo Motor
4- Jumper Wires
5- Breadboard
6- USB
7- System(PC/Laptop)

Important Component-
Servo Motor- A servomotor is a rotary actuator or linear
actuator that allows for precise control of angular or linear
position, velocity and acceleration. It consists of a
suitable motor coupled to a sensor for position feedback.
... Servomotors are used in applications such as robotics, CNC
machinery or automated manufacturing.

Ultrasonic Sensor- An ultrasonic sensor is an electronic


device that measures the distance of a target object by
emitting ultrasonic sound waves, and converts the reflected sound
into an electrical signal. Ultrasonic waves travel faster than the
speed of audible sound (i.e. the sound that humans can hear).

Servo Motor
Ultrasonic Sensor
Project working-
“Through this System, we will control the servo motor with an
ultrasonic sensor. According to this System, as soon as an object
comes in front of the ultrasonic sensor, the servo motor will rotate
at 180 angles. And we can build Smart Dustbin and automation
Project with the help of this system. And by looking at this circuit,
we will make connections to all these components.”

Circuit Diagram-
Now, we make a program of Arduino to operate this system.
And we will make the program as well as understand it.

Through this program, we will control the servo motor with an


ultrasonic sensor. According to this program, as soon as an object
comes in front of the ultrasonic sensor, the servo motor will rotate
at 180 angles. So for this, we have to first add the header file of the
servo to this program, then we will write.- #include<Servo.h>
Then after this we made Servo a data type and with its help, we
created servo1 a variable which would store the information of the
servo motor. So we will write this statement.- Servo servo1; Now
we will define pins for ultrasonic sensors, then we will define two
pins for ultrasonic sensors. One for the Triger pin and one for the
echo pin where the trigger pin will be the output pin. And the echo
pin will be the input pin. We will connect the trigger pin to pin
number 4 of the Arduino. And connect the echo pin to Arduino's
pin number 5. So for the trigger pin we will write- int trigPin = 4;
And for echo pin we will write- int echoPin = 5; So we have
declared the variables for Servo Motor and Ultrasonic Sensor.
Ultrasonic sensor works on duration and distance. So to store its
duration and distance, we also have to declare a variable. So we
will write for the duration- long duration; And will write for
distance- long distance; Ultrasonic sensors emit sound waves. And
these waves are reflected by the object that is inside our distance
value and when these waves are reflected, it makes the echo pin
high. And then our servo motor will spin at 180 angles. The value
of all sensors is in the count of 0 and 1 i.e. 0 means low (LOW)
state and 1 means HIGH state. Now after this we go to void setup
(). Now we will complete the void setup part of this program, so in
this, we have to first see how many components we are using in
our program. And how many components have been declared
variable like we have just used two components in this program.
Servo Motor and Ultrasonic sensor then we will write the pin mode
statement. Now we will write a statement to connect the out put
pin of the servo motor to pin 7 of the Arduino but in this we will
not use the pinmod command. For this, we will use the attach
method and inside its parenthesis we will write the pin number to
which the servo motor will connect. Then write it-servo1.attach
(7); But we will also write the pinMode statement for Ultrasonic
Sensor but it has two pins, trigger pin and echo pin, in which
trigger pin works in output mode and echo pin works in input
mode. Then we will write the Pinmode statement for the trigger
pin.- pinMode(trigPin,OUTPUT); And for Echo PIN, PinMode
will write the statement- pinMode(echoPin,INPUT); After this, we
have to set the baud rate in the program for the speed at which data
is to be communicated to our Arduino and system via USB. Use
the serial begin (Serial.begin) command to set the baud rate. What
we want to keep the baud rate in our program, we will know from
our Arduino software itself and according to the baud rate given in
the software, we keep the baud rate in our program. Now we will
write the baud rate in our program- Serial.begin(9600); And all the
statements that we have written in void setup will all be written
within curly bracket {.....} Now we will write the program in void
loop, in this we will also program curly bracket {..... } Inside it, we
put the trigger pin as low (LOW) for the first 2 microseconds, then
see what statement we will write for it.

After this, we will keep the trigger pin high for 10 microseconds
and will be lowered again (LOW). Now, let us see how this
statement will be written.

Now understand why this is written. digitalWrite () is a function /


command This function is used to write a higher or lower value to
a digital pin. If the pin is configured as an OUTPUT with pinMode
(), its voltage will be set to this value.
In this, the trigger pin emitted sound waves for up to 10
microseconds and then these waves were reflected from an object
when it comes back. The echo pin goes high. In this the pulseIn ()
function is used to detect the value of the echo pin. The value of is
LOW. Or HIGH. And this is equal to duration. Then we calculate
the distance with the help of duration. Now we write these
statements.

Then after this we will write a statement to keep the angle of the
servo motor at 0, for this we will use the servo1.write () command
and write the value of the angle inside its parenthesis on which we
have to put the servo motor in the starting, then in its We will write
for- servo1.write(0);
Now we will loop the if. And in the condition of if, we will set the
value of distance at which distance we have to detect any object,
then we have written in the block with if.- if(distance<=25); This
means if the object placed in front of the ultrasonic sensor is placed
25 centremeter apart or less than the sensor, then the echo pin will
be high. So this will make our servo motor ON. And the servo
motor will rotate at 180 angles, thus our program completes. Now
we make the complete program.

Program-
#include <Servo.h>
Servo servo1;
int trigPin = 4;
int echoPin = 5;
long distance;
long duration;
void setup()
{
servo1.attach(7);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);// put your setup code here, to run
once:
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;
servo1.write(0);
if(distance <= 25){
servo1.write(180);
}
}

9- Arduino Control Liquid Crystal Display


Material List-
1- Arduino UNO
2- 16*2 LCD Display
3- 10k OHM Preset
4- Jumper Wire
5- Breadboard
6- USB
7- System(PC/Laptop)
Important Component-
LCD Display- An LCD is an electronic display module that
uses liquid crystal to produce a visible image. The 16×2 LCD
display is a very basic module commonly used in DIYs and
circuits. The 16×2 translates o a display 16 characters per line in 2
such lines. In this LCD each character is displayed in a 5×7 pixel
matrix.

10k Preset- A preset is a passive variable resistor that is used


to vary the voltage and current in the circuit as per need. This is a
three terminal PCB mount friendly device which gives variable
voltage from center pin in the range of voltage difference applied
on the two outer pins, as it is rotated.

16*2 LCD Display

10k OHM Preset


Project Working-
“Through this system we will print a message on Liquid
Crystal Display. And we can build Smart Digital Board and
make a smart Name Plate with the help of this system. And by
looking at this circuit, we will make connections to all these
components.”

Circuit Diagram-

Now, we make a program of Arduino to operate this system.


And we will make the program as well as understand it.

"Through this program, we will print a message on Liquid Crystal


Display, so to create this program, we have to first include the
header file of Liquid Crystal Display like -
#include<LiquidCrystal.h> Now let's understand what a header
file is. And why are they included.The header file is an extension
file. It has an extension of .h. In which a particular topic has all the
information store such as its definition and its function and all the
information related to it.- <stdio.h>, <conio.h>, <iostream.h>
These are all header files. Like these, LiquidCrystal.h is also a
header file. In which Liquid Crystal Display will have all the
information about what to do. If we do not want to include the
header file in our program. So we have to write all the information
that is written in the header file in our program. So we add the
header file to make our program simple. And see how to write it.-
#include< LiquidCrystal.h> In any program that we use LCD
(Liquid Crystal Display), then we have to add the
<LiquidCrystal.h> header file to that program, after that we will
first have to create variables for the pins through which we will use
LCD from Arduino (Liquid Crystal Display). Because the data we
get on those pins, we will store it in that variable first and then
show it on the LCD, all these variables will be of the same type, so
to create all these, we will use the same data type and do it once.
And then we will make all the variables in the same line. Now let's
see how to write-

The configuration of all these pins is inside this <LiquidCrystal.h>


header file, so we have to define them and tell the processor of the
software that the detail of these pins is inside this header file, so for
this we have to write a statement in our program.

Then after this we will complete the voice setup part of this
program, in this we will first have to tell how many Colomns and
how many rows are there in the LCD we are using and we will use
a command to tell it. lcd.begin( ) And inside its parenthesis, we
have to pass two comments, in the first comment we write the
number of Columns of LCD. And in the second comment, we
write the row number of the LCD, now let's see how to write it.-
lcd.begin(16, 2); Then after that we will write a statement to print
the message on the LCD, for this we use the function lcd.print ()
and inside its parenthesis in double court we write the message that
we have to print on the LCD. Just like if we want to print hello
world then we will write.- lcd.print("hello, world!"); And we have
written all the statements of void setup in curly bracket, after this
we will complete the part with void loop. In this, we will first set
the cursor in the LCD, from which commons and from which row
will we start using the set cursor function. Under its parenthesis,
we will pass two numbers. The first number means that from
which commons we have to start printing, like we wrote 0, it
means to start with Solomon first. If 2 were written then the third
would start printing from Solomon, then the second number means
that from which line we have to start printing. If we wrote 1 then
printing will start from the first row. If we write 2 then printing
will start from the second line. Now the statement Complete write-
lcd.setCursor(0, 1); We have just written (0,1) in its bracket, so
now printing will start with the first Solomon and the first row. If
we wrote (2,2) in brackets, the printing would start with the third
Solomon and the second row.
Program-
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
int RS = 12, E = 11, D4 = 5, D5 = 4, D6 = 3, D7 = 2;
LiquidCrystal lcd(RS, E, D4, D5, D6, D7);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}

10- Arduino Based Humidity & Temperature Monitoring


System
Material List-
1- Arduino UNO
2- 16*2 LCD Display
3- DHT11 Sensor
4- 10k OHM Preset
5- Breadboard
6- Jumper Wires
7- USB
8- System(PC/Laptop)
Important Component-
DHT11 Sensor- The DHT11 is a basic, ultra low-cost
digital temperature and humidity sensor. It uses a capacitive
humidity sensor and a thermistor to measure the surrounding air,
and spits out a digital signal on the data pin (no analog input pins
needed). Its fairly simple to use, but requires careful timing to grab
data.
Project Working-
“Through this System we will print Temperature and Humidity on
Liquid Crystal Display, for this we will use DHT11 sensor. . And
we can build Humidity and Temperature Monitoring System with
the help of this system. And by looking at this circuit, we will
make connections to all these components.”

Circuit Diagram-
Now, we make a program of Arduino to operate this system.
And we will make the program as well as understand it.

Through this program we will print Temperature and Humidity on


Liquid Crystal Display, for this we will use DHT11 sensor. So we
first get to know about DHT11 sensor. DHT11 is a basic, low-cost
digital temperature and humidity sensor. It uses a capacitive
humidity sensor and a thermistor to measure the surrounding air,
and gives a digital signal to the data pin. The sensor consists of 4
pins: VCC, DATA OUT, NC and GND. The voltage range for the
VCC pin is 3.5 volt to 5.5 volt. Now we further proceed for
making programs. And we first add the header file of DHT11
sensor, now let us see how we will write it- #include<dht.h> You
have to know why we have added the header file of this sensor in
this program, we will also use LCD in this program, then after that
we also add the header file of the LCD in the program, after that
we will first Variables have to be created for those pins through
which we will transfer data from Arduino to LCD (Liquid Crystal
Display). Because the data we get on those pins, we will first store
it in that variable and then show it on the LCD, all these variables
will be of the same type, so to create all these, we will use the
same data type and do it once and Then we will make all the
variables in the same line. Now let's see how to write.

After this, we'll also declare variables for DHT11 sensor. So for
this we'll write.- dht DHT; After this, we have to connect the
output pin of DHT11 sensor to the pin of Arduino. We will also
define it for this, we will use the define data type here. So for this
we will write.- #define DHT11_PIN 7 In this we can write
anything else instead of DHT11_PIN. So in this way we have
made a variable declaration for the pin of DHT11 sensor on which
we will get the output data. Then after this we will complete the
voice setup part of this program, in this we will first have to tell
how many Colomns and how many rows are there in the LCD we
are using and we will use a command to tell it. lcd.begin( ) And
inside its parenthesis, we have to pass two comments, in the first
comment we write the number of Colomns of LCD. And in the
second comment, we write the row number of the LCD, now let's
see how to write it.- lcd.begin(16, 2); After this, we have to set the
baud rate in the program for the speed at which data is to be
communicated to our Arduino and system via USB. Use the serial
begin (Serial.begin) command to set the baud rate. What we want
to keep the baud rate in our program, we will know from our
Arduino software itself and according to the baud rate given in the
software, we keep the baud rate in our program. Now we will write
the baud rate in our program- Serial.begin(9600); And all the
statements that we have written in void setup will all be written
inside curly bracket {.....} Now we will write the program in void
loop, in this we will also program curly bracket {..... } Inside
In this, we will first read the value of the sensor, for this we write a
statement. Right now the output pin of the sensor is connected to
the digital pin 7 of the Arduino. So we will write in it- int chk =
DHT.read11(7); In its bracket also, we can write DHT11_PIN
instead of 7, it will not make any difference. In this we have read
DHT.read11 (); We have used the command, we know that
whatever statement is written in void loop will be repeated again
and again. Now we have written a statement to read the value of
the sensor. In this, we will first set the cursor in the LCD to start
printing from which Colomn and from which row we will use the
set cursor function. Under its parenthesis, we will pass two
numbers. The first number means that from which Colomn we
have to start printing, like we wrote 0, it means to start with
Colomn first, if writing 2, printing from the third Colomn would
start and then the second number in it Which means we have to
start printing from which row if we wrote 0 then printing from the
first row will start, if we wrote 1 then printing from the second row
will start, now write the statement complete- lcd.setCursor(0, 0);
We have just written (0,0) in its bracket, so now the printing will
start with the first Colomn and the first row. If we write (2,1) in
brackets, the printing starts with the third Colomn and the second
Row, after that we write the statement by which we have to print
the message on the LCD. For this, we will use the function
lcd.print () and in its parenthesis we write the message in double
court that if we want to print on LCD then we will write-
lcd.print("Temp: "); So this will print Temp: First Colomn and
First Row on LCD but now if we want to print the temperature
value, For this we will write another statement.- lcd.print
(DHT.temperature); Whatever temperature value will be detected
on the DHT sensor, it will be printed on the LCD next to Temp:
Now after this, if we want to symbolize the degree C ° in front of
the value, then for this we will write the statement.

Now after this we have to print Humidity, for this we have to set
the cursor on the LCD first but we have printed the temperature in
the first Row, now we will print it in the second Row, then we will
write to set the cursor in it. - lcd.setCursor(0,1); So this will start
printing with the first Colomn of the second row, after that we
write the statement by which we have to print the message on the
LCD. For this, we will use the function lcd.print () and in its
parenthesis we write the message in double court that if we want to
print on LCD then we will write- lcd.print("Humidity: "); So this
will print Humidity: From the first Colomn of the second row on
the LCD, but now if we want to print the value of Humidity, then
we will write another statement for this.-
lcd.print(DHT.humidity); Whatever Humidity value will be
detected on the DHT sensor will be printed on the LCD next to
Humidity: Now after this, if we want to indicate the percentage of
the value next to it, then for this we will write a statement-
lcd.print("%"); Now we keep 1000 microseconds i.e. 1 second for
our program to detect temperature and time, we will write a
statement for this - delay (1000); In this way Temperature and
Humidity will continue to show on the LCD. Now we write the
complete program.
Program-
#include <dht.h>
#include <LiquidCrystal.h>
int RS = 12, E = 11, D4 = 5, D5 = 4, D6 = 3, D7 = 2;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
dht DHT;
#define DHT11_PIN 7
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(DHT.humidity);
lcd.print("%");
delay(1000);
}
Note
With the help of all the projects you have learned to make
from this book, try to make more projects and all the
components or sensors can be controlled from Arduino,
then you should make a program for them.

You might also like