Object Missing Alert
by elonmmuskofbadideas in Circuits > Arduino
140 Views, 2 Favorites, 0 Comments
Object Missing Alert
A machine that lights up when the object next to it is gone.
Supplies
1. Breadboard x1
2. Arduino Leonard
3. Wires x7
4. Ultraviolet Sensor x1
5. 560 ohm Resistors x1
6. LED (any colour) x1
Putting It Together
As the title suggests, assemble the machine exactly as the picture shows.
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);
}
Done
You are done.