0% found this document useful (0 votes)
17 views40 pages

Manual

The document provides a series of exercises for interfacing various components with an Arduino, including LEDs, photoresistors, temperature sensors, servo motors, buzzers, relays, and ultrasonic sensors. Each exercise includes an introduction, hardware requirements, connection diagrams, working steps, and code sketches. The goal is to demonstrate how to control and monitor these components using Arduino programming.

Uploaded by

thilagavathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views40 pages

Manual

The document provides a series of exercises for interfacing various components with an Arduino, including LEDs, photoresistors, temperature sensors, servo motors, buzzers, relays, and ultrasonic sensors. Each exercise includes an introduction, hardware requirements, connection diagrams, working steps, and code sketches. The goal is to demonstrate how to control and monitor these components using Arduino programming.

Uploaded by

thilagavathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Ex 1: Controlling the Light Emitting Diode (LED) with a push button using

arduino.

Introduction: Push-button is a very simple mechanism which is used to control


electronic signal either by blocking it or allowing it to pass.

This happens when mechanical pressure is applied to connect two points of the switch
together.

Push buttons or switches connect two points in a circuit when pressed. When the push-
button is released, there is no connection between the two legs of the push-button.

Here it turns on the built-in LED on pin 11 when the button is pressed.

The LED stays ON as long as the button is being pressed.

LED Specifications

Pin definition
Push Button

Specifications:

Hardware Required:

ComponentName Quantity

ArduinoUNO 1

LED 1

PushButton 1

220Ω resistor 1

10KΩ resistor 1

USB Cable 1
Connection diagram

Steps of working

1. Insert the push button into your breadboard and connect it to the digital pin 7(D7)
which act as INPUT.
2. 2. Insert the LED into the breadboard. Attach the positive leg (the longer leg) to
digital pin 11 of the Arduino Uno, and the negative leg via the 220-ohm resistor to
GND. The pin D11 is taken as OUTPUT.
3. 3. The 10kΩ resistor used as PULL-UP resistor and 220 Ω resistors is used to limit
the current through the LED.
4. 4. Upload the code as given below. 5. Press the push-button to control the ON
state of LED.

The Sketch

➢ This sketch works by setting pin D7 as for the push button as INPUT and pin 11 as
an OUTPUT to power the LED.

➢ The initial state of the button is set to OFF.

➢ After that the run a loop that continually reads the state from the pushbutton and
sends that value as voltage to the LED. The LED will be ON accordingly.

Program

*Pressing Button LED*****/

const int buttonPin = 7; // choose the pin for the pushbutton

const int ledPin = 11; // choose the pin for a LED

int buttonState = 0; // variable for reading the pushbutton pin status

void setup()

pinMode(ledPin, OUTPUT); // declare LED as output pinMode

(buttonPin, INPUT); // declare pushbutton as input

