saravana
saravana
R ENGINEERING COLLEGE
(An Autonomous Institution, Affiliated to Anna University, Chennai)
Approved by AICTE, New Delhi & Accredited by National Board of Accreditation (NBA)
Accredited by NAAC with “A+” Grade, Recognized under12 (B) of the UGC Act, 1956.
An ISO 9001:2015 Certified Institution
Sevalpatti(P.O),Sivakasi - 626140.Tamilnadu.
LABORATORY RECORD
VI – SEMESTER
MAY 2024
P.S.R. ENGINEERING COLLEGE
(An Autonomous Institution, Affiliated to Anna University, Chennai)
Approved by AICTE, New Delhi & Accredited by National Board of Accreditation (NBA)
Accredited by NAAC with “A+” Grade, Recognized under 12(B) of the UGC Act, 1956.
An ISO 9001:2015 Certified Institution
Sevalpatti (P.O), Sivakasi - 626140. Tamilnadu.
Department of Computer Science and Engineering
BONAFIDE CERTIFICATE
by
Roll No in the
…………………………… …………………………………
Register No:
….……………………… …………………………………
1
Installation of Arduino Software (IDE)
Step1: Downloading
2
Step 3: Extraction of Files
The process will extract and install all the required files to execute properly
the Arduino Software (IDE)
3
Step 4: Connecting the board
The USB connection with the PC is necessary to program the board and not just to
power it up. The Uno and Mega automatically draw power from either the USB or an
external power supply. Connect the board to the computer using the USB cable. The
green power LED (labelled PWR) should go on.
Open the Arduino IDE software on your computer. Coding in the Arduino
language will control your circuit.
Open a new sketch File by clicking on New.
4
Step 6: Working on an existing project
5
Step 7: Select your Arduino board.
To avoid any error while uploading your program to the board, you must select the
correct Arduino board name, which matches with the board connected to your computer.
Go to Tools → Board and select your board.
6
Step 9: Upload the program to your board.
A Verify
B Upload
C New
D Open
E Save
F Serial Motor
7
8
Arduino Uno
Introduction: The Arduino Uno is an open-source microcontroller board based on the
Microchip ATmega328P microcontroller and developed by Arduino.cc. The board is
equipped with sets of digital and analog input/output (I/O) pins that may be interfaced to
various expansion boards (shields) and other circuits. The board has 14 digital I/O pins (six
capable of PWM output), 6 analog I/O pins, and is programmable with the Arduino IDE
(Integrated Development Environment), via a type B USB cable. It can be powered by the
USB cable or by an external 9-volt battery, though it accepts voltages between 7 and 20 volts.
The word "uno" means "one" in Italian and was chosen to mark the initial release of Arduino
Software.
9
Power USB
1 Arduino board can be powered by using the USB cable from your computer.All
you need to do is connect the USB cable to the USB connection (1).
Voltage Regulator
The function of the voltage regulator is to control the voltage given to the Arduino
3
board and stabilize the DC voltages used by the processor and otherelements.
Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does Arduino
4 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 thefrequency is 16,000,000
Hertz or 16 MHz.
Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning.You
5,17 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 pinscan
10 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
11 must know what IC your board has before loading upa new program from the
Arduino IDE. This information is available on the topof the IC. For more details
about the IC construction and functions, you can refer to the data sheet.
10
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 referredto as an SPI (Serial
12 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). Theyappear
in two places on the Arduino UNO board. First, at the digital pins 0 and 1, to
14 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 workas input digital pins
15 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
16
reference voltage (between 0 and 5 Volts) as the upper limit for the analog input
pins.
11
Ex.No:1
INTERFACING THE LED WITH ARDUINO UNO
AIM:
To construct the simple circuit for blinking the LED by using Arduino uno.
Hardware Require:
Components Quantity
1kohm Resistor 1
Red LED 1
Arduino Uno R3 1
Procedure:
Built the circuit as per the circuit diagram.
Components like resistor read to their terminal bend into 90degree angle in order
to fit the bread board socket.
Open the Arduino UNO IDE software on your system.
Code in the Arduino UNO language will central your circuit.
Open the new sketch file by clicking new window.
After finish the all circuit connections the write the code.
12
Code:
void setup()
pinMode(LED_BUILTIN, OUTPUT);
void loop()
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(LED_BUILTIN, LOW);
Circuit Diagram:
13
Result:
Thus the simple circuit for led blinking using Arduino was execute successfully
and the output was verified.
14
EX.NO:2
INTERFACING THE RGB LED WITH ARDUINO UNO
AIM:
To connect the simple circuit for blinking the RGB by using Arduino UNO.
Hardware Required:
Components Quantity
LED RGB 1
Arduino UNO 1
1 K ohm Resistor 3
Procedure:
Insert RGB LED into breadboard with common cathode/anode to GND and
resistors to digital pins.
Connect longer lead of RGB LED (anode) to current-limiting resistor, then
to Arduino's 5V pin.
Open Arduino IDE, write code defining pins as outputs, then loop to turn
on/off RGB LED with delays.
Connect Arduino Uno to computer via USB, select board and port in
Arduino IDE.
Click "Upload" to compile and upload code to Arduino.
RGB LED should blink with one second intervals for each color.
Adjust code and connections as needed for specific setup.
15
Code:
void setup()
{
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
}
void loop()
{
digitalWrite(13,HIGH); delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(11,HIGH);
delay(1000);
digitalWrite(11,LOW);
delay(1000);
}
16
Circuit Diagram:
17
Result:
Thus the simple circuit for blinking RGB using Arduino was executed
successfully and the output was verified.
18
Ex. No:3
CONTROLLING THE LIGHT EMITTING DIODE (LED) WITH A
PUSH BUTTON
Aim:
Hardware Required:
Components Quantity
Arduino Uno R3 1
220 Ω Resistor 1
Red LED 1
1 kΩ Resistor 1
Pushbutton 1
Procedure:
Insert the push button into your bread board and connect it to the digital pin 7
(07) which acts as input.
Insert the LED into the bread board.
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.
19
Code:
const int buttonPin = 2;
int buttonState = 0;
void setup()
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
void loop()
buttonState = digitalRead(2); if
(buttonState == HIGH)
digitalWrite(ledPin, HIGH);
else {
digitalWrite(ledPin, LOW);
delay(10);
20
Circuit Diagram:
Result:
Thus the controlling of the Light Emitting Diode (LED) with a push button was
executed successfully and the output was verified.
21
Ex. No:4
TRAFFIC MONITORING SYSTEM
Aim:
To construct the simple circuit for traffic light the led by using Arduino Uno R3.
Hardware Required:
Components Quantity
Arduino Uno R3 1
Green led 1
Yellow led 1
Red led 1
220 ohm resistor 3
Procedure:
Connect LED on the bread board as red, yellow, green respectively.
Connect the negative terminal of the led and connect the 220 ohm resistor in series.
Connect the positive terminal of the LED to the pins 2 to 10, respectively.
22
Code:
void setup()
{
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
}
void loop()
{
for (int i = 0 ; i < 10 ; i += 1)
{
digitalWrite(2, HIGH);
delay(100);
digitalWrite(2, LOW);
delay(100);
}
digitalWrite(2, HIGH);
delay(15000);
digitalWrite(2, LOW);
digitalWrite(1, HIGH);
delay(5000);
digitalWrite(1, LOW);
digitalWrite(0, HIGH);
delay(15000);
digitalWrite(0, LOW);
}
23
Circuit Diagram:
Result:
Thus the simple circuit for traffic light the LED by using Arduino Uno R3
24
successfully executed and the output was verified.
25
Ex. No:5
READING VALUES FROM ULTRASONIC SENSOR
Aim:
To construct the simple circuit for distance finding with ultrasonic sensors and
Arduino Uno
Hardware Required:
Components Quantity
Arduino Uno R3 1
Ultrasonic distance 1
sensor(4-pin)
1k ohms resistor 3
Red light 1
Yellow light 1
Green light 1
Procedure:
open the Arduino IDE.
select the color lights like yellow, green, red and connect the light with Arduino
board
upload the sketch to the connection diagram.
verify the output.
26
Code:
int trig = 9; int
echo = 8; int
red = 10;
duration = 0; int
cm = 0;
int in = 0;
void setup()
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
Serial.begin(9600);
Serial.println("Serial Started...");
void loop()
digitalWrite(trig,LOW);
digitalWrite(trig,HIGH);
digitalWrite(trig,LOW);
27
int duration = pulseIn (echo, HIGH);
cm = duration*0.034/2;
in = duration*0.0133/2;
Serial.println(in);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
delay(1000);
digitalWrite(green, HIGH);
digitalWrite(yellow, HIGH);
digitalWrite(red, HIGH);
delay(1000);
//yellow
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
delay(600);
digitalWrite(green, HIGH);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
28
delay(600);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
delay(600);
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(red, LOW);
delay(600);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
delay(300);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(300);
29
else if (in < 25)
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
delay(1000);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
delay(1000);
Circuit Diagram:
30
Result:
Thus the simple circuit ultrasonic sensors using with Arduino was successfully
executed and the output was verified.
31
Ex. No:6.1
INTERFACING LCD DISPLAY WITH ARDUINO UNO
Aim:
To connect the simple circuit for display the name using LCD display
using Arduino UNO.
Hardware Required:
Components Quantity
Arduino Uno R3 1
MCP23008-based, 32 (0x20) LCD 16 x 2 1
(I2C)
Procedure:
Connect SDA pin of the LCD to A4 and SCL pin to A5 on Arduino Uno R3.
Ensure power (VCC) and ground (GND) pins of the LCD are connected to
5V and GND respectively.
Define LCD address (usually 0x20) and dimensions (16x2) in Arduino
code.
Create LiquidCrystal_I2C object with defined address and dimensions,
initialize LCD in setup().
Use lcd.setCursor() and lcd.print() to display text on LCD in setup() or
loop().
Upload code to Arduino, adjust text and connections as needed for your
Circuit.
32
Code:
#include <Adafruit_LiquidCrystal.h>
int seconds = 0;
Adafruit_LiquidCrystal lcd_1(0);
void setup()
lcd_1.begin(16, 2);
void loop()
lcd_1.setCursor(4, 0);
lcd_1.print(“S.NAREN”);
lcd_1.setCursor(10, 1);
lcd_1.print(21CS069);
33
Circuit Diagram:
Result:
Thus the simple circuit for display the name using LCD display
using Arduino UNO was executed successfully.
34
Ex.No:6.2
INTERFACING TEMPERATURE SENSOR WITH ARDUINO
Aim:
Hardware Required:
Components Quantity
Arduino Uno R3 1
Procedure:
Connect the 1K ohm resistor between the middle pin of the TMP36
temperature sensor and ground (GND) on the Arduino UNO.
Connect the left pin of the TMP36 sensor to 5V on the Arduino UNO.
Connect the right pin of the TMP36 sensor to analog pin A0 on the Arduino
UNO.
Connect the anode (longer lead) of the red LED to digital pin 2, green LED to
pin 3, and yellow LED to pin 4.
Write code to read temperature from TMP36, and based on thresholds, turn on
respective LEDs to indicate temperature ranges.
35
Code:
void setup()
pinMode(A0, INPUT);
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
void loop()
baselineTemp = 40;
Serial.print(celsius);
Serial.print(" C, ");
Serial.print(fahrenheit);
Serial.println(" F");
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
36
}
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
37
digitalWrite(4, HIGH);
delay(1000);
Circuit Diagram:
38
Result:
Thus the simple circuit for temperature measurement using LCD display was executed
successfully and the output was verified.
39
Ex. No:7
INTERFACING PIR SENSOR WITH ARDUINO
Aim:
Hardware Required:
Components Quantity
PIR Sensor 1
Arduino Uno R3 1
Red LED 1
1kohm resistor 1
Procedure:
.
Insert the PIR sensor into the breadboard.
Connect VCC to Arduino's 5V, GND to GND, and OUT to digital pin 2
(D2).
Upload provided code to Arduino using Arduino IDE.
40
Code:
int pir = 0;
void setup()
pinMode(5, INPUT);
Serial.begin(9600);
pinMode(13, OUTPUT);
void loop()
pir = digitalRead(5);
Serial.println(pir);
if (pir == 1)
digitalWrite(13, HIGH);
else
digitalWrite(13, LOW);
41
Circuit Diagram:
42
Result:
Thus the develop a interfacing PIR sensor with Arduino board was successfully
executed and the output was verified.
43
Ex. No:8
INTERFACING SERVO MOTOR WITH ARDUINO
Aim:
To connect the simple circuit for find angle servo motor using Arduino UNO.
Hardware Required:
Components Quantity
Arduino Uno R3 1
Positional Micro Servo 1
Procedure:
Connect the servo motor to your Arduino Uno. Most servo motors have three wires:
power (usually red), ground (usually brown or black), and signal (usually orange or
yellow).
Connect the power wire to the 5V pin on the Arduino Uno, the ground wire to any
ground pin, and the signal wire to any digital PWM (Pulse Width Modulation) pin.
Develop the code to control the servo motor's position.
After uploading the code, observe the behavior of the servo motor. Verify that it
rotates to the specified angles as programmed in your code.
44
Code:
#include <Servo.h>
Servo servoBase;
void setup()
{
servoBase.attach(A1);
servoBase.write(0); //asigno 0 al servo motor
}
void loop() {
for(int i=0; i<=180; i=i+10)
servoBase.write(i);
delay(550);
}
45
Circuit Diagram:
Result:
Thus the servo motor & setting servo motor with Arduino UNO was successfully
executed and the output was verified.
46
Ex. No:9
INTERFACING LDR SENSOR WITH ARDUINO
Aim:
To construct a simple circuit for Automatic Street Light by using Arduino UNO.
Hardware Required:
Components Quantity
Arduino Uno R3 1
Photo Resistor 1
1 kΩ Resistor 1
Red LED 1
300 Ω Resistor 1
Procedure:
Connect the LDR (Light Dependent Resistor) sensor to your Arduino Uno. Wire
one leg of the LDR to the 5V pin on the Arduino Uno, and wire the other leg to
one leg of a resistor (any value between 1kΩ to 10kΩ is usually suitable). Connect
the other leg of the resistor to any ground (GND) pin on the Arduino Uno.
Finally, connect the junction between the LDR and the resistor to an analog
input pin (e.g., A0) on the Arduino Uno.
Develop the code to read data from the LDR sensor.
After uploading the code, expose the LDR sensor to different levels off light and
observe the readings on the Serial Monitor (if set up).
Verify that the sensor's output changes accordingly with varying light levels.
47
Code:
int input = 0;
void setup()
pinMode(A0, INPUT);
Serial.begin(9600);
pinMode(2, OUTPUT);
void loop()
input = analogRead(A0);
Serial.println(input);
digitalWrite(2, HIGH);
else
digitalWrite(2, LOW);
48
Circuit Diagram:
49
Result:
Thus the simple circuit for Automatic Street Light by using Arduino Uno was
executed successfully and the output was verified.
50
Ex. No:10
SMART HOME AUTOMATION SYSTEM
Aim:
To construct a simple circuit for smart home automation system using Arduino UNO.
Hardware Required:
Components Quantity
Arduino Uno R3 1
Ultrasonic Distance Sensor 1
Positional Micro Servo 1
PIR Sensor 1
Blue LED 2
1 kΩ Resistor 1
Temperature Sensor [TMP36] 1
H-bridge Motor Driver 1
DC Motor 1
Blue led 2
Green led 2
Red led 2
Procedure:
Code:
void loop() {
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
52
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
//Serial.print(inches);
//Serial.print("in, ");
//Serial.print(cm);
//Serial.print("cm");
//Serial.println();
//delay(100);
servo1.write(0);
if(cm < 40)
{
servo1.write(90);
delay(2000);
}
else
{
servo1.write(0);
if(pir == HIGH)
{
digitalWrite(4,HIGH);
delay(1000);
53
}
else if(pir == LOW)
{
digitalWrite(4,LOW);
}
Serial.println("temperature");
Serial.println(temperature);
54
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}
Circuit Diagram:
55
Result:
Thus the simple circuit for home automation system using Arduino UNO was executed
successfully and the output was verified.
56