Motor Operated Drawer

by argentinamm86 in Circuits > Arduino

1023 Views, 2 Favorites, 0 Comments

Motor Operated Drawer

auto_drawer.jpg

So, this idea came from an instagram post which showed a drawer that opened automatically and then i saw a comment asking for a tutorial, I kinda gave an overview but then someone asked for a github project or equivalent so here we are.

If you build this and see any error please write it in the comments, I don't have all of the supplies for this project so I wasn't able to test if it works properly.

Note: if you just want to make this for fun and don't want to solder anything make sure you buy the supplies but with header pins, those are the ones that you just connect to a wire like a connector, those components may be bigger and a little more expensive than the ones that you have to solder, but are more convenient for absolute beginners.

Supplies

We need:

motors, could be 5v if the drawer doesn't weight much, the heavier the drawer the more powerful motor we need, if the motor uses more than 5v you will also need a relay(I'll explain more)


A soldering iron to make all the connections.

Wire

an Arduino, I recommend the arduino UNO it's the most common model and probably the cheapest.

An ir transmitter and receiver something like this, we don't need 2 of them, except if we want to make it for more than 1 drawer of course.

2 limit switches: https://www.amazon.com/MXRS-Hinge-Momentary-Butto... something like that, but only 2 units.


2 1K ohm resistors.

Step 1: Preparing the Drawers

images.jpg

We will need some kind of gears system to make the drawer open and close something like the image above, the flat part needs to be in the drawer and the gear has to be on the motors, we need 2 strips, one for the motor that opens the drawer and 1 for the one that closes the drawer, they don't have to be metal, that's way too expensive, we can use plastic, i don't have a good idea on how to mount that to the drawer, now that we have this part we can get to the electronics

Step 2: Circuit

auto_drawer.jpg

Basically the circuit is just 2 motor, 2 limit switches, the IR receiver and the arduino, the limit switches are the black things at the left in the protoboard, the wires connected to the 5v are the common pin on the switch, and the one in the middle is the normally open contact(NO), the resistors are between the ground and the NO contact, it acts as a pulldown resistor, it just makes the arduino understand better when the switch isn't pressed.

Then we have the IR receiver, that weird thing to the right, if you buy a premade module, the pins probably have a designated function, like vcc data and gnd, vcc always goes to positive, in this case, 5v, and gnd always to ground, then data pin goes to pin 3 of the arduino.

Lastly, the motors, if you buy them they could come with no wires attached to it, and with no instructions, just don't panic, you won't break it for connecting it backwards, this kind of motors can take current from both sides, imagine you connect 5v to the left pin and gnd to the right pin, the motor turns right, but if you connect 5v to the right pin and gnd to the left pin, it would turn left. That's why we connected one backwards, to make it close the drawer.

Now we get to go to the code part.

If you never touched an arduino or a protoboard or have no experience with electronics I recommend you read this instructables: protoboards, soldering, arduino

Step 3: Calibration Code

I'm supposing that at this point you either know how to program with the arduino IDE and add libraries, or you read the arduino tutorial I linked in the last step.

First we need to install the IRRemote library.

and then we need to "calibrate" our IR sensor, because no receiver is the same the can have different codes for different keys on the remote, we need to figure out the code for the key we want to open the drawer and the one we want to close the drawer, for this we will use the serial monitor, we need to use this code:

#include   //including infrared remote header file
int RECV_PIN = 3; // the pin where you connect the output pin of IR sensor IRrecv irrecv(RECV_PIN); decode_results results; void setup(){ Serial.begin(9600); irrecv.enableIRIn(); } void loop() { if (irrecv.decode(&results))// Returns 0 if no data ready, 1 if data ready. { int readResults = results.value;// Results of decoding are stored in result.value Serial.println(" "); Serial.print("Code: "); Serial.println(results.value); //prints the value a a button press Serial.println(" "); irrecv.resume(); // Restart the ISR state machine and Receive the next value } }

then, we need to decide which key will do what, when you have that figured out, just press the key aiming for the receiver, if the code works, it should output a code on the serial monitor, write that code and the action that button will perform, like "open, 34" we'll need it for later, then, do the same with the other button. Now we have the codes we need, so we have to upload the final code, but, we have to tune some things.

#include <IRremote.h> //including infrared remote header file
int RECV_PIN = 3; // the pin where you connect the output pin of IR sensor
IRrecv irrecv(RECV_PIN);
decode_results results;

int motor1 = 6; //sets the pin where the motor is.
int motor2 = 7;
int btn_open = 5; //this limit switch should be pressed when the drawer is open
int btn_close = 4; //this limit switch should be pressed when the drawer is closed
int btn_open_s = 0;
int btn_close_s = 0;


void setup(){

Serial.begin(9600);
irrecv.enableIRIn();
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(btn_open, INPUT);
pinMode(btn_close, INPUT);
}


void loop() {

btn_open_s = digitalRead(btn_open);
btn_close_s = digitalRead(btn_close);

if (irrecv.decode(&results))// Returns 0 if no data ready, 1 if data ready.
{
int readResults = results.value;// Results of decoding are stored in result.value

irrecv.resume(); // Restart the ISR state machine and Receive the next value
}

if(readResults == 32 && btn_open_s == 0){ //Open results

digitalWrite(motor1, 200); //we tell the motor to open the drawer
digitalWrite(motor2, 0); //we tell the other motor to not do anything
if(btn_open_s == 1){
digitalWrite(motor1, 0);
}
}

if(readResults == 33 && btn_close_s == 0){ //close results

digitalWrite(motor1, 0); //we tell the motor to not do anything the drawer
digitalWrite(motor2, 200); //we tell the other motor to close the drawer
if(btn_close_s == 1){
digitalWrite(motor2, 0);
}
}
delay(100) //adds a little delay so the board works better
}

Okay, so, we need to change the open and close codes I wrote, for the ones you found with the calibration code, there are 2 if statements we need to change, I marked them with the following comments: "close results" and "open, results" you need to put your codes on readResults == code, just erase the 32 and 33 I wrote. And then upload it to the arduino.

Step 4: Done!

That's it. I hope you understood everything and have no problem trying it out.

If you have any suggestions, issues or questions please comment it, I'll try to answer it as soon as I see it.