Stray Bytes A place for my electronics projects, ideas and ramblings

3Mar/140

Multiple Buttons on One Microcontroller Pin

My LED Bar project uses an Arduino Duo to process button inputs, take analog readings, update the LCD display, and control the LED strips.  That's a lot for a little microcontroller to handle and by the time I had all my features finalized I ran out of pins.  All I needed was one more pin for a button input from the control panel.  There are many ways to solve this problem depending on your project.  However, one of the other buttons was already connected to an analog-to-digital converter (ADC) pin on the Arduino, but only using its digital input functionality.  So I came up with a simple circuit to take both button inputs on this pin:

Button Circuit

The microcontroller pictured above can be any microcontroller, not just an Arduino.  When no buttons are pressed the bottom 10k resistor acts as a pull-down and the microcontroller sees 0V.  When the left button is pressed 5V is fed directly into the microcontroller.  When the right button is pressed it creates a voltage divider and splits the 5V in half, giving 2.5V.  Unfortunately, if both buttons are pressed the top resistor is shorted out and it will look like only the left button is pressed.  So it's a good idea to either pick two buttons that are not likely to be pressed at the same time or put the most important button on the left side.

In your Arduino project, just throw an analogRead() command in your main loop and use the result to determine which button is pressed.  For the example above, the analog reading will be 0 when no buttons are pressed, 512 for the right button, and 1023 for the left button.  These values are very spaced part, which makes for a very reliable circuit.  I used the following ranges in my code to determine which button is pressed:

No buttons pressed: <256
Right button pressed: ≥256 and ≤768
Left button pressed: >768

Analog readings take much longer than a digital input reading, but my project is not time-sensitive and still responds instantly.  In fact, I had to put in a timer scheme similar to debouncing a digital button input to prevent multiple hits on a single button press.  This circuit isn't groundbreaking, but hopefully it helps someone out there if they run out of Arduino pins.

Adding More Buttons
The following circuit expands the first example to 4 buttons.  You can expand even further, but eventually you'll hit a limit where temperature variations and resistor tolerances will cause unreliable readings.

Button Circuit 2

The ADC readings for the above circuit are as follows:
None: 0 (0V)
Button #1: 255 (1.25V)
Button #2: 511 (2.5V)
Button #3: 769 (3.76V)
Button #4: 1023 (5V)

Simultaneous Button Presses
The following circuit expands the first example to add the ability to detect when both buttons are being pressed.  The tradeoff is that the ADC values are closer together, but this shouldn't cause problems.

Button Circuit 3

The ADC readings for the above circuit are as follows:
None: 0 (0V)
Left Button: 393 (1.92V)
Right Button: 511 (2.5V)
Both Buttons: 633 (3.1V)

Wrap-Up
As you can see, there are many ways to hook up multiple buttons to a single ADC pin.  There are many other methods as well.  For instance, you could use the internal pull-up resistor instead of the 10k pull-down resistor I used in my examples.  The resistors could also be in series for each button so that different buttons engage different numbers of resistors, creating the effect of adding resistance.  Experiment and search around online to find the best solution for your project.

Share
26Feb/140

LED Bar Videos

Now that the LED Bar is installed and fully functional you can see it in action.  These videos show off a few of the LED Bar effects.  The first video shows the random shot routine.  You just press the red random shot button and a crazy light show starts until a shelf and color are selected.  This color matches colored wristbands on each of the bottles.  Once it stops you take that shot.

 

This video shows the sliders in action.  There is a red, green, and blue slider.  Each one mixes in that color so that any color can be created on the bar LEDs.  The demo just shows the panel, but the lights shine off the wall in the background.

 

This last video shows the flow effect.  The colors change randomly and mix in to the next one.  Sync is turned off for this video so the two shelves are different colors.

Share
Tagged as: , , No Comments
7Feb/140

LED Bar Installation

I performed a lot of testing and couldn't get individual RGB LEDs to light up different colored alcohol bottles the way I wanted.  So I found some LED strips from Sparkfun and toyed around with them instead.  This was much easier than installing individual LEDs into the actual shelves.  The LEDs cannot be controlled individually on the strips, but it reduces complexity because I can use Arduino PWM outputs with external MOSFETs to drive them.  The top and bottom shelves are independent so I can at least make those different colors.

After I built and tested the new LED bar design on my workbench, I moved everything down to my basement bar.  It was a mess of wires just waiting for a spilled drink to destroy it, but it still worked exactly as I had envisioned.  Then I threw a party and realized just how much fun an interactive bar can really be.  By 'fun', I mean it's basically a hangover inducing robot.  The random shot button was a huge hit and everyone tried it several times throughout the night.

