Demo5 – Tricky Box
The device created is a box that tricks users into trying to store something in it. While the user is relatively far away from the box, the lid will open to invite users to put something in it. However, when the user approaches the box, it closes the lid to prevent anything from being stored in it.
CODE:
#include
#define IR_PIN A0
Servo lid;
const int LID_PIN = 9;
// check if sensed distance is between specified threshold
// https://acroname.com/articles/linearizing-sharp-ranger-data
bool check_IR(int IR_PIN){
float vol = analogRead(IR_PIN)*(5.0/1024);
float dist = 2914/(vol + 5) - 1;
return (dist < 500);
}
void setup() {
lid.attach(LID_PIN);
lid.write(0);
}
void loop() {
if (check_IR(IR_PIN)) {
lid.write(60);
delay(100);
} else {
lid.write(0);
delay(100);
}
}
[\code]
VIDEO:
Leave a Reply
You must be logged in to post a comment.