Introduction: Ultrasonic Monitor

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

Step 1: What Do You Need?

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)

Step 2:

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

Step 3: Connect

Step 4: Final

Step 5: 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);}