Basic Top 10 Arduino Based Projects - 10 Arduino Projects
Basic Top 10 Arduino Based Projects - 10 Arduino 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.
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-
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.
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);
}
}
Circuit Diagram-
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.
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);
}
}
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.
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.
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.
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);
}
}
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-
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.
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);
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-
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
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
}
}
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.
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.
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.
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);
}
}
Circuit Diagram-
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);
}
Circuit Diagram-
Now, we make a program of Arduino to operate this system.
And we will make the program as well as understand it.
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.