
blog
Handheld Virtual Donut
We render your hand-held virtual donut
I use an ultra-sound module & a servo to flush the toilet

I wanted to use a servo to flush a toilet somehow.
I wrote the code for the servor & the ultrasound & tested it some. This is what gave me the most reliable results:
#include <Servo.h>
Servo servo;
void setup() {
servo.attach(A0);
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(9, INPUT);
}
int i, n, p = 100;
unsigned int duration, distance;
char buf[64];
void loop() {
digitalWrite(8, LOW);
delayMicroseconds(2);
digitalWrite(8, HIGH);
delayMicroseconds(10);
digitalWrite(8, LOW);
duration = pulseIn(9, HIGH);
distance = (duration*.0343)/2;
sprintf(buf, "%d: %d\n", i, distance);
Serial.print(buf);
if (p > 0 && p < 20 && distance > 0 && distance > 50) {
Serial.print("triggered\n");
servo.write(0);
delay(1000);
servo.write(180);
}
p = distance;
delay(100);
i++;
}The trickiest part was mounting the servo. I just used a lot of superglue.

For power, I used one of these modules that allowed me connect a 9V battery:

See the video to see the whole rig in action:
Log in to comment.
No comments yet. Be the first!