You are on page 1of 24

Robotics Lab

Experiment - 1
Title : LED Blink
Objective : To demonstrate LED blinking.
Components Required :
1. Arduino UNO
2. Jumper Wires
3. Bread Board
4. IR Sensor

Circuit Diagram :

1.

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output
Code :
int led = 13;
void setup() {
pinMode(led, OUTPUT);
}

void loop() {
digitalWrite(led,
HIGH); delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
Result : The LED has blinked with 1 second delay.

AI Department,VJIT Page 1
Robotics Lab

Experiment - 2
Title : Sound
Sensor
Objective : To demonstrate the working of sound sensor
Components Required :
1. Arduino UNO
2. Jumper Wires
3. Sound Sensor
4. Breadboard
5. LED
6. Resistor (220 ohm)

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 2
Robotics Lab

Code :

int soundSensor=2;
int LED=4;
boolean LEDStatus=false;

void setup() {
pinMode(soundSensor,INPUT);
pinMode(LED,OUTPUT);

void loop() {

int SensorData=digitalRead(soundSensor);
if(SensorData==1){

if(LEDStatus==false){
LEDStatus=true;
digitalWrite(LED,HIGH);
}
else{
LEDStatus=false;
digitalWrite(LED,LOW);
}
}
}

Result : The LED has blinked with 1 second delay.

AI Department,VJIT Page 3
Robotics Lab

Experiment - 3
Title : Servo
Motor
Objective : To demonstrate the working of servo motor
Components Required :
1. Arduino UNO
2. Jumper Wires
3. Servo Motor
4. Breadboard

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 4
Robotics Lab

Code :

#include<Servo.h>
Servo motor;
int p=0;
void setup()
{
motor.attach(9);
motor.write(270);
}

void loop() {
for(p=0;p<270;p++) {
motor.write(p);
delay(10);
}
for(p=270;p>=1;p--) {
motor.write(p);
delay(10);
}

Result : The servo motor rotates periodically in clockwise and anticlockwise directions.

AI Department,VJIT Page 5
Robotics Lab

Experiment - 4
Title : Rotary
Encoder
Objective : To demonstrate the working of Rotary Encoder.

Components Required :
1. Arduino UNO
2. Jumper Wires
3. Rotary Encoder
4. Breadboard

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer

AI Department,VJIT Page 6
Robotics Lab
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 7
Robotics Lab

Code :

#define CLK 4
#define DT 5

int counter = 0;
int currentStateCLK;
int lastStateCLK;
String currentDir ="";

void setup() {
pinMode(CLK,INPUT);
pinMode(DT,INPUT);
Serial.begin(9600);
lastStateCLK = digitalRead(CLK);
}
void loop() {
currentStateCLK = digitalRead(CLK);
if (currentStateCLK != lastStateCLK && currentStateCLK == 1){
if (digitalRead(DT) != currentStateCLK) {
counter --;
currentDir ="CCW";
} else {
counter ++;
currentDir ="CW";
}
Serial.print("Direction: ");
Serial.print(currentDir);
Serial.print(" | Counter: ");
Serial.println(counter);
}

lastStateCLK = currentStateCLK;
delay(1);
}

Result :Serial Monitor Output: Direction CCW | Counter: 1


Direction CCW | Counter: 2
Direction CC | Counter: 1
Direction CC | Counter: 0
AI Department,VJIT Page 8
Robotics Lab

Experiment - 5
Title : Temperature Sensor
KY001
Objective : To demonstrate the working of a Temperature Sensor.
Components Required :
1. Arduino UNO
2. Jumper Wires
3. Temperature Sensor KY001
4. Breadboard

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 9
Robotics Lab
Code :

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 8

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup(void)
{
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library
Demo"); sensors.begin();
}

void loop(void)
{
Serial.print("Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");

Serial.print("\nTemperature : ");
Serial.print(sensors.getTempCByIndex(0));
}

Result :
Serial Monitor Output:
Dallas Temperature
Demo Requesting
temperatures DONE
Temperature : 28

AI Department,VJIT Page 10
Robotics Lab

Experiment - 6
Title : Touch
Sensor
Objective : To demonstrate the working of a Touch Sensor.
Components Required :
1. Arduino UNO
2. Jumper Wires
3. Touch Sensor
4. Breadboard
5. LED

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 11
Robotics Lab
Code :

int Led = 13;


int TouchSensor =
3; int val;

void setup ()
{
pinMode (Led, OUTPUT);
pinMode (TouchSensor, INPUT);
}
void loop ()
{
val = digitalRead (TouchSensor)
; if (val == HIGH)
{
digitalWrite (Led, HIGH);
}
else
{
digitalWrite (Led, LOW);
}
}

Result : The Led glows when the sensor is touched.

AI Department,VJIT Page 12
Robotics Lab

Experiment - 7
Title : Button
Objective : To demonstrate the working of a Button.
Components Required :
1. Arduino UNO
2. Jumper Wires
3. Button
4. Breadboard
5. LED
6. Resistors (220 ohm)

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 13
Robotics Lab
Code :

int buttonPin = 7;
int ledPin = 8;

bool buttonState = false;

void setup() {
pinMode(buttonPin,INPUT);
pinMode(ledPin,OUTPUT);

}
void loop() {

buttonState = digitalRead(buttonPin);

if ( buttonState == true){
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}

Result : The Led glows when the button is pressed.

AI Department,VJIT Page 14
Robotics Lab

Experiment - 8
Title : RGB LED
Objective : To demonstrate the working RGB LED.
Components Required :
1. Arduino UNO
2. Jumper Wires
3. Breadboard
4. RGB LED
5. Resistors (220 ohm)

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 15
Robotics Lab
Code :

int red_light_pin= 11;


int green_light_pin = 10;
int blue_light_pin = 9;

void setup() {
pinMode(red_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT);
pinMode(blue_light_pin, OUTPUT);
}
void loop() {
RGB_color(255, 0, 0); // Red
delay(1000);
RGB_color(0, 255, 0); // Green
delay(1000);
RGB_color(0, 0, 255); // Blue
delay(1000);
RGB_color(255, 255, 0); //
Yellow delay(1000);
RGB_color(255, 255, 255); // White
delay(1000);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}

Result : The RGB LED produces different colors periodically.

AI Department,VJIT Page 16
Robotics Lab

Experiment - 9
Title : Laser
Emitter
Objective : To demonstrate the working of Laser Emitter.

Components Required :
1. Arduino UNO
2. Jumper Wires
3. Breadboard
4. Button
5. Resistor (220 ohm)
6. Buzzer

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 17
Robotics Lab

Code :

int laserPin = 13;

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

void loop () {
digitalWrite(laserPin, HIGH);
delay(100);
digitalWrite(laserPin, LOW);
delay(100);
}

Result : The Laser Emitter emits Laser with delay.

AI Department,VJIT Page 18
Robotics Lab

Experiment - 10
Title : Buzzer
Objective : To demonstrate the working of a Buzzer.

Components Required :
1. Arduino UNO
2. Jumper Wires
3. Breadboard
4. Button
5. Resistor (220 ohm)
6. Buzzer

Circuit Diagram :

Procedure:
Make the connection as per the circuit diagram
1. Connect the Arduino to the computer
2. Compile and upload the code to Arduino
3. Observe the output

AI Department,VJIT Page 19
Robotics Lab

Code :

int buttonPin = 8;
int buzzerPin = 5;

bool buttonState = false;

void setup() {
pinMode(buttonPin,INPUT);
pinMode(buzzerPin,OUTPUT);

}
void loop() {

buttonState = digitalRead(buttonPin);

if ( buttonState == true){
digitalWrite(buzzerPin, HIGH);
delay(1000);
}
else {
digitalWrite(buzzerPin, LOW);
}
}

Result : The Buzzer sounds when the button is pressed.

AI Department,VJIT Page 20
Robotics Lab

Experiment - 11
Title : Flame
Sensor
Objective : To demonstrate the working of Flame Sensor.

Components Required :
1. Arduino UNO
2. Jumper Wires
3. Flame Sensor
4. Buzzer

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 21
Robotics Lab

Code :

int flamePin = 2;
int buzzer = 5;

void setup() {
pinMode(flamePin,INPUT_PULLUP);
pinMode(buzzer,OUTPUT);
}

void loop() {
if(digitalRead(flamePin) == LOW){
digitalWrite(buzzer,HIGH);
}else{ digitalWrite(buzzer,L
OW);
}
}

Result : The Buzzer sounds when the flame is detected.

AI Department,VJIT Page 22
Robotics Lab

Experiment - 12
Title : IR Sensor
Objective : To demonstrate the working of IR Sensor

Components Required :
1. Arduino UNO
2. Jumper Wires
3. Breadboard
4. IR Sensor
5. LED

Circuit Diagram :

Procedure:
1. Make the connection as per the circuit diagram
2. Connect the Arduino to the computer
3. Compile and upload the code to Arduino
4. Observe the output

AI Department,VJIT Page 23
Code :

int IRSensor = 2;
int LED = 13;

void setup()
{

pinMode (IRSensor, INPUT);


pinMode (LED, OUTPUT);
}

void loop()
{
int statusSensor = digitalRead (IRSensor);

if (statusSensor == 1)
digitalWrite(LED, LOW);
}

else
{
digitalWrite(LED, HIGH);
}

Result : The LED glows when an obstacle comes in front of the IR Sensor.

24

You might also like