Object Missing Alert

12420

Intro: Object Missing Alert

A machine that lights up when the object next to it is gone.

STEP 1: Putting It Together

As the title suggests, assemble the machine exactly as the picture shows.

STEP 2: Coding

Put this into the Arduino software

------------------------------------------------------------------------------------------------------------------------------------------------------

#define trigPin 13

#define echoPin 12

#define greenLED 11

#define redLED 10

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(greenLED, OUTPUT);

pinMode(redLED, OUTPUT);

}

void loop() {

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(50);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if (distance < 10) { // This is where the LED On/Off happens

digitalWrite(greenLED,HIGH);

} else {

digitalWrite(greenLED,LOW); digitalWrite(redLED,HIGH);

}

if (distance >= 200 || distance <= 0){

Serial.println("Out of range");

} else {

Serial.print(distance); Serial.println(" cm");

} delay(500);

}

STEP 3: Done

You are done.