After that I started on the actual installation to make everything more professional looking.  I stuck the LED strips to the bar shelves using the built in adhesive strips.  Then I installed the control panel on a wall above my sink.  On the other side of this wall is a small, unfinished room with my furnace and water heater.  This made it very easy to cut out a piece of drywall and mount the panel with relatively easy access behind it.  I then mounted the PC power supply and electronics on a stud in the utility closet.  There's an outlet in the room which makes it easy to power.

LED Strip LocationBehind Panel

There are several display modes that can be selected using the control panel:
Flow: Randomly changes between different colors by color mixing to the next one.  The two bar shelves can sync together and show the same color or change independently.
Pulse: Randomly changes between different colors by fading to black before the next one.  The two bar shelves can sync together and show the same color or change independently.
Static: Displays a single color.  There are several preset colors to choose from or the color sliders can be used to mix a custom color.
Strobe: Strobe light effect using a single color.  There are several preset colors to choose from or the color sliders can be used to mix a custom color.
Random: Changes between different display modes.  The strobe effect can be turned on or off in the rotation.

LED PanelPurple Lighting

You can also press the random shot button at any time to interrupt the current light show and start the random shot selector routine.  This will start a red, yellow, green countdown display for the entire bar (similar to a stop light).  Then the lights will start rapidly switching between random colors.  They switch very fast at first and then gradually slow down.  After a set period of time one of the shelves will turn off completely.  Then the lights on the remaining shelf will eventually stop on a color.  That color will match one of several colored wristbands placed on the alcohol bottles.  Each shelf has 7 different wristbands that can be placed on any of the bottles on that shelf.  This adds to the fun because the person taking the shot has a little influence on their destiny by where they stick the wristbands.  Certain alcohols can be heavily favored and others can be avoided completely.

Color BandsPanel Text

I'll upload a few videos of the LED Bar in a future post.

Share
Tagged as: , , No Comments
27Jan/140

370Z Upgrades Part 2

I swapped out my head unit last summer.  Since then I've been unimpressed with the stock speakers and their lackluster bass.  So I thought it would be nice to drop in a little 8" sub to give it a little kick.  The problem is that I didn't want a sub box sitting in the back of my car.  I looked around and custom enclosures for the Z are pretty expensive.  Plus, there are only a couple out there and none of them are that great in my opinion.  I searched the 370Z forums and found an example of a sub enclosure that fits inside the spare tire.  This makes it look stock at first glance and saves already limited trunk space.

The box is made out of various thicknesses of MDF.  All pieces are circular and the sides are actually rings that build up the walls of the box.  The speaker terminals are located on the bottom so that the speaker wires can feed up through the wheel spokes.  The bottom of the box has a hole for the spare tire mounting stud to hold the tire and enclosure down tight.  Unfortunately, this means I'll have to take out the speaker and then the box in order to use my spare tire, but hopefully I won't ever have to do that.  Luckily, Nissan provides a screwdriver in the trunk that I can use to remove all of this.  Each piece of MDF is glued to the next using Liquid Nails.  There are screws coming in from the bottom and the top to keep everything tight.  All of the internal seams are also sealed using silicon caulk.

Box WallsSub Box

I chose the Pioneer TS-SW841D subwoofer because it has a mounting depth of only 2.5".  The box I created has a depth of only 3.5", so this was a key factor in choosing a speaker.  The spare tire mounting stud will also be inside the box under the sub.  So the actual available depth is just under 3".  I chose the Kicker DX250.1 amplifier to power the sub.  It's a relatively small amp that can fit behind the seats and in front of the rear strut bar.  This will make it completely hidden from view once installed.  I also put in some sound dampening mat anywhere I could fit it while I had the interior torn apart.  The Nismo suspension makes for a rough and noisy ride so I wanted to knock that down as much as possible since I had the chance.

Speaker WiringDynamat
AmplifierFinished Sub

Another issue I wanted to address is that parallel parking or driving in reverse at all with 15% tint is next to impossible at night.  Especially with the already poor visibility of the Z.  My head unit supports a backup camera input so I installed one while I had my car torn apart.  I purchased this camera from eBay.  It was only about $13.  It has a 170 degree viewing angle, shows distance markers on the picture, and has a very small form factor.  I brought accessory power to it from the back of my head unit since I already had to run the video cable there.  The reverse light signal can be found in an orange wire running horizontal across the very back of the car.  There are several wires with the same color in that bundle, so a little trial and error was necessary.  I mounted the camera next to the license plate light recessed as much as possible to make it less visible.

Backup Camera

Share
Tagged as: , , , No Comments
18Sep/130

SUFO-2 Flight Recap

