0% found this document useful (0 votes)
19 views5 pages

21BEC1010 - LAB3 - Sri Rahul

Uploaded by

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

21BEC1010 - LAB3 - Sri Rahul

Uploaded by

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

NAME: SRI RAHUL RAGHAV REG.

NO: 21BEC1010

LAB-3: Ultrasonic Sensor

TASK STATEMENT:
To measure the distance using the ultrasonic sensor and make the LED’s blink
as per the range of the distance detected.
CIRCUIT DIAGRAM:
PROGRAM:
int trig = 9;
int echo = 10;
int led1 = 11;
int led2 = 12;
int led3 = 13;

long duration = 0;
int cm = 0;
int in = 0;

void setup()
{
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
Serial.begin(9600);
Serial.println("Serial Started...");
}

void loop()
{
digitalWrite(trig, LOW);
digitalWrite(trig, HIGH);
digitalWrite(trig, LOW);

int duration = pulseIn (echo, HIGH);


cm = duration*0.034/2;
in = duration*0.0133/2;

Serial.println(in);

if (in >= 108) {


digitalWrite(led3, LOW);
digitalWrite(led2, LOW);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led3, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led1, LOW);
delay(1000);
}

else if (in < 108 && in > 36){


digitalWrite(led3, LOW);
digitalWrite(led2, LOW);
digitalWrite(led1, LOW);
delay(600);
digitalWrite(led3, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led1, LOW);
delay(600);
}

else if (in <= 36 ){


digitalWrite(led3, LOW);
digitalWrite(led2, LOW);
digitalWrite(led1, LOW);
delay(300);
digitalWrite(led3, LOW);
digitalWrite(led2, LOW);
digitalWrite(led1, HIGH);
delay(300);
}
}

RESULT:
VERIFICATION:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy