Automated Toilet Lid Opener

by sarahman1 in Circuits > Arduino

283 Views, 0 Favorites, 0 Comments

Automated Toilet Lid Opener

E0cYXldVEAEVsGI.jpg

I turn on light and toilet lid open. I turn it off, and toilet lid close.

Supplies

61JAjYzklDL._SX466_.jpg
61Evn9b4D3L._AC_SX425_.jpg
download.jpeg
download (1).jpeg
download (2).jpeg
AD179-2.jpg
download (3).jpeg
download (6).jpeg
download (5).jpeg
download (4).jpeg
images.jpg
31zHzfNPTzL._AC_.jpg

The motor and power supply are more flexible only requirements are 12 V for both and for the motor specifically buy a 1 DC so it's strong enough to lift the toilet lid.

List: Motor, Arduino UNO, Breadboard, L298N, 12 V Power Supply, 3 Female to Male wires, 3 Male to male wires, 1 photoresistor, 1 resistor, 6-7 stranded wires, 1 wire cutter, and 1 wire stripper, cardboard, 1 USB 2.0 Cable Type A/B (GET A LONG CABLE), 1 hot glue gun, 1 hot glue stick, 1 command strip package, 1 scissor, 1 roll of masking tape, 1 spool of string, and 1 roll of duct tape (image for hot glue gun and glue stick, normal cardboard, command strip, masking tape, scissors, spool of string and duct tape aren't provided but still buy them).

ALSO GET THICK CORRUGATED CARDBOARD AS WELL BESIDES THE NORMAL ONE!!!!!!!!!!!!

Setup!

unnamed (1).jpg

Before following the diagram, make sure you strip the stranded wires and cut them accordingly to match the length you want. Then follow the diagram accordingly. Afterwards plug the power into the arduino

On a side note, if the male to male wire doesn't feel securely in place in ENA, you can use stranded wire instead.

Also for the ports that have screws on the top, once you have your stranded wire inserted, for example the OUTPUT 1 port, you will want to tighten that screw so that the wires stay secure.

Code

For this step, you'll want to download Ardunio IDE I am using version 2.0.3

-For the code it'll be at the bottom of this step-

(WARNING: DO NOT USE CABLE TO UPLOAD AND POWER CABLE AT THE SAME TIME, ONE OR THE OTHER! YOUR ARDUINO WILL GET BRICKED AND BE PERMANENTLY DAMAGED!!!!!!!!!!!!!!!!!!!!!!)

After successfully installing, measure how far you can lift your toilet lid before it stops falling down and starts staying in place. The reason we want to do this is because this is the maximum height the toilet lid should be lifted by the motor, and if we go further than this point, the motor can't be able to close the toilet lid. (You can try and see why that's the case.)

Test the code by seeing if the motor moves and stops after 5 seconds and rotates in opposite directions when the lights are on and off. Also keep in mind when looking at the motor when the lights are on you'll want the rotor to spin away from you and towards you when the lights are off. REMEMBER WHEN YOU INSTALL THE MOTOR TO MAKE IT SO THAT IT'LL SPIN AWAY FROM YOU WHEN THE LIGHTS ARE ON AND TOWARDS YOU WHEN THE LIGHTS ARE OFF.

---------------------------------------------------------------------------------------------------------------------------------------------------------------



#include<stdio.h>

#include <stdlib.h> //for system()

unsigned long startMillis; //some global variables available anywhere in the program

unsigned long currentMillis;

const unsigned long period = 5000; /* 5 seconds */

int led = 13;

int In1 = 7;

int In2 = 8;

int ENA = 5;

int Mspeed = 210;

int prevanalogValue;

void setup()

{

  prevanalogValue = 0;

  pinMode(In1, OUTPUT);

  pinMode(In2, OUTPUT);

  pinMode(ENA, OUTPUT);

  analogWrite(ENA, Mspeed);

  startMillis = millis();

  pinMode(led, OUTPUT);

  Serial.begin(9600);

}

void loop()

{   

  currentMillis = millis();

  int analogValue = analogRead(A1);

  Serial.println(currentMillis - startMillis);

  Serial.println(analogValue);

  if(analogValue > 20 && prevanalogValue < 20)

  {

   digitalWrite(In2, LOW);

   digitalWrite(led, HIGH);

   digitalWrite(In1, HIGH);

   if(currentMillis - startMillis >= period) //true until period has elapsed

   {

    prevanalogValue = analogValue;

    startMillis = currentMillis;

   }

    //if so, change the state of the Motor

  }

  if(analogValue < 20 && prevanalogValue > 20)

  {

   digitalWrite(In1, LOW);

   digitalWrite(led, HIGH);

   digitalWrite(In2, HIGH);

   if(currentMillis - startMillis >= period)

   {

    prevanalogValue = analogValue;

    startMillis = currentMillis;

   }

  }

  if(currentMillis - startMillis >= period)

   {

    digitalWrite(led, LOW);

    digitalWrite(In1, LOW);

    digitalWrite(In2, LOW);

   }

  delay(50);

}

Installation

IMG_4166.jpg
toilet lid opener

After having everything setup, you want to cut out a piece of cardboard, (size doesn't matter just make sure to comfortable can have enough surface area for all components). Duct tape the motor to the cardboard and connect the other components with masking tape. (The way you do this isn't strict do it however you want but just test it to make sure it's secure) afterwards, put a command strip on the cardboard and make sure the power cord is able to reach an outlet you want to make it so that the rotor is aligned with the toilet lid's center as the picture, then place the cardboard piece with the command strip on the wall.

In the end, stick the string on the rotor with tape and then extend the spool of string to reach EXACTLY to the toilet lid when it's closed, and make sure it's secure and also to the toilet lid. For most motors. you'd want to glue a circular piece of cardboard at the end of the rotor taped down after putting the string so that the string stays on. The picture is the end result you should see except for the last part about the circular piece of cardboard.

After successfully installing, measure how far you can lift your toilet lid before it stops falling down and starts staying in place. The reason we want to do this is because this is the maximum height the toilet lid should be lifted by the motor, and if we go further than this point, the motor can't be able to close the toilet lid. (You can try and see why that's the case.)


You can adjust how far and how fast the toilet lid gets opened with the coding so don't worry about it.

Calibrating

There are two values you'll be changing through the course of this project: period and Mspeed.

period in the code is simply the amount of time you want to pass before your motor stops. Think of it like a timer where if period is 5000 the timer goes off at 5 seconds and the motor holds in place afterwards. The timer is restarted if you switch the lights (goes back to 0 every time the lights are turned on or off.)

Mspeed is another variable you can change which, as in the name, changes how fast the motor spins.


You can change these accordingly to make the toilet lid faster or lift for a shorter or longer time to your preference! I recommend changing it from the settings in the current code.

Oh and One More Thing!

unnamed.jpg

Cut a square of cardboard the same one you put the motor on and cut two pieces of thick corrugated cardboard with a length and width of 4 inches with a height is the distance from the middle of the toilet lid to the base of the toilet, the distance is from earlier in step 3.

After successfully installing, measure how far you can lift your toilet lid before it stops falling down and starts staying in place. The reason we want to do this is because this is the maximum height the toilet lid should be lifted by the motor, and if we go further than this point, the motor can't be able to close the toilet lid. (You can try and see why that's the case.)"

Afterwards tape the two thick cardboard pieces together and then glue them to the cardboard base and connect the whole apparatus via command strip onto the toilet so it looks like the diagram in this step.