SUFO-2 successfully completed its flight to near space and back on 9/14/2013 and broke my goal altitude of 100,000 ft.  Here’s a recap of the flight and some interesting stats.

Launch Date September 14, 2013
Launch Time 12:47:09 CDT
Launch Point 39.244444, -92.228056 (View on Google Maps)
Landing Time 02:28:13 CDT
Landing Point 39.112500, -92.106111 (View on Google Maps)
Distance Traveled 11.2 miles
Flight Duration 1 hour 41 minutes 4 seconds
Payload weight 3.23 lbs
Balloon lift 3 lbs of free lift (1400 fpm average ascent rate)
Highest Altitude 101,233 feet (19.17 miles)
Maximum Velocity 143.2 mph
Pictures 655 total (511 during flight)
Video 1:29:21 total @ 720p (1:03:31 during flight)
Sensors Temperature, Absolute Pressure, Relative Humidity, 3-Axis Acceleration
Sensor Readings 82,784 total (42,040 during flight)
GPS Readings 11,990 total (6,065 during flight)
Furthest Antenna Reached NX0P in Glenville, Minnesota (382 miles)

Trajectory

View the full flight trajectory on Google Earth: SUFO-1 Trajectory.kmz

SUFO-2 Flat Track

SUFO-2 Side Track

Flight Recap

This flight was very similar to SUFO-1.  The only differences for this launch are a new cutdown module, a video camera, a heavier balloon, and hydrogen gas used for lift.  Hydrogen introduced new risks when filling and handling the balloon, but we took our time, filled the balloon in an open area outside, and made sure to reduce static electricity as much as possible.  I used the Cambridge University Spaceflight Landing Predictor to select a launch location.  Around 11am the chase crew headed up to the launch location, setup the capsule, filled the balloon, and prepared for launch.  The balloon lifted off around 12:50pm.  The predicted flight path is shown below.  As you can see, it is very similar to the actual flight path, except that the balloon was overfilled slightly and the balloon rose quicker than expected.

SUFO-2 Prediction

We learned from the last launch and only used cellphones to track the balloon while in the car.  We had the APRS.fi website up and could track the balloon that way.  Once the capsule came back down under 8000 feet that stopped working (as expected).  At that point we drove as close as we could, got out of the car, and started walking to the last known location.  My laptop was then used to get a direct signal from the capsule.  Once we got pretty close the laptop picked up the signal and we were able to walk right to it.  The whole area was surrounded by corn fields, but luckily it landed in a bean field so it was easier to walk through.

The first thing we noticed was that the balloon was still attached.  The last balloon did the same thing because a wire broke loose and the cutdown module couldn't operate.  This time I found that I forgot to plug in the 9V battery that powers the cutdown module.  Idiot!  Oh well.  The capsule wasn't damaged so I can't be too upset.  I reviewed the logs and it looks like the software worked correctly, but with no power the cutdown couldn't happen.  Maybe next time I'll get it right.

Overall this was another successful high altitude balloon launch.  I still didn't get the cutdown to work right, but we did learn from last time and selected a better landing location.  This made it very easy to to find.  Thanks again to my chase crew!

Pictures

Here are some pictures from the flight.  View my flickr set for more pictures.

SUFO-2 Prelaunch

Hamming it up for the camera

SUFO-2 Just Before Launch

Just before letting go

SUFO-2 - 17,000 feet

Not too high yet - 17,000 ft.

SUFO-2 - 46,000 feet

View of Columbia - 46,000 ft.

SUFO-2 - 69,000 feet

View of Fulton and Jefferson City - 69,000 ft.

SUFO-2 - 82,000 feet

Sky is dark now - 82,000 ft.

SUFO-2 - 97,000 feet

Higher than SUFO-1 - 97,000 ft.

SUFO-2 - 100,000 feet

Almost to the highest point - 100,000 feet

SUFO-2 - 101,000 feet

View from the top - 101,000 ft.

SUFO-2 Landing

SUFO-2 landing in a bean field

 

Data

Raw data log from capsule:  SUFO-2 Raw Data Log.zip

Flight Analysis (data & graphs):  SUFO-2 Flight Analysis.zip

Google Earth flight trajectory:  SUFO-2 Trajectory.kmz

Launch, flight & recovery pictures:  SUFO-2 flickr sets

SUFO-2 - Altitude vs. TimeSUFO-2 - Temperature vs. Time

SUFO-2 - Pressure vs. TimeSUFO-2 - Ascent Rate vs. Altitude

SUFO-2 - Humidity vs. Time

Feel free to post any comments or questions about the flight.  I'd be happy to share anything you feel I missed.

Share
Page 1 of 612345...Last »