0% found this document useful (0 votes)
42 views48 pages

EP All Lab File

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 48

Experiment-1

Aim: Introduction to Arduino Uno Board.


Component: Arduino board.

Part Descriptions:

Power USB
Arduino board can be powered by using the USB cable from your computer.

Power (Barrel Jack)


Arduino boards can be powered directly from the AC mains power supply by
connecting it to the Barrel Jack (2).

Voltage Regulator
The function of the voltage regulator is to control the voltage given to the
Arduino board and stabilize the DC voltages used by the processor and other
elements.

Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does Arduino
calculate time? The answer is, by using the crystal oscillator. The number printed
on top of the Arduino crystal is 16.000H9H. It tells us that the frequency is
16,000,000 Hertz or 16 MHz.
Time = 1/frequency or frequency = 1/time
Frequency of a signal is number of cycles per second.
1K = Kilo = 103=1000
1M = Mega = 106=1000000
1G = Giga = 109=1000000000
1T = Tera = 1012 = 1000000000000
1m = mili = 10-3 =
1micro = micro =10-6=
1n = neno = 10-9 =

Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning.
You can reset the UNO board in two ways. First, by using the reset button (17) on
the board. Second, you can connect an external reset button to the Arduino pin
labelled RESET (5).

Pins (3.3, 5, GND, Vin)


 3.3V (6) − Supply 3.3 output volt
 5V (7) − Supply 5 output volt
 Most of the components used with Arduino board works fine with 3.3 volt
and 5 volt.
 GND (8)(Ground: 0v ) − There are several GND pins on the Arduino, any
of which can be used to ground your circuit.
 Vin (9) − This pin also can be used to power the Arduino board from an
external power source, like AC mains power supply.

Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These pins can
read the signal from an analog sensor like the humidity sensor or temperature
sensor and convert it into a digital value that can be read by the microprocessor.

Main microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as the
brain of your board. The main IC (integrated circuit) on the Arduino is slightly
different from board to board. The microcontrollers are usually of the ATMEL
Company. You must know what IC your board has before loading up a new
program from the Arduino IDE. This information is available on the top of the IC.
For more details about the IC construction and functions, you can refer to the data
sheet.

ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino
consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to
as an SPI (Serial Peripheral Interface), which could be considered as an
"expansion" of the output. Actually, you are slaving the output device to the master
of the SPI bus.

Power LED indicator


This LED should light up when you plug your Arduino into a power source to
indicate that your board is powered up correctly. If this light does not turn on, then
there is something wrong with the connection.

TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive). They
appear in two places on the Arduino UNO board. First, at the digital pins 0 and 1,
to indicate the pins responsible for serial communication. Second, the TX and RX
led (13). The TX led flashes with different speed while sending the serial data.
The speed of flashing depends on the baud rate used by the board. RX flashes
during the receiving process.

Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM
(Pulse Width Modulation) output. These pins can be configured to work as input
digital pins to read logic values (0 or 1) or as digital output pins to drive different
modules like LEDs, relays, etc. The pins labeled “~” can be used to generate
PWM.

AREF
AREF stands for Analog Reference. It is sometimes, used to set an external
reference voltage (between 0 and 5 Volts) as the upper limit for the analog input
pins.
Experiment-2 (Lab-2)

Aim: To blink the LED using arduino programming


Components: Arduino board, connecting wires, LED (Light emitting diode),
bread board.
Descriptions:
 LED works as a switch. (Diode as a switch)

 Connect two ends of LED with arduino pins.


 We are having total 14 digital pins and 6 analog pins.
 Use PIN 13 to connect positive end of LED.
 Use Ground pin (0 v) to connect other end of LED.
Steps:
 Use tinkercad.com site
 Click on sign in
 Sign in with google accout
 From dashboard click on circuit
 Click on new circuit
 Search arduino from component
 Place arduino
 Search led and breadboard
 Place led on breadboard
 Connect anode of led to pin 1
 Connect cathode of led to gnd pin
 Open code window
 Write the following code.
//declaration part is not required here

void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}

Code:
1. Declaration
2. Setup part:
 pinmode() is used to define whether pin used is input pin or output pin

