Ultrasonic Monitor

by Dylanthechosenone in Circuits > Electronics

292 Views, 1 Favorites, 0 Comments

Ultrasonic Monitor

IMG_3198.JPG

This machine can be used as a warning light when something is close to what you want to protect

What Do You Need?

Eee

Arduino UNO R3 (I use the Adafruit mount)One (1) HC-SR04 Ultrasonic SensorOne (1) Red LEDOne (1) Green LEDTwo (2) 560 ohm (Green, Blue, Brown, Gold) ResistorsHalf BreadboardEight (8) Male/Male hookup wiresA ruler that measures centimetres (or use the serial monitor)

unnamed.jpg

For this instrument, I used the old carton for a purpose that was hard to find.

Connect

截圖 2019-12-16 22.44.47.png

Final

hhhhhh

Program

https://create.arduino.cc/editor/Dylancso/e6edda8b...

void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(led, OUTPUT); pinMode(led2, OUTPUT);}

void loop() { long duration, distance; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH);// delayMicroseconds(1000); - Removed this line delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance < 4) { // This is where the LED On/Off happens digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off digitalWrite(led2,LOW);} else { digitalWrite(led,LOW); digitalWrite(led2,HIGH); } if (distance >= 200 || distance <= 0){ Serial.println("Out of range"); } else { Serial.print(distance); Serial.println(" cm"); } delay(500);}