Experiment No.
1 : Blinking of LEDs
Aim:
To build the circuit and demonstrate the blink/toggle led with an Arduino board.
Hardware and Software required:
Arduino Uno board, Light Emitting Diodes, Berg Connectors, Arduino IDE software
Circuit diagram:
Program:
1.1 Write a sketch to blink LED.
void setup() {
// put your setup code here, to run once:
pinMode(12,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
delay(1000);
}
1.2 Write a sketch to blink LED 5 times and turn off 50ms after.
void setup() {
// put your setup code here, to run once:
pinMode(12,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i<5; i++)
{
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
delay(1000);
}
digitalWrite(12,LOW);
delay(50000);
}
1.3 Write Arduino sketch to blink 2 LEDs alternatively.
Void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
Void loop()
{
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
delay(1000);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
delay(1000);
}
1.4 Write Arduino Sketch to blink two LEDs simultaneously
void setup() {
// put your setup code here, to run once:
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
delay(1000);
}
1.5 Write a sketch for
a) Blink an LED , using a loop function , 10 times with 1 second intervals.
b) After 10 blinks, the LED must completely turn off
c) Then blink a different LED 25 times with a second intervals.
d) Once the 25 blinks have achieved, this LED must also turn off.
Coding
const int LED =13;
const int LED2 =12;
int count = 0;
int count2 = 0;
void setup()
{
pinMode (LED, OUTPUT);
pinMode (LED2, OUTPUT);
}
void loop()
{
digitalWrite(LED, LOW);
digitalWrite(LED2, LOW);
while (count < 10)
{
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
count++;
}
digitalWrite(LED2, LOW);
while (count2 < 25)
{
digitalWrite(LED2, HIGH);
delay(1000);
digitalWrite(LED2, LOW);
delay(1000);
count2++;
}
digitalWrite(LED2, LOW);
}
1.6 Write a sketch to turn on LED and display it in serial monitor about its status ON/OFF.
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13,HIGH);
Serial.println("LED is ON");
delay(1000);
digitalWrite(13,LOW);
Serial.println("LED is OFF");
delay(1000);
}
Result:
The circuit for blinking of LEDs has been constructed and sketch for blinking LED output
verified using Arduino IDE.
Experiment No.2 Moving Message Display on LCD
Aim:
To construct the hardware for the LCD interfacing with Arduino board and demonstrate the LCD running
display.
Hardware and Software required:
Arduino Uno board, 16 X 2 Liquid Crystal Display, Berg Connectors, Arduino IDE software
Circuit diagram:
2.1 Display characters in LCD
#include<LiquidCrystal.h>
LiquidCrystal lcd (12,11,5,4,3,2);
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
lcd.print("Hello World!");
lcd.setCursor(0,1);
lcd.print("Be Happy!");
}
2.2 Scroll characters in LCD
#include<LiquidCrystal.h>
LiquidCrystal lcd (12,11,5,4,3,2);
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(" Dr.S.R.VIJAYALAKSHMI");
lcd.setCursor(3,1);
lcd.print(" SKASC, CBE");
}
void loop()
{
for (int i=0; i<13; i++)
{
lcd.scrollDisplayLeft();
delay(400);
}
for (int j=0; j<26; j++)
{
lcd.scrollDisplay Right();
delay(400);
}
}
Result:
The 16x2 LCD has been interfaced with Arduino Uno and the display sketch is verified.
Experiment No. 3 Tone generation
Aim
To construct the circuit and demonstrate the toggle output on speaker circuit using an Arduino board.
Hardware and Software required:
Arduino Uno board, buzzer or piezo speaker, Berg Connectors, Arduino IDE software
Circuit diagram:
3.1 Generate tone
void setup() {
// put your setup code here, to run once:
pinMode(9,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
tone(9,230);
delay(500);
noTone(9);
delay(500);
}
3.2 Generate notes for music key board
#define SPEAKER_PIN 9
void setup() {
// put your setup code here, to run once:
pinMode(SPEAKER_PIN,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
tone(SPEAKER_PIN,262,500); //C Note
delay(500);
tone(SPEAKER_PIN,294,500); //D Note
delay(500);
tone(SPEAKER_PIN,330,500); //E Note
delay(500);
noTone(SPEAKER_PIN); // no sound
delay(500);
}
3.3 Generate desire continuous frequency
#define SPEAKER_PIN 9
void setup() {
// put your setup code here, to run once:
pinMode(SPEAKER_PIN,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for (int i=200; i< 15000; i=i+50)
{
tone(SPEAKER_PIN,i,500); // frequency generation
delay(500);
}
noTone(SPEAKER_PIN); // no sound
delay(500);
}
Result:
The tone has been generated and verified output using Arduino Uno and IDE.
Experiment No. 4 DC motor Speed control
Aim
To assemble the DC motor interfacing circuit and demonstrate speed control outputwith the help of an
Arduino board.
Hardware and Software required:
Arduino Uno board, Geared DC motors, L293D motor driver module, Berg Connectors, Arduino IDE
software
Circuit diagram:
Sketch for DC motor speed control
int motorenable = 9;
int motorPin1 =10;
int motorPin2 = 11;
void setup() {
// put your setup code here, to run once:
pinMode(motorenable, OUTPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(motorenable, HIGH);
for (int mspeed =0; mspeed <= 255; mspeed+=20)
{
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(2000);
}
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
delay(2000);
for (int mspeed = 255; mspeed >= 0; mspeed-=20)
{
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(2000);
}
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
delay(2000);
}
Result:
The speed control of DC motor has been verified using Arduion Uno and IDE software.
Experiment No. 5 Position Control of Servo Motor
Aim
To control the shaft position of servo motor using potentiometer
Hardware and software required:
Arduino Uno board, Servo motor, 1 K Potentiometer, berg connectors, Arduion IDE.
Circuit Diagram
5.1 Position control using potentiometer
#include <Servo.h>
int potPin = 0;
int servoPin = 9;
Servo servo;
void setup() {
// put your setup code here, to run once:
servo.attach(servoPin);
}
void loop() {
// put your main code here, to run repeatedly:
int reading = analogRead(potPin);
int angle = map(reading, 0,1023, 0 , 180);
servo.write(angle);
}
5.2 servo rotate forward and backward
#include<Servo.h>
Servo servo;
int p = 0;
void setup() {
// put your setup code here, to run once:
servo.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
for (p = 0; p <=180; p+=1)
{
servo.write(p);
delay(15);
}
for (p = 180; p >= 0; p-=1)
{
servo.write(p);
delay(15);
}
}
Result:
The position control of servo motor output has been verified using Arduino Uno and IDE
software.
Experiment No. 6 Proximity detector
Aim
To construct a motion detector circuit with Arduino board and demonstrate the output.
Hardware and Software required:
Arduino Uno board, Inductive proximity sensor, Berg Connectors, Arduino IDE software
Circuit diagram:
const int PIRsensor = 7;
const int led = 13;
int count = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(PIRsensor,INPUT);
pinMode(led, OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
do
if(digitalRead(PIRsensor) == LOW)
{
Serial.println("object detected");
digitalWrite(led,HIGH);
delay(200);
count = count +1;
Serial.print("No. of count =");
Serial.println(count);
digitalWrite(led, LOW);
}
while(digitalRead(PIRsensor)== HIGH);
}
Result:
The proximity detector output has been verified using Arduino Uno and IDE software.
Experiment No.7. Accelerometer and Ultrasonic sensor interface
Aim
To interface accelerometer and ultrasonic sensor with Arduino Uno
Hardware and Software required
Arduion Uno, Accelerometer sensor, Ultrasonic sensor, berg connectors, Arduino IDE software
Circuit Diagram for Accelerometer
7.1 Read values of accelorometer
const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(analogRead(xpin));
Serial.print("\t");
Serial.print(analogRead(ypin));
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.print("\t");
Serial.println();
delay(100);
}
7.2 Roll and Pitch calculation using accelerometer
#include <math.h>
const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int x_adc, y_adc, z_adc;
double x_g, y_g, z_g;
double roll, pitch;
x_adc = analogRead(xpin);
y_adc = analogRead(ypin);
z_adc = analogRead(zpin);
Serial.print("x =");
Serial.print(x_adc);
Serial.print("\t\t");
Serial.print("y =");
Serial.print(y_adc);
Serial.print("\t\t");
Serial.print("z =");
Serial.print(z_adc);
Serial.print("\t\t");
/*Acceleration in x direction in g units*/
x_g = ((((double)(x_adc*5)/1024)-1.65)/0.330);
/*Acceleration in y direction in g units*/
y_g = ((((double)(y_adc*5)/1024)-1.65)/0.330);
/*Acceleration in z direction in g units*/
z_g = ((((double)(z_adc*5)/1024)-1.65)/0.330);
roll = (((atan2(y_g, z_g) *180)/3.14)+180);
/*Formula for roll*/
pitch = (((atan2(z_g, x_g) *180)/3.14)+180);
/*Formula for roll*/
/* not possible to measure yaw using accelerometer - need gyroscope */
Serial.print("Roll = ");
Serial.print(roll);
Serial.print("\t");
Serial.print("Pitch = ");
Serial.print(pitch);
Serial.print("\n\n");
delay(1000);
}
7.3 Circuit diagram to interface ultrasonic with arduino uno
7.3 Ultrasonic sensor interface
const int trigpin = 9;
const int echopin = 10;
float duration, distance;
void setup() {
// put your setup code here, to run once:
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
digitalWrite(trigpin, LOW);
duration = pulseIn(echopin,HIGH);
distance = (duration*0.0343)/2;
Serial.print("Distance:");
Serial.println(distance);
delay(100);
}
Result:
The Accelerometer and Ultrasonic sensor output has been verified using Arduino Uno and IDE
software.
Experiment No. 8: Obstacle Avoiding Robot using Ultrasonic Sensor
Aim
To interface ultrasonic sensor with Arduino Uno for designing obstacle avoiding robot
Hardware and Software required
Arduion Uno, DC motors, Motor Drivers, Ultrasonic sensor, berg connectors, Arduino IDE
software
Circuit Diagram:
Program:
int trigPin = 9; // trig pin of HC-SR04
int echoPin = 10; // Echo pin of HC-SR04
long duration, distance;
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(7, OUTPUT); // Left motor connection - ports
pinMode(6, OUTPUT);
pinMode(5, OUTPUT); // Right motor connection - ports
pinMode(4, OUTPUT);
digitalWrite(7, LOW); // Clear motor driver ports
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // send waves for 10 us
delayMicroseconds(10);
duration = pulseIn(echoPin, HIGH); // receive reflected waves
distance = duration / 58.2; // convert to distance delay(10);
Serial.println(distance);
if (distance > 19)
{
digitalWrite(7, HIGH); // move forward
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
}
if (distance < 18)
{
digitalWrite(7, LOW); // stop vehicle
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(500);
digitalWrite(7, LOW); // move backward
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(7, LOW); // stop vehicle
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, HIGH); // move right
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(500);
}
}
Result:
The obstacle avoiding robot using ultrasonic sensor and Arduino Uno has been designed and verified
its operation.
Experiment 9 Line-following Robot
Aim: To build a line following robot with the help of Arduino board and demonstrate the output.
Hardware / Software required:
1. Arduino Uno Board
2. IR sensor modules (2)
3. Robot Mobile Assembly and Geared Motors (2)
4. L293D motor driver module (1)
5. Battery (12V)
6. Berg Connector
7. Arduino IDE
9.1 Circuit diagram to interface IR sensor with Arduino uno
int IRsensor = 9;
int LED = 13;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Serial Working");
pinMode(IRsensor, INPUT);
pinMode(LED,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorstatus = digitalRead(IRsensor);
if (sensorstatus == 1)
{
digitalWrite(LED, LOW);
Serial.println("Motion Ended!");
}
else
{
digitalWrite(LED,HIGH);
Serial.println("Motion Detected!");
}
}
9.2 Line following Robot Circuit diagram:
Program for line following robot:
int IR1 = 8;
int IR2 = 9;
void setup() {
pinMode(IR1, INPUT);
pinMode(IR2, INPUT);
pinMode(7, OUTPUT); // Left motor connection
pinMode(6, OUTPUT);
pinMode(5, OUTPUT); // Right motor connection
pinMode(4, OUTPUT);
void loop() {
//HIGH from IR1 & IR 2 to stop motors both
if(digitalRead(IR1)== HIGH && digitalRead(IR2)==HIGH)
digitalWrite(7, LOW); // Clear motor
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
//LOW from IR1 & IR 2 to move motors forward
else if(digitalRead(IR1)== LOW && digitalRead(IR2)==LOW)
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
//LOW from IR1 & HIGH from IR 2 to move motor right
else if(digitalRead(IR1)== LOW && digitalRead(IR2)==HIGH)
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
//HIGH from IR1 & LOW from IR 2 to move motor left
else if(digitalRead(IR1)== HIGH && digitalRead(IR2)==LOW)
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
else
digitalWrite(7, LOW); // stop motor
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
Result:
The line-following robot has been designed and tested for operation.
Experiment 10 :Wireless Controller Robot
Aim:
To build a wireless controlled robot using Bluetooth module and Arduino board, and demonstrate the
output
Hardware and Software required
1. Arduino Uno Board
2. HC-05 Bluetooth module
3. Geared motor
4. L293D motor driver module
5. Battery (12V)
6. Mobile Phone with Bluetooth terminal App
7. Berg Connectors
8. . Arduino IDE
10.1 Circuit diagram for interfacing Atduino uno and Bluetooth:
Steps to download App in mobile phone:
nce you have uploaded the code you need to go to play store and download arduino bluetooth
controller app . Please follow the below instructions.
after you have downloaded it you need to open the app and it will start searching for HC-05 bluetooth
module
Once you see it click on it and then select switch mode
you will find the settings or configure button on the top right corner.
now you control your led using a mobile app.
Program to on/off LED using Bluetooth :
char incomingValue = 0;
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
incomingValue = Serial.read();
Serial.print(incomingValue);
Serial.print("/n");
if (incomingValue == '1')
digitalWrite(13,HIGH);
else if (incomingValue == '0')
digitalWrite(13,LOW);
}
}
10.2 Wireless controlled robot Program
#define led1 = 13
#define in1 = 12
#define in2 = 11
#define in3 = 10
#define in4 = 9
void setup() {
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
if (Serial.available()>0)
{
char inputvalue = char (Serial.read());
if (inputvalue == 'F')
{
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
else if (inputvalue == 'B')
{
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
}
else if (inputvalue == 'R')
{
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
else if (inputvalue == 'L')
{
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
else if (inputvalue == 'C')
{
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
else if (inputvalue == 'A')
{
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
}
else if (inputvalue == '0')
{
digitalWrite(13, HIGH);
}
else if (inputvalue == 's')
{
digitalWrite(13, LOW);
}
else if (inputvalue == 'S')
{
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
}
10.2 Wireless controlled robot circuit diagram
Result
The wireless controlled robot was designed and tested using the Bluetooth module HC-05 and
the Arduino Uno.