3. Main loop part


 digitalWrite() function is use to write on digital pin.
 digitalWrite(13, HIGH) means send high value / signal (+5v) on pin no 13.
 digitalWrite(13, LOW) means send low value / signal (0v) on pin no 13.
 Delay() is used to generate delay in terms of time
 Delay(1000) means generate delay of 1000 ms.

 Run the simulation and check the output.


Experiment-3 (Lab-4)

Aim: To make the Buzzer / LED ON/OFF using pushbutton switch with arduino
programming

Components: Arduino board, connecting wires, LED (Light emitting diode),


Buzzer, Pushbutton switch, bread board, resistor (10K)

Descriptions:

(Buzzer)
 It is having two wires out of which one wire is connected with ground
and other is connected with positive end.
 Connected one end with Pin 13 and other end with GND.
 LED is connected with Pin 13 and other end with GND.

(Pushbutton switch)
 It is having four ends.
 Connect one end of pushbutton switch with ground using pull down
resistor having value of 10K.
 Connect this end with Pin 3 also.
 Connect other end of switch with +5v supply.

Steps:
 Use tinkercad.com site
 Click on sign in
 Sign in with google accout
 From dashboard click on circuit
 Click on new circuit
 Search arduino from component
 Place arduino
 Search led ,buzzer, pushbutton , resistor and breadboard
 Place led and pushbutton switch on breadboard
 Connect anode of led to pin 13 and cathode to GND.
 Connect cathode of led to gnd pin
 Connect positive end of buzzer with pin 13 and negative end with GND.
 Connect upper end of pushbutton switch to +5v and lower end with
resistor of size 10K.
 Connect other end of resistor with GND.
 Also connect lower end with pin 3.
 Open code window
 Write the following code.
Code:
Code for making Buzzer ON/OFF based on Pushbutton switch
//declaration
Int buzzer = 13;
Int switch = 3;

//setup part to define input and output


Void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(switch, INPUT);
}
//setup function will run for once only.

//Loop part
Void loop()
{
If( digitalread(switch) = = 1)
{
digitalwrite(buzzer, HIGH);
}
else
{
digitalwrite(buzzer, LOW);
}
}
//digitalread() function is used to read digital input from switch.
//digitalwrite() function I used to write digital output to the buzzer.

Screenshots:
Experiment-4
7-segment LED Display
Aim: to display 0 to 9 numbers one by one on 7 segment LED display
Components: Arduino board, 7 segment LED, wires, Resistor for common
ground.

Theory:

Detailed diagram

Pin 7 A
Pin 6 B
Pin 4 C
Pin 2 D
Pin 1 E
Pin 9 F
Pin 10G
Common cathode: then connect this pin (8) with ground
Common Anode: then connect this pin (8) with +5v

a= 11;
b=12;
c= 2;
d =3;
e = 6;
f = 9;
g= 10;

Lookup Table:

a b c d e f g
0 High(1) High High High High High Low(0)
1 Low High High Low Low Low Low
2 High High Low High High Low High
3 High High High High Low Low High
4 Low High High Low Low High High
5 High Low High High Low High High
6 High Low High High High High High
7 High High High Low Low Low Low
8 High High High High High High High
9 High High High High Low High High
b Low Low High High High High High
C High Low Low High High High Low
d Low High High High High Low High
F High Low Low Low High High High

Code:
int a= 11;
int b=12;
int c= 2;
int d =3;
int e = 6;
int f = 9;
int g = 10;
void setup()
{
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}
void two()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
delay(1000);
}
void three()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
delay(1000);
}
void four()
{
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
delay(1000);
}
void five()
{
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
delay(1000);
}
void six()
{
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
delay(1000);
}
void seven()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
delay(1000);
}
void eight()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
delay(1000);
}
void nine()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
delay(1000);
}
void zero()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
delay(1000);
}

void loop()
{
zero();
// one
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
delay(1000);
two();
three();
four();
five();
six();
seven();
eight();
nine();
}
void C()
{
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c, LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g, LOW);
delay(1000);
}
void E()
{
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
delay(1000);
}

void loop()
{
C();
E();
}
Experiment-5
Aim: To interface potentiometer with arduino and glow LED if potentiometer
value is above 300 points.

Components: Arduino board, connecting wires, LED (Light emitting diode),


