EP All Lab File
EP All Lab File
EP All Lab File
Part Descriptions:
Power USB
Arduino board can be powered by using the USB cable from your computer.
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).
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.
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)
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
Aim: To make the Buzzer / LED ON/OFF using pushbutton switch with arduino
programming
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;
//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 10G
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.
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:
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.
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
void setup()
{
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop()
{
int analogSensor = analogRead(smokeA0);
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.
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:
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
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.
Groundgnd
Power5 v
ControlPin3
Connection of part-II
Groundgnd
Power5 v
ControlPin3
Ground of potgnd
Power of pot5 v
Control of potA0 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
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
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
Screenshots:
Experiment-9
Que: Write an arduino program which changes the LED values from low
(dim) to high (bright) using PWM pin 9.
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
(16 x 2) LCD
LCD Program:
LiquidCrystal()
#include <LiquidCrystal.h>
void loop() {}
#include <LiquidCrystal.h>
void setup() {
lcd.begin(16, 2);
lcd.print("You are best");
}
void loop() {
lcd.blink();
delay(500);
lcd.noBlink();
delay(500);
}
void loop()
{
// print the character
lcd.write(thisChar);
delay(1000);
thisChar++;
#include <LiquidCrystal.h>
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)
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.
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);
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.
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=1024voltage = 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.
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.
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.
Schematic:
Code:
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;
Delay(100);
}
Experiment 14
(DC Motor)
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);
}