void loop()
{ buttonState = digitalRead(button Pin); // read input value

if (buttonState == HIGH)

{ // check if the input is HIGH

(button pressed)

digitalWrite(ledPin, HIGH); // turn LED ON

Else

digitalWrite(ledPin, LOW); // turn LED OFF}}

Observation Table:

Precautions:

1. The pushbutton is square so it is important to set it appropriately on breadboard. 2.


While making the connections make sure to use a pull-down resistor because directly
connecting two points of a switch to the circuit will leave the input pin in floating
condition and circuit may not work according to the program. 3. It is very important
to set pinMode() as OUTPUT first before using digitalWrite() function on that pin. 4.
If you do not set the pinMode() to OUTPUT, and connect an LED to a pin, when
calling digitalWrite(HIGH), the LED may appear dim.
Ex.2 Detection of the light using photoresistor

Introduction: A photo resistor or photocell is a light-controlled variable


resistor made of a high resistance semiconductor. The resistance of a photo
resistordecreaseswithincreasingincidentlightintensity.Aphotoresistorcan be
applied in light-sensitive detector circuits, and light- and dark-activated
switching circuits. It's also called light-dependent resistor (LDR).

Hardware Required:

Component Name Quantity

ArduinoUNO 1

LED 1

Photo Resistor 1

10KΩ Resistor 1

220Ω Resistor 1
USB Cable 1

Breadboard 1

Jumper wires several

Connectiondiagram:

Steps of working

1. Insert the photo resistor into your breadboard and connect its pin to
the analog pin A0 and the remaining pin to supply on the breadboard.
2. Insert the LED into the breadboard. Attach the positive leg (the longer
leg) to pin 9 of the Arduino via the 220-ohm resistor, and the negative
leg to GND.
3. Insertthe10K-ohm resistor

4. Upload the code

5. Turn the photo resistorto ON the LED

6. Observe the changes in the state of theLED.

The Sketch
This sketch works by setting pin A0 as for the photo sensor and pin 9 as an
OUTPUT to power the LED. After that the run a loop that continually reads
the value from the photo resistor and sends that value as voltage to the LED.
The LED will vary accordingly.

program
/****************PhotoResistortoLED*****/

constintsensorPin=A0;//choose the pin for the Photo resistor


const int ledPin = 9; // choose the pin for a LED
int lightCal; //variable for reading theinitial state of photo sensor
int lightVal; // variable for reading the current state photo sensor
void setup()
{

pinMode(ledPin,OUTPUT);//declare LED as output


lightCal = analogRead(sensorPin);
}

voidloop(){

lightVal=analogRead(sensorPin);//readinputvalue

if(lightVal<lightCal-50){//check if the input is less than threshold


digitalWrite(9,HIGH); // turn LED ON

}
else{digitalWrite(9,LOW);//turn LEDOFF

}
ObservationTable:

Sr.no. Light detected LEDstate

2
Ex .3.Interfacing of temperature sensorLM35 with Arduino

Introduction:TheLM35seriesareprecisionintegrated-circuittemperature
devices with an output voltage linearly proportional to the Centigrade
temperature.LM35isthreeterminallineartemperaturesensorsfromNational
semiconductors.Itcanmeasuretemperaturefrom-55degreeCelsiusto+150
degree Celsius. The voltage output of the LM35 increases 10mV per degree
Celsius risein temperature. LM35 can beoperated from a5V supply and the
standbycurrentislessthan60uA.ThepinoutofLM35isshowninthefigure below.
HardwareRequired:

ComponentName Quantity

ArduinoUNO 1

Lm35 1

USB Cable 1

Breadboard 1

Jumperwires Several

ConnectionDiagram:
Stepsofworking

1. Insertthetemperaturesensorintoyourbreadboardandconnectitspin1 to
the supply.
2. Connect its center pin to the analog pin A0 and the remaining pin3 to
GND on the breadboard.
3. Uploadthecodeasgivenbelow.

4. Varythetemperatureandreadthevoltagechanges.

5. OpentheArduinoIDE’sserialmonitortoseetheresults.

TheSketch

This sketch works by setting pin A0 as for the temperature sensor. After that
the run a loop that continually reads the value from the sensor and sends that
value as voltage. The voltage value is between 0–5 volts, when temperature
will vary accordingly.
/*************File name: LM 35 Temperature Sensor.ino Description: Lit
LM35 Temperature Sensor, let Precision Temperature sensor***/
intLM35Pin=A0;
void setup()
{

Serial.begin(9600);}
void loop ()
{intval;
intdata;
val=analogRead(LM35Pin);
data= (val*5)/10;
Serial.print(“Temp:”);
Serial.print(data);
Serial.println(“C”);
delay(500);
}

ObservationTable:

Sr. Voltage Temperature

no.

5
Ex.4 Interfacing Servo Motor with the Arduino
Introduction:
A Servo Motor is a small device that has an output shaft. This shaft can be
positioned to specific angular positions by sending the servo a coded signal.
As long as the coded signal exists on the input line, the servo will maintain
the angular position of the shaft. If the coded signal changes, the angular
position of the shaft changes. Servo motors have three terminals – power,
ground,andsignal.Thepowerwireistypicallyred,andshouldbe connected
tothe5Vpin ontheArduino.Thegroundwireistypicallyblack orbrown as shown
in figure:

Specifications:

GND commongroundforboththemotorandlogic.

5V positivevoltagethatpowerstheservo.

Control Inputforthecontrolsystem.
The control wire is used to communicate the angle. The angle is determined
by the duration of a pulse that is applied to the control wire. This is called
Pulse Coded Modulation. The servo expects to see a pulse every 20
milliseconds(.02seconds).Thelengthofthepulsewilldeterminehowfarthe motor
turns. A 1.5 millisecond pulse, for example, will make the motor turn to the
90-degree position (often called as the neutral position). If the pulse is
shorter than 1.5 milliseconds, then the motor will turn the shaft closer to 0
degrees. If the pulse is longer than 1.5 milliseconds, the shaft turns closer to
180 degrees.

HardwareRequired:

ComponentName Quantity

ArduinoUNO 1

Servomotor 1

USB Cable 1
Breadboard 1

Jumperwires several

ConnectionDiagram:

Stepsofworking

1. The servo motorhas a female connector with threepins.The darkestor


even black one is usually the ground. Connect this to the
ArduinoGND.
2. Connect the power cable that in all standards should be red to 5V on
the Arduino.
3. Connect the remaining line on the servo connector to a digital pin on
the Arduino.
4. Uploadthe code
5. Observethepositionoftheshaft.

The Sketch
This sketch works by setting pin D9 as for the control of servo motor. After
that therunaloop that continually increment the value of the index of rotation
angle and sends that value as voltage to the D9.Thevoltagevalueisbetween
0–5 volts, and the rotation angle of the servo motor will vary accordingly.
/********ServoMotorRotation******/
#include<Servo.h>
Servomyservo;
int pos=0;
voidsetup()
{

//put your setup code here,to run once:


myservo.attach(7);}
voidloop(){
//put your main code here,to run repeatedly:
for(pos=0;pos<=180;pos++)
{
myservo.write(pos);
delay (15);
}

delay(1000);
for(pos=180;pos>=0;pos--)
{

myservo.write(pos);
delay(15);
}

delay(1000);
}

ObservationTable:

Sr.no. Voltage PositionofShaft

5
Ex.5 Interfacing of the Active Buzzer with
Arduino.
Introduction:
Apiezobuzzerisatypeofelectronicdevicethat’susedtoproducebeepsand tones.
The working principle of the device is piezoelectric effect. The main
component of this device is a piezo crystal, which is a special material that
changes shape when a voltage applied to it. The active buzzer will only
generate sound when it will be electrified. It generates sound at only one
frequency. This buzzer operates at an audible frequency of about 2 KHz.

Specifications:

Specification Range

VoltageRange 3.3-5V

Frequency 2KHz
PinName Description

Positive Identifiedby(+)symbolorlongerterminal lead.


Can be powered by 6V DC

Negative Identifiedbyshortterminallead.Typically
connected to the ground of the circuit

HardwareRequired:

ComponentName Quantity

ArduinoUNO 1

Buzzer / piezo 1
speaker

220-ohmresistors 1

USBCable 1

Breadboard 1

Jumperwires several
ConnectionDiagram:

Steps of working:

Connect the Supplywire (RED) of the buzzer to the DigitalPin9 of the


Arduino through a 100-ohm resistor.
Connect the Ground wire (BLACK) of the buzzer to any Ground Pin on the
Arduino.
Uploadthe code
Observe the changes in the pitch and volume of the buzzer.
Sketch:
This sketch works by setting pin D9 as for the control the buzzer. After that
the run a loop that continually sends that value as voltage high or low to the
D9 using the function digitalWrite( ). The voltage value and the tone
generated from the buzzer will vary accordingly.
/****Musicalbuzzer****/
int buzzer = 9; //thepinoftheactivebuzzer
void setup()
{

pinMode(buzzer,OUTPUT); //initializethebuzzerpinasanoutput
}

void loop()
{ unsignedchari;
while(1){
//outputafrequency
for(i=0;i<80;i++)
{
digitalWrite(buzzer,HIGH);
delay(1); //waitfor1ms
digitalWrite(buzzer,LOW);
delay(1); //waitfor1ms
}

//output another frequency for(i=0;i<100;i+


+){ digitalWrite(buzzer,HIGH);
delay(2); //waitfor2ms
digitalWrite(buzzer,LOW);
delay(2); //waitfor2ms
}

Observation:

Sr.no. Changethevalue Frequencyoftone

3
Interfacing of the Relay with Arduino.
Introduction:
Relayisanelectromagneticswitch,whichiscontrolledbysmallcurrent,and
usedtoswitchONandOFFrelativelymuchlargercurrent.Meansbyapplying
small current we can switch ON the relay which allows much larger current
to flow.

HardwareRequired:

ComponentName Quantity

ArduinoUNO 1

5VRelay 1
USB Cable 1

Breadboard 1

Jumperwires several

ConnectionDiagram:

Stepsofworking:

1. Therelaymoduleconnectedwiththreepins.Wewillconnecttherelay
modulewithArduinointhenormallyopenstate.Theblackoneofrelay is
usually the ground. Connect this to the Arduino GND.
2. Connecttheredwireofrelaymoduleto5VoftheArduino.
3. Connectthesignalpinofrelaymoduletoadigitalpin6oftheArduino.
4. Uploadthe code
5. Observe the clicking sound of the relay that states the ON and OFF
constantly.

Sketch:

This sketch works by setting 5V supply pin of Arduino as for the control of
relay module. After that the run a loop that continually sends that value as
voltage to the D6 with the delay given.

//ArduinoRelayControlCode Int
relayPin=6;
#defineinterval2000
void setup() {
pinMode(relayPin,OUTPUT);
}

voidloop()
{

digitalWrite(relayPin,HIGH);
delay(interval);
digitalWrite(relayPin, LOW);
delay(interval);
}

Observations:

Sr.No. Delay RelayStatus

2
Building Intrusion Detection System with
Arduino and Ultrasonic Sensor

Introduction:
An intrusion detection system (IDS) is a device or software application that
monitors a network or systems for malicious activity
Ultrasonic Sensors:The HC-SR04 ultrasonic sensor uses SONAR to
determine the distance of an object just like the bats do. It offers excellent
non-contactrangedetectionwithhighaccuracyandstablereadingsinaneasy- to-
usepackagefrom2cmto400cmor1”to13feet.Itcomescompletewith ultrasonic
transmitter and receiver module. The ultrasonic sensor uses the
reflectionofsoundinobtainingthetimebetweenthewavesentandthewave
received. It usually sent a wave at the transmission terminal and receives the
reflected waves. The time taken is used together with the normal speed of
sound in air (340ms-1) to determine the distance between the sensor and the
obstacle. The Ultrasonic sensor is used here for the intruder detection. The
sound via a buzzer occurs when an object comes near to the sensor. The
distance to which the sensor will respond can be easily adjusted in the
program.
HardwareRequired:

ComponentName Quantity

ArduinoUNO 1

RedLED 1

Green LED 1

HC-SR04 Ultrasonic 1
Sensor

Buzzer 1

USB Cable 1

Breadboard 1

Jumperwires several
ConnectionDiagram:

Stepsofworking

1. Insertthe UltrasonicsensorintoyourbreadboardandconnectitsEcho pin


to the digital pin 2 and the Trigger pin to digital pin 3 of the Arduino.
2. InserttheREDandGreenLEDintothebreadboard.Attachthepositive
leg(thelongerleg)ofredLEDtosignalpinof theBuzzerviathe220-
ohmresistor,andthenegativelegtoGND.ThegreenLEDisconnected to
digital pin 8 of the Arduino.
3. Uploadthecode.
4. ObservetheLEDsandtakesomeobjectinfrontofultrasonicsensor.
5. ObservethechangesintheLEDandbuzzersound.
TheSketch
Thissketchworksbysettingpin2asfortheultrasonicsensorsandpin 8,pin9 & pin
10 as an OUTPUT to power the LEDs and buzzer. After that the run a loop
that continually reads the value from the echo pin and sends that value as
voltage to the LEDs. The color of the LED which glows will vary
accordingly to the detection of object in the given range.
/**********IntrusionDetection******/
#define echo 2
#definetrig3
#define outA 8 // Red LED
#define outB 9 //GreenLED
#define outC 10 // Buzzer
float duration; // time taken by the pulse to return back
float distance; //onewaydistancetravelledbythepulse
constintintruderDistance=10;//theminimumdistanceuptowhichthe sensor is able
to sense any object
void setup()
{ pinMode(trig,OUTPUT
); pinMode(echo,
INPUT);
pinMode(outA,OUTPUT);
digitalWrite(outA, LOW);
pinMode(outB, OUTPUT);
digitalWrite(outB, LOW);
pinMode(outC, OUTPUT);
digitalWrite(outC,LOW);
Serial.begin(9600);
}

void loop() {
time_Measurement();
distance=(float)duration*(0.0343)/2;
//calculatetheonewaydistancetravelledbythepulse
Serial.println(distance);
alarm_condition();
}

voidtime_Measurement()
{ //functiontomeasurethetimetakenbythepulsetoreturnback
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration=pulseIn(echo,HIGH);
}

voidalarm_condition()
{ //function to execute the output commands based on the sensor
input
if(distance<=intruderDistance)
{

digitalWrite(outA,HIGH);
digitalWrite(outB,LOW);
analogWrite(outC,200);}
else
{
digitalWrite(outA,LOW);
digitalWrite(outB,HIGH);
analogWrite (outC,0);
}

ObservationTable:

Sr no. ObjectDetected LED Buzzer

2
DirectionalControloftheDCmotorusing
Arduino
Introduction:
A DC motor (Direct Current motor) is the most common type of motor. DC
motors normally have just two leads, one positive and one negative. If you
connect these two leads directly to a battery, the motor will rotate. If you
switch the leads, the motor will rotate in the opposite direction.

Specification

Pin Description

GND commongroundforboththemotorandlogic

5V positivevoltagethatpowerstheservo

Control Inputforthecontrolsystem.
The control wire is used to communicate the angle. The angle is determined
by the duration of a pulse that is applied to the control wire. This is called
Pulse Coded Modulation. The servo expects to see a pulse every 20
milliseconds(.02seconds).Thelengthofthepulsewilldeterminehowfarthe motor
turns. A 1.5 millisecond pulse, for example, will make the motor turn to the
90-degree position (often called as the neutral position). If the pulse is
shorter than 1.5 milliseconds, then the motor will turn the shaft closer to 0
degrees. If the pulse is longer than 1.5 milliseconds, the shaft turns closer to
180 degrees.

HardwareRequired:

ComponentName Quantity

ArduinoUNO 1

DC motor 1

RGBLED 1

Pushbutton 1

10k-ohmresistor 1

USB Cable 1

Breadboard 1

Jumperwires several
Connectiondiagram:

Stepsofworking

1. Theservomotorhasafemaleconnectorwiththreepins.Thedarkestor
evenblackoneisusuallytheground.ConnectthistotheArduinoGND.
2. Connect the power cable that in all standards should be red to 5V on
the Arduino.
3. Connect the remaining line on the servo connector to a digital pin on
the Arduino.
4. Uploadthe code
5. Observethepositionoftheshaft.

TheSketch
This sketch works by setting pin A2 as for the potentiometer and pin 9 as an
OUTPUT to power the LED. After that the run a loop that continually reads
the value from the potentiometer and sends that value as voltage to the LED.
The voltage value is between 0–5 volts, and the brightness of the LED will
vary accordingly.

/********DCMotorDirectioncontrolbyRGB******/ const
int inputPin=1;
constintblue=3;
const int red=4;
constintmotorPin1=5,motorPin2=6; int
dir=LOW;
intprevState=0,currentState=0;
void setup()
{

//putyoursetupcodehere,torunonce:
pinMode(inputPin,INPUT);
pinMode(motorPin1,OUTPUT);
pinMode(motorPin2,OUTPUT);
pinMode(blue,OUTPUT);
pinMode(red,OUTPUT);
}
voidloop()
{

//putyourmaincodehere,torunrepeatedly:
currentState=digitalRead(inputPin); if(currentState!
=prevState)
{

if(currentState==HIGH)
{dir=!dir;
}

prevState=currentState;
if(dir==HIGH)
{
digitalWrite(motorPin1,HIGH);
digitalWrite(motorPin2,HIGH);
digitalWrite(blue,LOW);
digitalWrite(red,HIGH);
}

ObservationTable:

Sr no. Voltage PositionofShaft

You might also like