bread board, potentiometer

Theory:
Potentiometer:

Clockwise:

 If I will rotate the button in direction of clock from north to east then it is
clockwise direction.

Anticlockwise:

 If I will rotate the button in opposite direction of clock from north to West
then it is anti-clockwise direction.
 Potentiometer is a device which is used to get variable resistor value.
 It is available with specific range.

Steps:
 Use tinkercad.com site
 Click on sign in
 Sign in with google account
 From dashboard click on circuit
 Click on new circuit
 Search arduino from component
 Place arduino
 Search led, breadboard, potentiometer.
 Place potentiometer on bread board.
 Place LED on bread board.
 Connect one end of LED to Digital pin 2 through resistor of 1kohm.
 Connect other end of LED to ground.
 Open code window
 Write the following code.

Code:

const int sensorMin = 0;


const int sensorMax = 800;

void setup()
{
pinMode(2,OUTPUT);
}

void loop()
{
// read the sensor:
int sensorReading = analogRead(A0);

if (sensorReading>=300)
{
digitalWrite(2, HIGH);
delay(500);
}
else
{
digitalWrite(2, LOW);
delay(500);
}

}
Screenshots:
Experiment-6

Aim: To interface Gas senor (Smoke sensor) with arduino and to glow the LED
if smoke value is higher.

Components: Arduino board, connecting wires, LED (Light emitting diode),


Buzzer, bread board, resistor, Gas sensor.

Descriptions:

(Smoke sensor)
Theory:
 Smoke sensors are useful in designing fire safety applications.
 Fire alarm is the main application of smoke sensor.
 It is used in industry to maintain the fire levels.
 It is also used in application like car safety system.
 It is used for safety purpose near petrol pump or any other gas station.
 It can be used in multipurpose applications like safety at home, hospital
or any other remote places.
 Any sensor must have at least 3 pins.[ VCC(+5v), Ground (0v), Data line]
 Gas sensor also has supply, ground and data pins.
 Gas sensor input is of analog type and it must be connected with analog
pin of arduino board.

Steps:
 Use tinkercad.com site
 Click on sign in
 Sign in with google accout
 From dashboard click on circuit
 Click on new circuit
 Search arduino from component
 Place arduino
 Search led , breadboard, resistor and gas sensor.
 Place gas sensor on bread board.
 Connect VCC of the gas sensor to +5v or vcc of arduino.
 Connect ground of gas sensor to Gnd of arduino.
 Connect data pin of gas sensor to A0 pin of arduino.
 Place LED on bread board.
 Connect one end of LED to Digital pin 2 through resistor of 1kohm.
 Connect other end of LED to ground.
 Open code window
 Write the following code.
Code:
Code for interfacing Gas sensor with Arduino

int redLed = 12;


int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
int sensorThres = 100;

void setup()
{
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}

void loop()
{
int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");


Serial.println(analogSensor);

if (analogSensor > sensorThres)


{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000,200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}

Screenshots:
Experiment-7

Aim: To design pitch follower using photo resistor and tone() function

Components:
 Arduino board,
 connecting wires,
 photo resistor,
 Buzzer or speaker,
 bread board,
 resistor (4.7k, 100 ohm).

Descriptions:
 This example shows how to use the tone() command to generate a pitch
that follows the values of an analog input.

 A photo resistor is a sensor whose resistance varies with light intensity.


 As the light intensity increases the resistance decreases.
 We have to convert this change in resistance into voltage or electrical
signal.
 Voltage divider is a popular circuit which is used to convert resistance
into voltage.

 R2 is photo resistor
 R1 is fixed value resistor
 Vcc is fixed supply of 5 v.

Circuit diagram:
 Connect one terminal of your speaker to digital pin 9 through a 100 ohm
resistor,
 Connect its other terminal to ground.
 Power your photo resistor with 5V,
 Connect other end of it to analog 0 with the addition of a 4.7K resistor
which is connected to ground.

𝑅2
𝑣 = (+5)
4.7𝐾 + 𝑅2

Steps:
 Use tinkercad.com site
 Click on sign in
 Sign in with google accout
 From dashboard click on circuit
 Click on new circuit
 Search arduino from component
 Place arduino.
 Search buzzer , breadboard, photo resistor and two resistor of 4.7k and
100 ohm.
 Connect one end of buzzer to ground and other end of buzzer to digital
pin 9 of arduino through 100 ohm resistor.
 Connect one end of photo resistor to +5v of arduino.
 Connect other end of photo resistor to analog pin A0.
 Also connect this end with 4.7 K resistor and connect other end of resistor
to ground.
 Open code window
 Write the following code.
Code:

Code for interfacing photo resistor sensor with Arduino

int sensorReading = 0;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
pinMode(9, OUTPUT);
}

