21BEC1010 - LAB3 - Sri Rahul
21BEC1010 - LAB3 - Sri Rahul
NO: 21BEC1010
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);
Serial.println(in);
RESULT:
VERIFICATION: