As the title suggests, I’ve rolled up my sleeves and created a way to flush a toilet and integrate that into my home automation system. The commands work with my Amazon Alexa for ease of use using some custom Arduino code. I also have an Echo Dot mounted in my bathroom.
The original handle on the toilet works as normal. The servo is mounted in a custom 3D printed case that fits above the flapper and around the overflow valve. The servo wires are connected to the NodeMCU that is in a custom 3D printed case that hangs on the side of the toilet. The whole system is powered through a single cable either using a power bank or standard usb-b phone charger.
Device In Action
Component List
-Access to 3D printer
-NodeMCU
-MG996R Digital Torque Metal Gear Servo
-Chain for servo to flapper
-Power (battery bank or phone charger)
-Usb-b cable
Connect the red wire to the 3.3v connector on the NodeMCU. Connect the black/brown wire to GROUND. The yellow/orange cable should be connected to D1 on the NodeMCU.
I installed the servo motor to the mount that goes on the overflow valve with two screws on each side. The chain is mounted from the last hole on the servo arm to the flapper. There should be a little play in the flapper chain. Wash your hands!!!! It is a toilet.
The original handle can be left installed. You could also replace the normal flush handle with an electric push button.
Program NodeMCU
Below is the code that I am currently using for this project. The code is horrible and I am working on better code to replace it. You can download this garbage and use it if you want. It works but it is not up to my standard. Feel free to email me or contribute in this section.
This is a little project that I worked on that involves using servos in a 2 axis setup. This is a really cheap project that outlines some of the great things that you can do with a few servo motors. This setup can be used to swivel a small camera on 2 axis. We used it to create a Lego tilt-a-whirl.
Materials
Computer (to upload Arduino code)
Arduino or Arduino compatible device (between $2 and $20 depending on the device you purchase)
2x SG90 Servo motors. ($1 each on eBay)
2-Axis SG90 Gimbal Bracket for SG90 servos (pic below) ($1.80 on eBay)
Male to Male jumper wires ($1.50 on eBay for 40 pack)
Wiring
The red wires for both servos will connect to the 3.3v pin on the Arduino. The brown/black wires for both servos will connect to ground on the Arduino. The orange wire for the bottom servo will connect to pin 9. The orange wire for servo the top servo will connect to pin 10. The Arduino will get power from the USB port from either your computer or from an optional USB battery bank.
Code
I will build a few variants that you can use to upload and test. You can use these an example to get you started working with this setup for your own projects. These servos typically rotate 180 degrees and you will see these positions used in the code to point the servo where we need them.
Project 1 – Swivel/Tilt
I attached a little Lego man at the top so that you can see the tilt from the second servo motor. The top motor tilts at 45 degrees and the bottom motor does a 180 degree swivel before both return home. Video and code below.
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
void setup() {
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo1.write(0); //moves bottom servo to position 0
myservo2.write(0); //moves top servo to position 0
delay(800); //Delays were added to give the motors time to complete the action
myservo1.write(180); //turns bottom servo 180 degrees
myservo2.write(45); //turns top servo 45 degrees to tilt down
delay(800);
myservo1.write(0); //moves bottom servo back to position 0
myservo2.write(0); //moves top servo back to postion 0
delay(800);
}
Project 2 – Randomized Motor Position
I use similar code as above but I changed it so that servo positions were picked at random. I set the bottom servo to 180 degrees and I limited the top servo to 90 because the Lego man would not survive otherwise.
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
void setup() {
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo1.write(random(0,180)); //Randomly moves the bottom servo up to 180 degrees
myservo2.write(random(0,90)); //Randomly moves the top servo up to 90 degrees.
delay(800);
}
Project 3 – Crazy Randomizer
This code is similar to project #2. I turned the delay down and limited the positions. Chaos ensues for Lego Man.
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
void setup() {
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo1.write(random(45,180));
myservo2.write(random(0,80));
delay(75);
}
Project 4 – Pencil Precision
I removed Lego man and added a pencil so you can see the full range and motion with attached devices. You can use loops and other forms of control to create slashing movements or slowly pan one position at a time.
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
void setup() {
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo1.write(0);
myservo2.write(0);
delay(750);
myservo1.write(180);
myservo2.write(180);
delay(750);
myservo1.write(0);
myservo2.write(0);
delay(750);
myservo2.write(180);
delay(800);
myservo2.write(0);
delay(800);
myservo1.write(90);
myservo2.write(90);
delay(800);
myservo1.write(180);
delay(800);
myservo2.write(45);
delay(800);
myservo2.write(135);
delay(800);
myservo2.write(0);
delay(800);
}
Arduino is a company that produces open source hardware and software used to control micro controllers. Most of the Arduino, or Arduino-like, hardware you find will use one of the various Amtel Atmega and Attiny microchips. These chips vary in size, shape, number of pins, flash memory, cost, PWM (pulse width modulation) channels, timers and more. The software is a mixture of C and C++ programming languages.
Arduino boards are typically used for simple, repetitive tasks. Keep in mind these are not full blown computers. Typically, you would select the hardware you would like to use (lights, servos, led displays, temperature sensor, valves, etc) and program how you want the micro controller to handle the input and output.
Arduino has reduced the learning curve and added error correction with programming microchips for prototyping your projects.
Raspberry Pi vs Arduino
I’ve heard the argument that a Raspberry Pi is better than Arduino because it is basically a small ARM based Linux computer with input and output pins. I disagree with this completely. The Pi has it’s purpose but it can be outdone by the Arduino in many cases because you can purchase and use ONLY the components you need. A great example is that you would like to build a solar platform to follow the sun. All that would be needed is a cheap Arduino board, some servos and a photo-resistor. It will use less power, provide better reliability and be more cost effective.
The Raspberry Pi is a small computer that comes with video, audio and USB input/output. Arduino is only use one main component, the micro-controller. The Raspberry Pi uses 200-700 mA under different uses while the Arduino only uses a few millamperes. I’ve found projects on the internet that use only the Atmega chipped programmed using Arduino software that can run for years on a single battery.
Device Types
There are many different types of devices that can be programmed by Arduino. The list of devices that can be programmed with Arduino is longer than the Wiki found here.
Arduino Uno
The most popular board is the official Arduino Uno and it is currenlty listed for $22 at the Arduino store. I recommend starting with this board as it is the most capable to test and learn with. As you learn, I recommend keeping this board available so you can test and purchase a specific board that will meet your project’s needs. There are a ton of pins that can be used for both input and output. The ~ beside the pin number indicates that it is PWM capable (typically used for servos).
https://store.arduino.cc/usa/arduino-uno-rev3
NodeMCU
The next board is a Chinese variant know as the NodeMCU. This board can be purchased for as little as $3 and is half the size of an Uno and is Wi-Fi capable out of the box. I was able to host a webpage from this device and connect an LED that could be controlled remotely. You could connect a relay and use it to power devices on and off.
Digispark
The Digispark is uses the ATtiny microchip and is roughly the size of a quarter. The Digispark pro actually has built in Wi-Fi. Chinese variants can be found for as little as $2 online. You will have limited inputs/outputs and the programs that you upload will be limited in size but the advantage is clear. These are a no-brainier for small compact projects that only require a few pins.
ATtiny85
It is possible to build your own board and program the ATtiny85 in a stand alone project using an Arduino Uno. I actually programmed one of these chips to control a MAX7219 Led display kit that I bought on eBay for $1.50 shipped. See the video below if you’re interested.