void loop()
{
// read the sensor
sensorReading = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorReading);
// map the sensor reading to a range for the speaker
int thisPitch = map(sensorReading, 400, 1000, 120, 1500);
tone(9, thisPitch, 10);
//tone(9, 440 * pow(2.0, (constrain(int(map(sensorReading, 0, 1023,
36, 84)), 35, 127) - 57) / 12.0), 1000);
delay(10); // Delay a little bit to improve simulation performance
}

Screenshots:
Experiment-8

Aim: To interface Servomotor with arduino controller and implement following


functionality.
1. Rotate the servo motor from 0 to 180 degree in forward direction and 180 to
0 degree in reverse direction.
2. Use potentiometer (variable resistor) which controls the position of
servomotor.

Components:
 Arduino board,
 connecting wires,
 Servo motor,
 bread board,
 Potentiometer

Descriptions:
 There are four main parts of servomotor
o DC motor
o Gearing set
o Control circuit
o Position sensor
 It is used in almost all robotics applications like
o Robotics arm
o Positioning robot
o Helping robot
o Robotics boat
 It is used in electronics devices like DBD player or blue ray disc player.
 They are used in automobile industries.
 It is used in electronics toys.
 It is used in aerospace industry.
 It is used in mechanical industry with CNC machine.
 It is used in elevators also.
 Servomotor works with PWM technique.

PWM: Pulse Width Modulation


 Modulation??
 [Low frequency signal (paper)+ High frequency signal(Stone)]
modulated signal (the process is modulation)
 [Modulated signal - High frequency signal(Stone)] low frequency signal
(paper) (the process is demodulation)
 In PWM width of pulse changes according to source signal.

 Servomotor is having three wires.


o Power (Vcc, +5v)
o Ground
o Control
 Ground wire is connected with ground (gnd) of arduino.
 Power wire is connected with +5 v of arduino.
 Control wire is connected with Digital Pin-3 of arduino.
Connection of part-I

Groundgnd
Power5 v
ControlPin3

Connection of part-II

Groundgnd
Power5 v
ControlPin3
Ground of potgnd
Power of pot5 v
Control of potA0 analog pin
Steps:
 Use tinkercad.com site
 Click on sign in
 Sign in with google accout
 From dashboard click on circuit
 Click on new circuit
 Search arduino from component
 Place arduino.
 Search servo motor , breadboard, potentiometer and add to sketch.
 Make the connection as per sketch shown in the figure.
 Write the following code.

Code:
 Install library for servomotor
 Include header file for servo.
 #Include <Servo.h>
Part-I

Code for interfacing servomotor with Arduino


#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(3); // attaches the servo on pin 3 to the servo object
}
void loop()
{
for (pos = 0; pos <= 180; pos ++) { // 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 --) { // 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
}
}
Part-II

Code (sketch) for controlling the position of servomotor using


potentiometer.
#include <Servo.h>

Servo myservo; // create servo object to control a servo

int val; // variable to read the value from the analog pin

void setup() {
myservo.attach(3); // attaches the servo on pin 3 to the servo
}

void loop()
{
val = analogRead(A0); // reads the value of the potentiometer
//(value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the
//(value between 0 and 180)
myservo.write(val); // sets the servo position

delay(15); // waits for the servo to get there


}

Screenshots:
Experiment-9

Que: Write an arduino program which changes the LED values from low
(dim) to high (bright) using PWM pin 9.

Arduino program for PWM

Int light=0;
Int step=5;

Void setup()
{
pinMode(9, OUTPUT); //9 is PWM pin so use it.
}
Void loop()
{
analogwrite(9, light);
light = light + step;
if (light == 0 ||light == 255)
{
step = -step
}
delay(50);
}
Experiment-10

Aim: Interface LCD with arduino and print “You are the best” message

LCD Interfacing with Arduino:

(16 x 2) LCD

LCD Program:

LiquidCrystal()
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup()
{
lcd.begin(16,2); // it is used to on or initialize the LCD
lcd.print("You are best!");
}

void loop() {}

Output Message on LCD:

Program to Blink the cursor on LCD

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;


LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
lcd.begin(16, 2);
lcd.print("You are best");
}
void loop() {
lcd.blink();
delay(500);
lcd.noBlink();
delay(500);
}

LCD Program to print the alphabet starting with ‘a’.


1. If the alphabet is ‘m’ then change the writing direction from right to left.
2. If the alphabet is ‘s’ the change the writing direction from left to right.
3. If alphabet is ‘z’ then start again with ‘a’ from initial position
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int thisChar = 'a';


void setup()
{
lcd.begin(16, 2);
lcd.cursor();
}

void loop()
{
// print the character
lcd.write(thisChar);
delay(1000);
thisChar++;

// reverse directions at 'm':


if (thisChar == 'm') {
// go right for the next letter
lcd.rightToLeft();
}
// reverse again at 's':
if (thisChar == 's') {
// go left for the next letter
lcd.leftToRight();
}
// reset at 'z':
if (thisChar > 'z') {
// go to (0,0):
lcd.home();
// start again at 0
thisChar = 'a';
}
}
LCD Program for Autoscroling the text

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;


LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{
lcd.begin(16, 2);
}

void loop()
{
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
Int i;
for (i = 0; i < 10; i++)
{
lcd.print(i);
delay(500);
}
// set the cursor to (16,1):
lcd.setCursor(16, 1);
// set the display to automatically scroll:
lcd.autoscroll();
// print from 0 to 9:
for (i = 0; i < 10; i++) {
lcd.print(i);
delay(500);
}
// turn off automatic scrolling
lcd.noAutoscroll();
// clear screen for the next loop:
lcd.clear();
}
Experiment 11
(PIR Sensor)

Aim: To interface PIR sensor with arduino controller.


1. Ring the buzzer when motion is detected.
2. Rotate the servomotor by 90 degree when motion is detected.
3. Display “No motion” when object is not found and display “Motion is
detected” on LCD when movement is there.

Components:
 Arduino board,
 connecting wires,
 Servo motor,
 bread board,
 LCD display
 Buzzer
 PIR sensor

Descriptions:
 PIR stands for Passive Infrared Sensor.
 It is called passive sensor because it does not emit the IR rays. It only
receives the IR rays.
 PIR sensor allows to detect or sense the motion.
 It is small, Inexpensive and low power device.
 It is non wearable device for that reason they are commonly found in
appliances and gadgets used in homes or businesses.

 It is having 3 pin structure where ,


o Pin 1 is Vcc (+5v)
o Pin 2 is Output
o Pin 3 is ground
 All pins must be connected with arduino pins.

 PIR sensor can detect animal/human movement in a requirement range.


 For Indoor passive infrared Detection distances range from 25 cm to 20 m
 For Outdoor passive infrared, the detection distance ranges from 10
meters to 150 meters.
 It detects infrared radiation from the environment. Once there is infrared
radiation from the human body particle with temperature, focusing on
the optical system causes the device to generate a sudden electrical
signal.

Connection of part-I
Link:
https://www.tinkercad.com/things/bjhnjH7wga1-copy-of-pir-
sensor/editel?sharecode=VaOlr6QL7HH0-
DG8_egopkf3yAXW2AAWh3Gjfewty3M
Steps:
 Use tinkercad.com site
 Click on sign in
 Sign in with Google account
 From dashboard click on circuit
 Click on new circuit
 Search arduino from component
 Place arduino.
 Search servo motor, breadboard, LCD and buzzer and add to sketch.
 Make the connection as per sketch shown in the figure.
 Write the following code.
