Wednesday, February 13, 2013

Power consumption of Arduino

While the Arduino doesn't draw much power, the consumption does go up (significantly) if you throw a 7805 voltage regulator in the mix. Just because you don't actually see stuff happening, doesn't mean that the processor isn't at work. Even at full rest, an Atmel ATMega 328 powered through a 7805, does draw current. As my lights and sirens project demonstrates: one night of letting the box sit around without turning the main power switch off pretty much drained a 9V. Especially when the circuit is a toy for a 3-year old, it is hard to expect him to turn the thing off every time.

In order to address that, I updated my circuit a bit. After doing some searching, it was clear that the standby mode of the Arduino processor isn't good enough; it still draws power because of the voltage regulator. In order to address that, I came up with the following solution:

The 9V battery powers the voltage regulator in one of two ways. When the momentary push button is pushed, the circuit is closed and power is applied. That power will then initialize the processor, which in turn will set a pin to 5V. Setting the pin to 5V will engage the relay, which at that point closes the circuit for the 9V <-> 5V battery also. The momentary button can be released, since the relay is still active.

After some period of no activity, the processor can simply drop the pin to which the relay is connected to low, the relay disengages, and the circuit is broken, which cuts power to the voltage regulator, and as a result to the microprocessor.

As far as I can see now, the only drawback of this design is that the relay also draws a current. The model that I chose clocks in at around 24mA, which compares it to an LED. I could have countered that with a relay that latches, but those were too pricey for me.

All in all-- a solution that appears to work. And, with a timeout set to 2.5 minutes, hopefully less frequent battery replacements.

Friday, February 8, 2013

Arduino Lights and Sirens Final Product

I finished the final version of my Arduino Lights and Sirens project last night. I'll write up the software and the final build post later on, but I figured that I would at least share the results here.

The completed project box looks like this:

When it is actually running, you get the effect as shown below:

More details about the write-up at a later time.

Tuesday, January 29, 2013

Arduino Lights and Siren Prototype

The first step of building the Arduino Lights and Sirens is breadboarding a prototype. With all the components known, that is a fairly straightforward exercise, as shown below. Four LEDs connect via 220 Ohm current-limiting resistors to pins 2,3,6,7, leaving pin 4 and 5 for future expansion. Pins 8, 10, 11 and 12 are for the four momentary switches. Each switch is typically pulled to ground via a 10k Ohm resistor when it isn't pushed, and goes straight to +5V when pushed.

The speaker goes to pin 9. The schematic looks like this.

Note that the speaker cannot be on pin 8, since that is not a PWM port, and the tone() function will fail on that pin.

The beauty of the Arduino platform reveals itself here; you don't have to worry at all about power supplies, capacitors to get rid of AC, crystals to provide a reference clock, etc. All of that stuff will come when we move from breadboard to production board. For now, it is all provided by the Arduino board itself.

When the breadboard prototype is actually built. it doesn't look as clean as in the picture above, but everything does work very well.

Pictured above are only two of the four momentary buttons; the other two switches are just out of sight, as is the Arduino itself. The speaker at in the center has been rescued from an old speaker phone.

This is really all the hardware we will need for this project. Next, we'll discuss the software.

Arduino Lights and Sirens

I have recently set out to work on my next project; this time it is based on the popular Arduino Uno microcontroller. The life of my son, who is 3 years old, revolves around fire trucks, sirens and flashing lights. So, I figured that I'd build the ultimate light-and-siren assembly.

My vision is to build a box that has a bunch of colored LEDs to emulate the light bar of an emergency vehicle, and a little speaker in the box that can be used as a siren. The heart of the assembly will be an Atmel ATMega 328p microcontroller.

As far as control goes, I'm looking for a few switches and push buttons:

1. A master on/off switch to cut power to the microcontroller
2. A toggle switch to determine if the LEDs are on
3. A momentary push switch to operate an "air horn"
4. A momentary push switch to operate the siren
5. A momentary push switch to change the pattern in which the LEDs flash
6. A momentary push switch to change the pattern of the siren

I also want to have a parental control that I can use to turn the siren assembly completely on or off, regardless of what buttons are pushed. Most likely, that's going to be done via pushing a secret combination of buttons at start-up. Note that I'm using the momentary push button to turn the siren on, rather than a toggle switch.

Once the box has been prototyped, I'll move to a more permanent board; although the Uno's are cheap enough, I'd rather spend $3 on a replacement microcontroller than $20 to replace the Arduino. That will require a few extra components, but nothing fancy. The final project will be powered by a 9V block battery.

The first order of business will be to bread-board the hardware components. It should be fairly straightforward: each LED will have a resistor to limit the current to 20mA (the 328 is rated at 35 mA, so 20mA seems fair); the siren is going to be a 0.25 W speaker with an impedance of 25 Ohm that was salvaged from an old speaker phone. The push buttons will have a 10k resistor to pull them to ground when open.

The second order of business will be the software; I would like this thing to be extensible and usable by others, so decent code is going to be a requirement.

Thursday, January 10, 2013

14 Raspberry Pi's on a single board with custom power supply

Having mounted all power boards, it comes time to turn attention on the power distribution box. It turns out that this was by far the easiest element in the entire build. First off; all power boards have a black/red 18 gauge speaker wire (Radioshack 278-567) soldered directly to the board (red for +5 V, black for ground). The other end of the cable was terminated in ring connectors (Radioshack 64-3120). All the ring connectors were gathered on a bolt and a nut was added to keep everything tightly together.


To make the power distribution box, I got a project enclosure box (Radioshack: 270-1803) with a little bit of perforated board cut to size. After drilling some holes in the perf board to hold the leads, and a little notch in the top of the board to allow the fuse line to go through, it is a matter of connecting everything together.

Note that the holes on the perf boards are pretty much as far apart as I could make them. it is going to be quite crowded in the box, and you don't want +5V and ground lines touching each other. By spacing them this way, they have plenty of space. Note that you also want to keep some space from the side to allow for mounting in the box.

On the right-hand side of the power box, we see red and black coming in from the power supply. For this, I used installation wire. On the left-hand side, we see the power go out to the power boards. The lid of the power box has a switch and a fuse. The switch doesn't really serve much of a purpose if your power supply also has one, but since I was building anyway, I figured that I might as well add one. Next to the switch is a 10A fuse.

That same assembly is show above. The red line coming in from the left is the +5 V power line coming in from the power supply. It goes into the fuse, and from the fuse, connects to the left-hand power lead  of the switch.

Note that this switch has a built-in LED, which doesn't give you an option to play with polarity. On the left, you must connect incoming power. The second terminal must connect to the switched power (Acc) and the right-most terminal connects to ground. While in some cases, you may choose to omit the ground wire, you cannot do that here because of the build-in LED in the switch. From a safety point-of-view, having the ground wire is a better plan anyway.

The connectors used here are flexible quick-release terminals. They work very well for stuff like this. Now that everything is in place, the project box can be closed up too.

The final power distribution box looks like shown below.

After mounting the plexiglass sheet on an MDF panel for added rigidity, the power supply and the power distribution panel can be added also. The full assembly looks like shown below when everything is on, and active.

After this, we'll start work on the software.

Tuesday, January 8, 2013

Mounting the power boards

With the individual power boards at completion, it is time to bring line power to them, and to mount them on the main board.

First of all, I learned another lesson: scalability is nice to keep in mind, but don't let it complicate things too much. My master plan was that I would make small power boards that would power up to four Raspberry Pi's each, and that the smaller boards would connect back to one power distribution board. That concept still stands, and I believe it is the right way to go.

However, what I also tried to do was make things convenient. I figured that I would attach one DC power jacks on each of the power boards and one DC power jack for each board on the distribution panel. I would then connect the whole lot together using some power jacks connected to two-conductor cable, and I would be ready to go. I did indeed go so far as to mount the power jacks on the boards, but in the end, I decided to not use them and solder the power feed directly to the smaller board .

At the other end, with the distribution board, I will create some form of scalable something, but most likely it is just going to be ring terminals held together by a nut and bolt. In this case, simplicity wins over elegance.

Since the power boards have a switch on them that protudes a fair distance, I cannot use the same standoffs that I used to mount the Raspberry Pi's. Instead, I chose the slightly longer 0.875" standoffs (Digikey 1859K-ND) instead. Note that unlike the Radioshack standoffs, these don't come with screws. If you don't have them in stock, you'll need to provide your own.

Once mounted on the board, they look pretty good. One word of caution: the standoffs need 8-32 machine screws, which are just too wide to fit in the pre-drilled holes on the circuit board. If you are going to use them, you'll have to widen the holes with a drill before attempting to mount. Failure to do so leads to the bottom-right corner: it snaps the circuit board.

I used a little zip-tie to secure the cable to the standoff of the power board immediately to the right; it provides some tension protection and it will just look nicer.

Mounting the additional boards will then complete that part. Don't connect the power to your Raspberry Pi's yet! You'll want to complete the build-out of your power distribution panel and hook that up to both the outbound feeds to the boards, and the incoming feeds from your power supply first. Then, you'll want to grab your multimeter to check that you have not actually created accidental short-circuits and that you measure power at appropriate levels. Make sure that all toggle switches are in the off positions before you start connecting stuff.

Next: 14 Raspberry Pi's on a single board with custom power supply 

Wednesday, January 2, 2013

Prototype power board to light up four Raspberry Pi's

Building the actually power board was fairly straightforward. I started with a prototype on a simple rectangular grid-style PC board (Radioshack 276-149), which measures roughly 45mm by 70 mm (1 27/32 inch by 2 27/32 inch). It provides ample space for everything that needs to be done. The build was really not much more than positioning the components and attaching everything.

A few pointers:

Begin with drilling the hole for the toggle switch. That way, you won't have any debris gathering in your components.

The USB ports will pre-drilled fit in the holes, but you may have to bend the clamps on the sides out of the way. Make sure you get the  polarity right. Wikipedia has a page on USB connectors that shows you the pin layout. In my build, I am using a vertical double type A connector.

Position the components on the side of the board that does not have the solder rings. All components fit through and can be soldered on the other side.

After positioning the components, carefully bend the end of the leads that stick through to secure the pieces to the board before soldering them. Soldering is a lot easier when the stuff doesn't move around.

Position all components on the board before you start soldering them in place. De-soldering isn't all that easy and it always leaves a little bit of a mess. Get it straight the first time.

Once all the components are soldered in place, wire them up. Since I had it  laying around, I used 24 gauge pre-tinned copper wire (Radioshack 278-1341). Besides, AWG 24 is rated up to 3.5 A for chassis wiring, and with 4 USB ports, I should only draw around 2 A.

The first board, as shown above, does not have the power bus on it yet, but that should be a relatively simple addition. The solder joints aren't perfect, but they seem to do the trick.

After checking the connections for shorts with a multi-meter, the board was hooked up to the main power supply. Using my USB tester cable, I did confirm +5 V over the USB cable. Time to hook up the RPi's!


Adding a little power to the boards, and toggling the switch to the 'On' position, did what I hoped it would. The power LED came on, and my four boards powered up. Putting the multi-meter inline with the power supply proved that I indeed made the right design decision; these four boards pull fairly significant current:

The next step will be to build two more boards, and a distribution panel that connects the power supply to the boards.