0% found this document useful (0 votes)
65 views1 page

Sketch Nov25a.ino

This code uses an ultrasonic sensor connected to trigger and echo pins to measure distance, activates a buzzer if the distance is less than or equal to 10 cm, and prints the distance and door status to the serial monitor, toggling the buzzer on or off depending on the distance reading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views1 page

Sketch Nov25a.ino

This code uses an ultrasonic sensor connected to trigger and echo pins to measure distance, activates a buzzer if the distance is less than or equal to 10 cm, and prints the distance and door status to the serial monitor, toggling the buzzer on or off depending on the distance reading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

int trigger_pin = 2;

int echo_pin = 3;
int buzzer_pin = 4;

int time;
int distance;

void setup ( ){

Serial.begin (9600);
pinMode (trigger_pin, OUTPUT);
pinMode (echo_pin, INPUT);
pinMode (buzzer_pin, OUTPUT);
}

void loop ( ) {

digitalWrite (trigger_pin, HIGH);


delayMicroseconds (10);
digitalWrite (trigger_pin, LOW);
time = pulseIn (echo_pin, HIGH);
distance = (time ' 0.034) / 2;

if (distance <= 10)


{
Serial.println (" Door Open ");
Serial.print (" Distance= ");
Serial.println (distance);
digitalWrite (buzzer_pin, HIGH);
delay (500);
}

else {
Serial.println ( " Door closed ");
Serial.print (" Distance ");
Serial.println (distance);
digitalWrite (buzzer_pin, LOW);
delay (500);
}
}

You might also like