Code:
Code for interfacing servomotor with Arduino
int sensor = A0;
int led = 2;
int sensorvalue=0;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
}
Void loop()
{
sensorvalue = analogRead(sensor);
Serial.Println(sensorvalue);

If (sensorvalue > 800)


{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
Experiment 12
(Temperature Sensor)

AIM: Interface LM35 sensor with arduino board. Write a sketch for
1. To read the temperature
2. To Display the temperature in Celsius
3. To Display the temperature in Fahrenheit.

1. LM35 is popular temperature sensor.

Steps (Algorithm)
1. Read the input value from temp sensor.
2. Use A0 pin to read the value.
3. Store the answer in “tmp” variable.
4. The value read from analog sensor is 10 bit number=210=
5. Convert this 10 bit number in the range of 5 v
6. Voltage = (temp)* 5v / 1024 means for temp=0 voltage = 0 and for
temp=1024voltage = 5 v = 5000 mili volt
7. Again convert this voltage into millivolts by multiplying the voltage with
1000. Milivolt = Voltage*1000.
8. To find the temperature use following equation
Temp (in celcius) = (millivolt – 500)/10
9. To convert temp into Fernheat (F) use following equation.
F = °C × (9/5) + 32
10.Display temp in C.
11.Display temp in F.

Program or sketch for temperature sensor


char degree = 176; //ASCI value of Degree
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600);
}
void loop()
{
int tmp = analogRead(A0);
float voltage = (tmp * 5.0)/1024;
float milliVolt = voltage * 1000
float tmpCel = (milliVolt-500)/10
float tmpFer = (((tmpCel*9)/5)+32
Serial.print("10bit number(0-1023): ");
Serial.println(tmp);
Serial.print("voltage: ");
Serial.print(voltage);
Serial.println("V");
Experiment 13
Ultrasonic Sensor

Aim: To interface Ultrasonic sensor with arduino and make three LEDs on /off
based on the distance of an object.
1. distance >350 cm then LED1=OFF, LED2=OFF, LED3=OFF
2. distance >250 cm and distance <350 cm then LED1=ON, LED2=OFF, LED3=OFF
3. distance >150 cm and distance <250 cm then LED1=ON, LED2=ON, LED3=OFF
4. distance >0 cm and distance <150 cm then LED1=ON, LED2=ON, LED3=ON
Components:
Arduino board,
Ultrasonic sensor,
Bread board,
Connecting wires,
3 LEDs,
3 resistors

Theory:
Ultrasonic sensor interfacing with arduino:

Ultra: It refer to sound which cannot be listen by human but animals like bat
and dog can hear it.

Sonic: It refers to sound

 Generally human use the eye for finding the distance of an object which
is not an accurate method.
 Birds like bat can emit the sound signal and receives it back and find the
distance.
 Velocity = distance / time
 Time = distance / velocity
 Velocity in space or air = 3 x 108 m/s
 If we estimate the time between sending and receiving the signal then we
can able to find distance.
 Ultrasonic sensor can be used in many application where we need to find
the distance of an object, detecting motion, counting objects etc.
 Ultrasonic sensor must have two parts
o A transmitter which transmits the signal which human cannot hear.
o A Receiver which receives the reflected signal bounced back from
nearby objects.
 If the object is very close to the sensor, the signal comes back quickly.
 If the object is far away from the sensor, the signal takes longer to come
back
 If objects are too far away from the sensor, the signal takes so long to
come back (or is very weak when it comes back) that the receiver cannot
detect it.

 It is used to find the objects.


 It also find the distance of the object from arduino.
 It is based on principle of transmitting and receiving ultrasonic sound
waves.
 It send the waves in the space and waits for its reflection.
 It calculates the time difference between transmitted waves and received
(reflected) waves.
 Calculate the distance based on tie difference.
 Distance (cm) = 0.0172* Time duration (micro second)
 Ultrasonic senor has 4 pins
o Vcc+5v
o Ground
o Trigg pin
o Echo pin
Steps:
 Use tinkercad.com site
 Click on sign in
 Sign in with google accout
 From dashboard click on circuit
 Click on new circuit
 Search arduino from component
 Place arduino.
 Search Ultrasonic sensor , breadboard, LEDs, resistors, bread board and
add to sketch.
 Make the connection as per sketch shown in the figure.
 Write the following code.

Schematic:

Code:

Ultrasonic sensor interfacing progra


//function to find the duration
Long ultrasonicduration(int triggpin, int echopin)
{
pinMode(echopin, INPUT);
pinMode(triggpin, OUTPUT);
//Generating the pulse on triggpin
digitalWrite(triggpin, LOW);
delayMicroseconds(10);
digitalWrite(triggpin, HIGH);
delayMicroseconds(10);
digitalWrite(triggpin, LOW);
delayMicroseconds(10);
// Reads the echo pin, and returns the sound wave travel time
return pulsein(echopin, HIGH);
}
Void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}

Void loop()
{
Int cm=0.0172*ultrasonicduration(7,6);
Int inches=cm/2.54;
Serial.print(cm);
Serial.println(“ cm”);
Serial.print(inches);
Serial.println(“ inches”);
Int threshold=350;

If (cm > threshold)


{
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}

If(cm<=threshold && cm> threshold - 100)


{
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}

If(cm<=threshold-100 && cm> threshold - 200)


{
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
}
If(cm<=threshold-200 && cm> 0)
{
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
}

Delay(100);
}
Experiment 14
(DC Motor)

Aim: DC motor interfacing with arduino using L293D motor driver.

 L293D is 16 pin IC.


 It is used to connect two DC Motors with arduino.
 Left side pins 1 to 8 are used for motor 1.
 Right side pins 9 to 16 are used for motor 2.

Pin Pin Name Pin Description


Number
PIN 1 Enable 1,2  Pin 1 is known as the enable pin.
 If HIGH voltage I given to Pin 1 then it enables
motor 1.
 When enable pin is high then all input and
output pins (2,3,6,7) are ready to work.
PIN 2 Input 1  It is a pin which reads the input from arduino
or any other controller.
PIN 3 Output 1  It is a Pin which writes the data or output to
DC motor input
 It must be connected with DC Motor.
PIN 4 Ground  The ground pin will be attached to the ground
of the circuit or arduino.
PIN 5 Ground  The ground pin will be attached to the ground
of the circuit or arduino.
PIN 6 Output 2  It is a Pin which writes the data or output to
DC motor input
 It must be connected with DC Motor.
PIN 7 Input 2  It is a pin which reads the input from arduino
or any other controller.
PIN 8 Vcc  It must be connected with +5v to +16 v
PIN 9 Enable 3,4  Pin 9 is known as the enable pin.
 If HIGH voltage I given to Pin 9 then it enables
motor 2.
 When enable pin is high then all input and
output pins (10,11,14,15) are ready to work.
PIN 10 Input 3  It is a pin which reads the input from arduino
or any other controller.
PIN 11 Output 3  It is a Pin which writes the data or output to
DC motor input
 It must be connected with DC Motor.
PIN 12 Ground  The ground pin will be attached to the ground
of the circuit or arduino.
PIN 13 Ground  The ground pin will be attached to the ground
of the circuit or arduino.
PIN 14 Output 4  It is a Pin which writes the data or output to
DC motor input
 It must be connected with DC Motor.
PIN 15 Input 4  It is a pin which reads the input from arduino
or any other controller.
PIN 16 Vss  It must be connected with +5v to +16 v

Program to rotate the two motors anticlockwise and clockwise one by one.

void setup()
{
pinMode(4, OUTPUT);input from arduino pin 4 to motor 1 driver as output
pinMode(5, OUTPUT); input from arduino pin 5 to motor 1 driver as output
pinMode(6, OUTPUT); input from arduino pin 6 to motor 2 driver as output
pinMode(7, OUTPUT); input from arduino pin 7 to motor 2 driver as output
}

void loop()
{ //clockwise M1
digitalWrite(4, HIGH);digitalWrite(5, LOW);
delay(3000);
//anticlockwise M1
digitalWrite(4, LOW);digitalWrite(5, HIGH);
delay(3000);
//stop M1 for 3 second
digitalWrite(4, LOW);digitalWrite(5, LOW);
delay(3000);

//clockwise M2
digitalWrite(7, HIGH);digitalWrite(6, LOW);
delay(3000);
//anticlockwise M1
digitalWrite(7, LOW);digitalWrite(6, HIGH);
delay(3000);
//stop M1 for 2 second
digitalWrite(7, LOW);digitalWrite(6, LOW);
delay(3000);
}

You might also like