ECE412 Final – Automatic Toilet Paper Dispenser

Big Picture

In this project we used windows and Arduino and we started out with high hopes and big plans. We began brainstorming ideas for the project and originally planned to use a load sensor or another proximity sensor of some sort to be able to weigh, or ultimately tell when you were out of toilet paper. We decided that a load cell was too hard to incorporate mechanically and even if it was it wouldn’t be accurate enough to sense a few sheets of toilet paper. After we trashed that idea, we decided we would still have a sensor for when it was empty but we would use a interrupt sensor and a series of pullies tied in with the motor to show that the motor was turning but no more toilet paper was coming out. Well this plan also failed due to lack of time and mechanical availability. So we decided to try to perfect the simple action of automated toilet paper dispensing. 

Sample Demo

Schematic

The hardware of this project was mostly recycled from other projects. The Styrofoam casing and motors came from a previous project that was about RC cars using DC motors. Our hardware was fed through the existing and new holes and the board and wiring was all implemented on the opposite side to what the user would see. The motor was wired through a transistor and diode to protect the DC motor in case of feedback. We originally had a 5V power source but the output was too low for the motor to turn with the toilet paper attached. The PWM ports on the Arduino were used to change the power used for the DC motor. The photo infrared sensor acts as a trigger to activate the toilet paper dispenser for 3 seconds.

Code

The code for this project is a mixture of checking for interrupts in the PIR and if there are changes then the toilet paper dispensing is triggered and then resets after it is done. It is very similar code for paper towel dispensers that you would see in almost all public bathrooms. Our PIR was very sensitive so often the it would trigger multiple times in a row, but otherwise the code worked perfectly. There were plans to add a buzzer to the rig as shown in the code, but it never made it to the final product. Everything was coded in Arduino.

Infrared Controlled Wah-Wah – Code Snippet

The programming of the microcontroller was accomplished using Atmel studio 7 on Windows 10.  The goal of converting the analog voltage produced by the Sharp IR sensor to a digital signal was accomplished using the ADC of the microcontroller. The ADC was setup in an ADC initializing function, ADCinit. PC5 was selected as the input for the ADC by setting the MUX0 and MUX2 to 1. The ADCSRA register was set up to enable the ADC, enable auto trigger, enable interrupts and set the prescaler to 64. Global interrupts were enabled in this function using the sei instruction. The output voltage of the sharp IR sensor was found to have a range of 0 to 3 volts depending on the distance. The ADC voltage reference was set to 3.3 volts to more closely match the output of the IR sensor as opposed to the 5 volt default. This was accomplished using AREF as the voltage reference by connecting the 3.3 volt output of the microcontroller to AREF pin with a jumper wire. The LED brightness was controlled with PWM. PWM was set up in the PWMinit function. The clock was set up with no prescaler and using CTC mode. In this mode the OCR1A acts as the top value of the counter while the OCR1B is the value to be compared to. Interrupt service routines were used to change the duty cycle based on the ADC value passed into the duty variable and then by setting OCR1B compare value to duty.  The result of the program was a smooth fluctuation in the brightness of the LED based on the distance of a hand or object from the sensor.

The Wah circuit was combined with the microcontroller by inserting the LED and LDR into a heat-shrink tube in order to have the light passed to the LDR directly related to the LED without outside light interference. The resulting behavior of the LED based on hand position can be observed in the video above.

Catapult – Project Ideas

The goal of performing this project was to encompass learning objectives acquired throughout the duration of this course. We wanted to use a motor to pull back the arm of a catapult and have a solenoid be the release mechanism. The project was successful. When we pressed the appropriate key, the motor would pull back the arm and the solenoid would retract.

Boogie Ball: Code Snippet

The ball’s rotation is done through the implementation of a Timer Compare Interrupt. Each time this interrupt occurs, a global flag is set in the code. The main program loop checks this flag each loop and updates the servo position each time it is set. The flag is then cleared and the loop continues until the interrupt occurs again. A snippet of the code that changes the servo position is shown below along with a video of the spinning.

Continue reading Boogie Ball: Code Snippet

Music Keypad – Code Snippet

One of the most difficult parts of our projects was figuring out how to initialize our keypad and retrieve inputs to the A3BU.  In the code below, we initialize the 4 ADC pins to receive inputs from the 4 buttons on the keypad.  Then we have to set each of the inputs to -1 initially.  The code stated that the light on the microcontroller, LED0, will turn on when button one is pushed via an if statement. We also added a string of code to display on the LCD screen to show what button was pressed. At first, the LCD screen seemed to act a bit intermittent, and after speaking with the professor, a 10k resistor was added. By adding the resistor, we were able to have button one work successfully.  We started to implement button two. We had the issue of something not working properly. Both buttons were wired exactly the same and the code was also identical. After a bit of troubleshooting, the code was changed from  “if (ioport_get_pin_level(COL1) > 0)” to “if (ioport_get_pin_level(COL1) == 1)”. By setting a more definite condition, we were able to clear that issue up. We were able to get button one and two to work successfully. We, then, added button three and four. They were tested and passed with no errors.  When not pressed, the keypad button in question is set to 0: off. When pressed, it is set to 1: on.

Code to initialize our inputs from the numeric keypad. COL1 is for button 1, COL2 for button 2, COL3 for button 3, and COL4 for button 4.

Code to get the input from the keypad back to the board

Once we programmed our A3BU to receive inputs from the keypad, we had to create the desired output.  To create our short jingles, we used pulse width modulation to vary the frequencies and duty cycles.  The desired notes corresponded with a specific frequency, and we chose 85 as the optimum duty cycle to get the clearest tone.  By adding in delays, we were able to control the length of the note and the length of the pauses between the notes.

Code snippet from part of the song “Jingle Bells”

“Jingle Bells”

Anagram Solver Explained and Demo – Team SilverCharm

This is a quick demo of our teams final project. In it you can see a quick run through of the basic functionality we implemented with close ups and reruns. We show our whole board and explain step-by-step what happening, and what’s to be expected.

Continue reading Anagram Solver Explained and Demo – Team SilverCharm

Music Keypad- Big Picture

For our final project, we wanted to incorporate some of the skills we’ve learned in previous labs to create a unique and interactive device.  Using pulse width modulation from Lab 4, we incorporated our AVR XMEGA-A3BU XPLAINED with a 4-input number pad, four 10K ohm resistors, a piezo buzzer and jumper wires to create a musical touch pad that plays different songs based on which button is pressed.  After getting a general understanding of the keypad schematic, we connected the common connection to VCC on the J2 header of the A3BU.  The other 4 buttons were connected to 4 of the ADC pins on the J2 header.  We connected the piezo buzzer to the SDA and GND pins on the J1 header.  After researching the frequency limits of our piezo buzzer, we were able to assign certain frequency values to specific pitches and program the A3BU to play 4 different songs: Twinkle Twinkle Little Star (button 1), Mary Had a Little Lab (button 2), Jingle Bells (button 3), and Ode to Joy (button 4).

General A3BU Setup

“Ode to Joy”