Introduction: IR Controlled Locking Mechanism
This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)
This instructable will show images and discuss the steps necessary to creating an infrared (IR) controlled locking mechanism. Please note, this will not replace your current locking mechanism. This is a replica and simulates a door locking.You will notice that the entire system fits inside of this box that I have 3-D printed. I took the instructions given to us literally and thought that everything had to fit in this box. To my surprise halfway into the semester, only the wires needed to be placed inside this box. The importance of this design lies not in the hardware but in the software and the capabilities of this software that can be implemented in a real-life alarm/security system!
The module was modeled in Autodesk Inventor and simulated in Inventor Studio. After the simulation was confirmed, the box was 3-D printed in Makerbot Studio. Each subsystem was implemented into/onto the box and connected to ensure proper functionality. Wires can be tapered to the inside of the box to keep it clean. After the box is assembled and the lid is placed on, it is ready for the prototyping phase.
In creating this instructable it is my belief that the person building this design already knows how to create CAD files. Because of this assumption, I am not going to go into step by step instructions for extruding holes, placing objects in holes, or placing objects on surfaces. Similarly I assume the person is familiar with coding at least on a basic level as I was.
***I am an Electrical Engineer at heart so my Mechanical Engineering knowledge is limited to the knowledge I have gained from this class alone. Please excuse my dust if the mechanical aspects of this design are lacking and/or simplistic***
***This is also the first instructable I have ever created***
Step 1: Step 1: Materials and Resources
The first step in this project is to gather the parts listed below and shown above:
- Arduino Uno
- solder-less breadboard
- HCSR04 Ultrasonic Proximity Sensor
- i2C LCD display (a regular LCD screen is capable of producing the same result)
- SG90 9G Servo Motor
- IR controller
- IR receiver
- 20-30 wires (depending on length)
- Female-to-female connectors (if length of wire is not long enough)
- Recommended Items
- Screwdriver and screws
- Nail File
Additionally, you will need these resources:
- 3-D printing capability
- USB A to B cable
- Installed Arduino IDE
The parts listed are the parts that come with my MAKE course kit. Any parts that you find can be more effective should be used. I want to reiterate that this was just a simulation and concept that I came up with and is not meant for practical applications. Due to the limitations, an Arduino Uno is used as shown above. I had more than enough pins available. I used a half sized breadboard and further broke it down so it would fit in the module. I also elected to use an HCSR04 Proximity Sensor. This idea was developed after I created my CAD file so please excuse me for not having it in the image. I had a regular LCD screen in my possession, without i2C connect-ability, and it can/does work. However, the i2C capability allows for fewer connections and fewer wires to be implemented in the module. A servo motor was used to actuate the locking mechanism (a simple servo motor will not work in moving an actual lock). A stepper motor or more durable motor head can be used if you should feel the need to use it. The Arduino IDE can be used to read values from most remote controls. I used the remote control at my disposal. Feel free to use whatever remote works for you. Just know that each value has its own associate hexadecimal and binary value associated with it. As such, in the code, you will need to change the "FFxxxxx" value to the value that is displayed on the serial monitor (more on that later).
Additionally, I recommend using Windows 7 (or later) and Intel core i5 processor (at least) for the Autodesk Inventor part of this project. Also, I would use Windows for the Arduino IDE as Mac OS has been known to cause issues with some users (I have observed this in some other students in my class). Finally, I would recommend using Arduino 1.6.5 IDE or later for coding.
Step 2: Step 2: 3-D Modelling
The box enclosure is 7.5" x 4.5" x 2.5". You can use any size box that you see fit but this size allows for all of the components to fit in. Additionally, the orange cover shown in the third picture has the same length and width but a thickness of about 0.25".
If you are looking for the LCD screen, Arduino, breadboard, or servo motor, or any other parts, visit the GrabCAD website (this is an awesome open-source website that allows you to appropriately use different components that are not inherent to Autodesk Inventor). GrabCAD has the dimensions of the components already defined. All you need to do is import them to your computer.
I have extruded a rectangle for the servo motor to be placed in. Rather than relying on tape or glue, an extruded rectangle or three sided rectangle will work very effectively (as shown here: |_| ).
Pegs are also extruded for the Arduino to fit in. I would again advise using the extrusion tool over simply gluing or taping the Arduino to the shell. NOTE: You may need to elevate the board off of the inside of the shell by about 0.25" because of the soldering of the pins underneath the Arduino. The Arduino size is fairly accurate when importing it from GrabCAD and gives a good idea of the footprint in the box. Putting the Arduino in pegs ensures that it will not go anywhere when being knocked over for example.
Doing this also means that the extrusion for the USB A to B connector will need to be moved as well. The beautiful thing about Autodesk Inventor is the ability to "project geometry". The Arduino "B" connector can be projected onto the shell of the box and then that shape can be extruded. This will leave a nice hole for the connector to be placed in.
You can also use Inventor Studio to create a video of the design and animate certain aspects to rotate or move accordingly. This implementation will give a good idea of how each part can move. NOTE: Autodesk Inventor does not know how you, the designer, want a part to move. Every part can move in 3-D space in Inventor. Whether or not it can physically happen in real life is a different story. You will need to design the lever arm appropriately in Inventor if you wish to get a full idea of the range of motion it will produce.
Step 3: Step 3: 3-D Printing
The only part that needs to be printed is the shell (the grey box in the 3-D model) and the lid (orange lid in the third model). The functionality of the 3-D part is a shell for all of the components. Three sub-systems fit in the box and one fits on the outside (IR sensor).
The 3-D printer I used did not have screw holes that you can print so I had to make my own. This device is a module in and of itself so having the cover on is necessary for the complete design.
When sending off the file to print, make sure it is saved as a .stl file or similar file that the Makerbot can read. After about 24-48 hrs, the box will be completed
This step is easy to mess up and you may put too much faith into the capabilities of the typical, off-the-shelf, Makerbot product. This 3-D printed part was about 0.05-0.1 inches off from the 3-D modeled part in Autodesk Inventor. If you are relying on precision for the enclosure, consider printing holes 0.05-0.1 inches larger than you designed for and make the pegs skinnier by 0.075 inch in diameter and the rectangle larger in length and width by 0.075 inch each. In the ideal case (in the case of the 3-D modeling), you would want the pieces to fit in flush and in the modeling all of the parts will without any corrections. However, a typical 3-D printer will be off from the designed values by a significant (0.05-0.1 inch) margin. If you don't make corrections, no amount of wedging the pieces in will work. I learned this the hard way and advise you to heed my advice or pay the same price I did. It is important to remember that 3-D printing is costly and can take time. Since this is for modeling purposes and for the class I am in, I did not need to choose the most expensive material nor did I wait until the last minute to make the piece necessary to complete this project
We will come back to the assembly after the discussion about the code
Step 4: Step 4: Arduino Code
I will go section by section discussing the major features of the code.Third-party libraries can be imported from GitHub. The LiquidCrystal and IRremote libraries can be found at GitHub. I had to create the library from scratch for the HCSR04 Proximity Sensor (hopefully you can find it attached above). In these libraries, you can find the variables required to send a command or call a function. Each library has a C++ (software for coding) and .h (extension header file). If creating your own libraries, you need to create both of these.
Next I move on to the initialization of the variables. We have several classes from the Servo, IRremote, LiquidCrystal, and HCSR04 libraries and the variables that are declared. I have also defined several of the buttons on the remote control I used. The LiquidCrystal class instantiates an LCD object called "lcd". The LCD address is 0x27 with 16 columns and 2 rows.The HCSR04 Proximity Sensor has two triggers. The "trigger" pin is responsible for sending out a pulse. This pulse either bounces back (echos) or gets dissipated in space. The "echo" pin receives a floating value assigned to pin 8. This trigger takes in the triggered pulse and converts the value into centimeters (per my own designed library). The distances that the proximity sensor receives are defined as floating values. They could have been defined as integer values but I wanted the measurements to be accurate and this means that the values that are read have decimal values (an example would be 6.52 cm).
Moving onto the setup, I initialize the i2C bus on the LCD screen that I am using. I2C essentially cuts down on the number of pins that I have to use on my Arduino. I initialize the backlight on the LCD screen as well. If you wish to view your results on a serial monitor you must use a Serial.begin(baudrate) command to establish how many symbols to read. This starts the communication between the Arduino and the serial monitor. I clear the LCD screen in case there are any erroneous symbols or letters on the screen. I set the cursor to the middle of the first row and welcome the user to the module. It waits one second and the screen is cleared again. The IR receiver is ready to take in values from the IR remote. Similarly, the servo motor is moved to position 0.
Finally, we move onto the main loop. distance1 is declared as the trigger that is sent out and received. This value is read from the proximity senor to the Arduino in centimeters. last_distance does as its name implies. It stores the last distance that is read. More detail will be provided as to the function of these commands later. The if (irrecv.decode(&results)) command is used to map the address for each button press. Each button has its own bit stream associated with it. Because this project is about opening a lock using a specified value, this command needs to be the first loop in the main loop. last_distance > distance1 compares the values that were stored. If the previous distance was greater than the current distance then the screen is cleared as there is nobody at the door. Similarly, if distance1 <= 7 (cm) then the user will be prompted to enter the password. Only one value will work (9). All other values (0-8) will instruct the user to try again. However, for value = 9, the door will unlock and greet the user. Also, there is a nested for loop in this if statement. The nested for loop enables the motor to kick on and simulate unlocking the door. The distance <=7 is here to check if the user is still at the door or if he/she has gone inside or left. If the user is still at the door, the door will remain open. The door will remain open for about 4 seconds to allow the user to go through the door and then it will proceed to close. After the 4 second delay, the servo motor is detached. I do this to prevent excess power from being delivered to the motor when it is not in use. Additionally, I have serial.println() commands to display the results on the serial monitor.
As briefly discussed prior, pressing any other button will not actuate the motor so I had to make sure that any other button didn’t do anything (values 0-8). The LCD screen will prompt the user to try again. If you forgot your password, you can press the EQ button and the LCD screen will prompt you to rate the course. It is a “Reminder” message saying “REMINDER: ON A SCALE OF 0-9, HOW AWESOME IS THIS CLASS?” After this, the screen clears and you can now put in the correct value of 9.
This next command is very important: irrecv.resume(); If you do not put it in here, the receiver will no longer check for another input. This command prevents the loop from locking up after one iteration or button press.
If the distance is greater than 7 cm but less than 10 cm, this symbolizes the user approaching the module or door. You will again be instructed to enter the password.
Closing out the loop, I have a final if statement. If the last distance is greater than the current distance, it means that the user is nowhere to be found. Additionally, I have it checking to make sure that the user isn’t anywhere to be seen by including && distance1 > 12 (cm). This signifies that someone was there and left. The screen is again cleared. There is a nested for loop that says, okay I saw that the door opened, the lock was moved to the unlocked position, and now I will move back to the locked position. The servo motor is attached and the LCD screen tells the person good bye. The motor moves 35 degrees back to the locked position. After the servo motor is done with its task, it is again detached to prevent overdriving the motor and minimizing the power used to power the servo motor. This is the end of the loop and will run continuously.
Step 5: Step 5: Assembly
If the 3-D printed part came out with incorrect dimensions, as is normal for
the printer to do, DO NOT PANIC! (if you have a Dremel, boxcutter, or other power tools on hand). You can use a Dremel to shave down the sides of the insides of the rectangle if the servo motor does not fit properly. If the pegs are too thick, use of a nail filer works to slowly decrease the diameter of the pegs (a box cutter or any other fine blade works as well but you risk personal injury or the peg snapping off). Sandpaper is recommended to have on hand to smooth out any rough edges if you need to make any corrections.
The first image shows the front of the module with the “Please Enter Password” prompt. Here you can see the placement of the subsystems. The LCD snapped nicely into place. The IR sensor needed holes to be drilled for each of the pins to fit through the plastic. The pins are flexible enough to be spread apart. You can bend the senor up to face the user and can tape the back to the front of the box should you please. The proximity sensor holes were handmade using a rather large drill bit. However, you could use a Dremel if you choose. Make sure the holes are spaced apart as accurately as possible. You could potentially damage the proximity sensor if they separate from the circuit board. The image displayed is just a generic image showing what the module does and it doubles as a mask for the deficiencies in the 3-D printing.
Next you will see the inside of the box. Every part has a place. Starting from the top, the wires from the LCD screen and the IR sensor are taped to the top of the lid and twisty-tied together to make the spacing more neat and compact. In the close up image of the servo motor, you will see that I had to hand carve some space for the wires in order for the servo motor to fit properly. Also, you can see that I had to open up the inside of the servo compartment to make sure the motor fit (the hole was originally too small). In this same picture you will see the pegs that are holding the Arduino. These are here to keep the Arduino from falling down and have also been shaved down in diameter as these pegs were also too large for the Arduino holes. Putting pegs is ideal vs. simply taping/gluing the board to the device as you have more flexibility in using the board for other projects.
There is a 3-sided guide for the servo motor arm mechanism to slide on and off of. This may not be needed depending on how big you decide to make the locking mechanism hole. I replicated a locking mechanism with two pieces of cardboard. The first piece that is connecting to the servo motor is attached to the head and small arm (not shown because it is underneath the cardboard). You can use pins or paperclips to secure the extender to the servo motor head. This basically acts as an extension of what is already there. At the end of this piece is a screw (or you could use a wooden stub or something similar). On the other piece of cardboard is a slot for the screw to slide on. The slot is there to push and pull the lock out/in. The lengths of these cardboard pieces were chosen based on the specifics of the hole and the servo motor location. At the bottom of the module there is a breadboard for the HCSR04 Proximity sensor and a power rail for the power and ground for all components (in theory, you do not need a breadboard at all. Once you make the holes for the echo and receiver ultrasonic sensors, you could connect just female-to-female connectors as was done for the LCD screen and the IR sensor. Then all you would need is a power rail. If you do this, you would free up space, though you would still have the same number of wires.
In the next image you will see that I had to shave down the insides of the box enclosure. I did this for all four sides so that the lid will fit on properly. The A-to-B-USB port connector for the computer and Arduino gets attached to the silver rectangle shown and there is a hole for that to fit into as well.
Finally, I have the lid. I had to scrape off the edges (or use a Dremel) to allow for the lid to fit on the back of the box module. There are screw holes on all four corners to allow for the module to be compact.
Most of the steps described here are contingencies for deficiencies in the 3-D printing process. Ideally, you may not need to shave items down in order for them to fit.
You may put in screw holes if you desire. I did to keep everything looking neat. Having wires showing or anything on the inside showing is not desirable for demonstrations so it’s best to keep everything contained. Finally, once the lid is screwed on, you can plug the A-to-B USB cord into the Arduino.
Step 6: Addtional Step: Fritzing Modeling
This step is not necessary in completing the project but is a good starting point for new beginners. Being able to put the connections in the correct spot allows for the completion of the schematic. Should you desire to put the schematic onto the PCB board, you can get a better understanding of how electronics work and the connections that are required to make one. As per the requirements of the class, I needed to create a circuit schematic illustrating how the circuit interacts with the Arduino.
Also attached is a block diagram illustrating how the subsystems interact with one another.
The bulk of this project was coding and getting all of the systems to interact appropriately with one another.
Thank you for your time. I hope this Instructable proved beneficial! Please let me know if you have any questions
We have a be nice policy.
Please be positive and constructive.