0% found this document useful (0 votes)
22 views20 pages

Arduino LED and Sensor Projects Guide

This document summarizes an assignment involving blinking two LEDs in an interval using code. The code uses two digital pins to connect the LEDs and toggles them on and off in alternating fashion with a 3 second delay for one LED and 4 second delay for the other. The code uses variables to track a counter and conditional statements to control the LED states over multiple loops.
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)
22 views20 pages

Arduino LED and Sensor Projects Guide

This document summarizes an assignment involving blinking two LEDs in an interval using code. The code uses two digital pins to connect the LEDs and toggles them on and off in alternating fashion with a 3 second delay for one LED and 4 second delay for the other. The code uses variables to track a counter and conditional statements to control the LED states over multiple loops.
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

Assignment 01

Objective : Blinking 2 LED In a time Interval


Circuit Diagram : -

Description :-
Code :-
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT); // Led is connected in Digital PIN 13
pinMode(12,OUTPUT); // Led is connected in Digital PIN 12
}

int i=1;
void loop() {
// put your main code here, to run repeatedly:
if(i%2==0)
{
digitalWrite(13,1);
digitalWrite(12,0);
delay(3000); //1sec=1000milisec
i++;
}
else
{
digitalWrite(12,1);
digitalWrite(13,0);
delay(4000);
i++;
}

}
Simulation :-
Assignment-3

TOPIC: HC-SR04(Singling System using 4


LEDs/1 LED)

Objective:

What is an HC-SR04 Sensor?

HC-SR04 Ultrasonic (US) sensor is a 4 pin module, whose pin names are Vcc, Trigger,
Echo and Ground respectively. This sensor is a very popular sensor used in many
applications where measuring distance or sensing objects are required. The sensor
works with the simple formula that

Distance = Speed × Time


The Ultrasonic transmitter transmits an ultrasonic wave, this wave travels in air and
when it gets objected by any material it gets reflected back toward the sensor this
reflected wave is observed by the Ultrasonic receiver module.

COMPONENTS AND SUPPLIES

● Arduino UNO & Genuino


UNO

● Breadboard (generic)
● Wires
● HC-SR04 sensor

CIRCUIT DIAGRAM:
CODE:

Int trig=13;
int echo=12;
int led=4;
int led1=8;
int led2=7;
int led3=2;
void setup() {
// put your setup code here, to run once:
[Link](9600);
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
pinMode(led,OUTPUT);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
long distance,duration;
digitalWrite(trig,HIGH);
delayMicroseconds(1000);
digitalWrite(trig,LOW);
duration=pulseIn(echo,HIGH);
distance=(duration/2)/29.1;
[Link]("Distannce from object : ");
[Link](distance);
[Link]("CM");
delay(10);
if(distance<=50)
digitalWrite(led,HIGH);
else{
if(distance>50)
digitalWrite(led,LOW);
if(distance>50 && distance<=100)
digitalWrite(led1,HIGH);
else{
if(distance>100)
digitalWrite(led1,LOW);
if(distance>100 && distance<=150)
digitalWrite(led2,HIGH);
else{
if(distance>150)
digitalWrite(led2,LOW);
if(distance>150 && distance<=200)
digitalWrite(led3,HIGH);
else
if(distance>200)
digitalWrite(led3,LOW);
}
}
}
SIMULATION:

OUTPUT:
Assignment -2
Assignment - 5
Smoke Detection Using MQ2
Objective
In this example, we will get to read the sensor analog output voltage and when the
smoke reaches a certain level, the buzzer will make a sound and a red LED will turn on.

When the output voltage is below that level, the green LED will be turned on.

What is an MQ-2 Smoke Sensor?

The MQ-2 smoke sensor is sensitive to smoke and to the following flammable gases:

● LPG
● Butane
● Propane
● Methane
● Alcohol
● Hydrogen

The resistance of the sensor is different depending on the type of gas.

The smoke sensor has a built-in potentiometer that allows you to adjust the sensor
sensitivity according to how accurate you want to detect gas.

COMPONENTS AND SUPPLIES


● Arduino UNO & Genuino
UNO

● Breadboard (generic)
● MQ-2 Smoke detection sensor
● Wires
● LEDs
● Resistor
● Buzzer

Circuit
CODE:

int smoke = A0;


int buzzer = 4;
int redled = 8;
int greenled =7;
void setup() {
// put your setup code here, to run once:
pinMode(smoke,INPUT);
pinMode(greenled,OUTPUT);
pinMode(redled,OUTPUT);
pinMode(buzzer,OUTPUT);
[Link](9600);
}

void loop() {
// put your main code here, to run repeatedly:
int thres = 200;
int smokeReg = analogRead(smoke);
[Link]("Smoke : ");
[Link](smokeReg);
if(smokeReg>thres){
digitalWrite(redled,HIGH);
digitalWrite(greenled,LOW);
tone(buzzer,1000,10000);
}
else{
digitalWrite(redled,LOW);
digitalWrite(greenled,HIGH);
noTone(buzzer);
}
}

SIMULATION & OUTPUT:


ASSIGNMENT - 6

Radar using HCSR04 and motor

OBJECTIVE:

What is an HC-SR04 Sensor?


HC-SR04 Ultrasonic (US) sensor is a 4 pin module, whose pin names are Vcc, Trigger,
Echo and Ground respectively. This sensor is a very popular sensor used in many
applications where measuring distance or sensing objects are required. The sensor
works with the simple high school formula that

Distance = Speed × Time


The Ultrasonic transmitter transmits an ultrasonic wave, this wave travels in air and
when it gets objected by any material it gets reflected back toward the sensor this
reflected wave is observed by the Ultrasonic receiver module.

COMPONENTS AND SUPPLIES

● Arduino UNO & Genuino


UNO

● Breadboard (generic)
● Wires
● HC-SR04 sensor

CIRCUIT:
CODE:

//Includes the Servo library


#include <Servo.h>
// Defines Tirg and Echo pins of the Ultrasonic Sensor
const int trigPin = 10;
const int echoPin = 11;
// Variables for the duration and the distance
long duration;
int distance;
Servo myServo; // Creates a servo object for controlling the servo motor
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
[Link](9600);
[Link](12); // Defines on which pin is the servo motor attached
}
void loop() {
// rotates the servo motor from 15 to 165 degrees
for(int i=15;i<=165;i++){
[Link](i);
delay(30);
distance = calculateDistance();
// Calls a function for calculating the distance measured by the Ultrasonic sensor for
each degree
[Link]("Angle :");
[Link](i); // Sends the current degree into the Serial Port
[Link]("Distance :");
[Link](distance); // Sends the distance value into the Serial Port
//[Link]("."); // Sends addition character right next to the previous value needed
later in the Processing IDE for indexing
}
// Repeats the previous lines from 165 to 15 degrees
for(int i=165;i>15;i--){
[Link](i);
delay(30);
distance = calculateDistance();
[Link](i);
//[Link](",");
[Link](distance);
//[Link](".");
}
}
// Function for calculating the distance measured by the Ultrasonic sensor
int calculateDistance(){

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave
travel time in microseconds
distance= duration*0.034/2;
return distance;
}

SIMULATION:
OUTPUT:

You might also like