Skip to main content
cover image · 1280×720
Blog Post

Arduino Toilet Flusher

I use an ultra-sound module & a servo to flush the toilet

JE
jeremybobbin
@jeremybobbin·Apr 24, 2026· 1 min read·arduino
5 views
Arduino Toilet Flusher

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:

c
#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.

servo

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

rig

See the video to see the whole rig in action:

YouTube
JE
Written by
jeremybobbin
@jeremybobbin
Related Posts

Comments

No comments yet. Be the first!