This team did a lock based on a dial, much like a gym locker or “Master” lock. They took the Spring 2015 lab 4 in a direction nobody anticipated, and added a servo to open a box when the right combination was dialed in. There’s a lot of great build tips here for putting your project in a beautiful metal case. This team also went off the grid with their OWN WordPress site, here’s the link with a video, code, and more:
The primary objective of this lab was to use a culmination of all that was learned throughout the semester in a cumulative project showcasing the skills and knowledge that we had developed in a project of our own choice and design. The made the primary goal to coherently and practically apply the principles and techniques we had developed over the course of the semester. After brainstorming and debating about the primary function of our project, the team decided to attempt to utilize an LCD screen and an accelerometer to display and move a small dot about the screen in relation to the origin and the movement of said accelerometer, possibly making a simple game out of it. However, due to the relative difficulty of the application and various time constraints, the LCD screen originally intended for the project was substituted with the screen already on the A3BU microcontroller and the accelerometer was substituted with a small joystick with which the dot is moved about the screen. A small button was also integrated into the design with which we were able to use to “shoot” at static targets in the context of a classic video game style. The various pieces of equipment used at some point throughout the course of the project are as follows: the Atmel A3BU microcontroller, a Parallax joystick, and a basic push-button. Despite the few and minor hiccups that we had during the course of the project, the final result is an effective and functioning rendition of our original idea to make a simple and fun game with the help of the A3BU microcontroller and a few select pieces of third-party hardware.
The schematic for Team 4.1’s U-Box seems complicated but is actually fairly straightforward. There is essentially a circuit for the LED and LCD screen, and a second circuit for the servo motor. From the A3BU, 3.3V runs through a 330 Ohm resistor to a red LED and back to ground. A switch completes the loop so that the LED will only light up when the switch is flipped. The other side of the switch runs back to an input pin on the A3BU that just lets the micro-controller know which position the switch is in. This is necessary so that our LCD screen knows when to show the different faces.
Unfortunately, the 3.3V from the A3BU were not enough to power the 5V servo, so a second part of the schematic is designed to run this servo. When the switch is flipped, the A3BU tells an Arduino to run its code, and the Arduino outputs the 5V necessary to turn the servo 35 degrees. The servo will rotate and hit the switch back into the off position, causing the LED to turn back off.
Above is the main schematic we used for our project which helped us figure out what pins corresponded to which row and column as well as how a specific keys location was relayed to the board. The schematic details the conductors associated with each row and each column. The keypad we used for our project has 4 rows and 3 columns for 12 total buttons, but only 7 data pins. To read which button was pressed at any given time, we energized the voltage on each row while checking for a column inputs.
Here is a diagram of how each row and column was wired to the A3BU:
The intent of our final project was to create a keypad lock using a 12-key membrane keyboard and the XMEGA-A3BU board that would trigger a stepper motor to open a mechanical lock. We ran into a problem early on that forced us to change course slightly. The EasyDriver for the stepper motor we were planning on using for our lock did not arrive in time so we decided to go with an alternate driver. This ended poorly for us as the alternate driver caught fire during initial testing, much like our hopes and dreams.
As an alternative, we printed messages to the LCD while also flashing the onboard LEDs to signal that the provided password was correct or incorrect. We also implemented a menu system through which the user can either set or try a password. Passwords can be 10 digits or less, and are hashed upon entry for added security. If the user attempts to try a password before one has been set, an error message is displayed and the user is returned to the main menu.
What you see above is how we went about getting user input from the keypad. We initially set a row high then wait 50ms to ensure the voltage has a chance to ramp up to solid logic levels. We then check to see which column goes high. This tells us which key is pressed by creating a coordinate pair (row, column). We then set the row back low and move on to the next row. This continues until all rows (total of 4) have been set high and then low again.
This could be easily improved by moving the input handler to an interrupt service routine that gets called when changes are detected on the input pins. However, this would also require more time and consideration to pull off without it having adverse effects on the sequential flow of our program.
Since our 5v servo motor needed more juice to run than our A3BU could provide we opted to use an Arduino to power the motor for the arm. Below is the fairly simple code needed to flip the switch on our U-box. An initial position is set, then once the pin state is read high the arm position is moved to flip the switch and then return to its initial position.
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
const int pin = 2;
int pos = 0; // variable to store the servo position
int state = 0;
myservo.attach(9); // attaches the servo on pin 9 to the servo object