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.

Tuesday, January 1, 2013

Raspberry Pi board power design

Now that we have the Raspberry Pi's mounted on a plexiglass board and a power supply has been obtained that can easily put out the 8 A at 5 V requirement, it is time to give some thought on how to get the power to the board. Whenever you build something, there are a few design principles to follow:

1. Safety first
2. Make the design scalable
3. Keep it as simple as you can make it

Safety first means that I don't want to have to worry about excessive power all going through one circuit. If I can break it up in smaller sections, I think I'll prefer that. Looking at the problem at hand, there seem to be two ways to get power to the RPi. One is using the micro USB connector on the board, and the other is via the GPIO pins. After reading quite a bit of online articles, I decided against using the GPIO pins and I went for a USB-based approach instead.

Having made that decision, I decided to go for three power boards, each containing 4 USB ports. The boards must be put in parallel to distribute the current requirement. Each board will have a toggle switch to power it on or off, an LED to indicate if it active and the main circuit will have a fuse in it; for the time being fused at 10 A. If I decide to add additional Pi's, all I need to do is add a board and maybe upgrade the fuse.
Theoretically, each power board should be able to deal with about 2 A. Note that I will not need a separate power switch or LED indicator for the total circuit, since that is taken care of by the power boards.

Each power board is relatively simple also; two double USB-ports (DigiKey: ED2984-ND) in parallel, a toggle switch (Radioshack 275-613) and an LED indicator to signify that the board is on.


Note that pin 2 and pin 3 of the USB ports have been shorted; that just means that no data will flow and that the port can only be used for charging. The resistor in series with the LED is just a current limiter; the LED (568nm; green) has a forward voltage of 2.2 V, which leaves 2.8 V over the resistor. I need a current of 25 mA, which means that the resistor needs to be about 120 Ω. Because I had them, I put in 330 Ω, which gives me a current of about 8 mA. Not the brightest LED, but that's okay.

For now, the plan is that I'm going to build up the circuits using a simple PC Board.

Next: Prototype power board to light up four Raspberry Pi's

Using a PC power supply for Raspberry Pis

Now that I had determined that I need to be able to provide approximately 500 mA of current at +5 V of voltage per unit, which adds up to needing the capability to draws about 9 A when all boards are on, I needed to come up with a way to make that happen. A quick experiment with a multi-port USB hub with external power quickly made it beyond obvious that was not going to work. The hub ran out of juice after four Pi's, and I need to be able to power a dozen or more.

Rather than coming up with something complicated, I decided to convert a PC ATX power supply and strip out everything I don't need. PC power supplies are cheap and they provide a range of voltages (+12 V, +5 V, + 3.3 V, to name a few). My power supply is capable of 22 A at +5 V, which is plenty for my purposes.

Fortunately, all wires are color coded, and that was going to be helpful. There are a few things worth mentioning:

1) A PC power supply will not work without some form of a load over the +5 V line
2) In order for the power supply to turn on, the switch wire (green) must be connected to ground

With that knowledge; we can by removing all wire ties and connectors from the cables sticking out of the power supply. Once that is done, we can start opening up the enclosure. Be careful, there are some large capacitors in there that can hold quite a nasty charge. You don't want to be on the receiving end.



Since a normal PC power supply is turned on and off by the master switch on the PC enclosure, we want to bring in our own switch. I like to have a visual confirmation of the fact that the power is on, so I included an indicator LED also.

For both the switch as well as the LED, I needed to drill holes in the enclosure. Make sure that when you do that, metal shavings don't short out any of the components in there, and make sure that the drill doesn't go too far and damage stuff on the circuit board.

On the left-hand side, from top-to-bottom, we see the toggle switch (Radioshack 275-603), the load resistor (Radioshack 271-132), two banana plugs (that I ended up not using) and the LED (Radioshack 276-271).

The first thing to do is remove all wires that we know for a fact will not be used. In my case, I removed all but the black, red, and green wires. Using wire cutters, clip the wire as close to the circuit board as possible and pull out the clipped ends. You'll still have quite a few red and black wires left; don't trim any of those until you are doing putting in place what you need; it is much harder to unclip than it is to clip ;)

Step 1) Cut back one black (ground) wire and one red (+5V) wire and strip about 1/2 inch of the insulation. Don't go back all the way to the circuit board; but go short enough that it fits in the enclosure comfortably. Slide pieces of heat shrink tubing over the trimmed wires.

Step 2) Solder the 10 ohm resistor to the wires, move the heat shrink tubing over the exposed leads and apply some heat to shrink them into place. If you can avoid having live leads exposed, why not do so? I found that the best place to mount the resistor is next to the cooling fan, and zip-tied to the grating. Your mileage may vary.

Step 3) Figure out how to position your switch and, using a multi-meter, measure what leads you'll need to use. Remember; a switch in the down position is usually off, a switch in the up position is usually on. Cut the green wire (power switch) and a black wire back far enough that you can reach the switch leads comfortably. Keep in mind that there usually is only one green cable; you don't get a second chance if you cut it too short, so err on the side of caution! Slide the heat shrink wrap over the wire, solder to the switch, position the heat shrink tube and apply heat to shrink.

Step 4) Identify a red cable and a black cable and cut it to size to fit your LED. Slide on heat shrink tubes. Note: unlike light bulbs, LEDs are polarized. Make sure you solder the wires to the right leads, or it won't work. The LED that I used had a resistor included with it, so I didn't have to worry about that. If you are using separate LEDs, you'll have to put a resistor in series. Don't forget to position the heat shrink tube and apply heat.

At this point, you should be pretty much done. Cut back all but two red wires and all but two black wires. Make the cuts as close to the circuit board, taking care not to damage anything in the process.

Next, you can take the two red leads and twist+solder them together, and do the same for the black. Before closing up; it probably wouldn't hurt to grab your multi-meter and just test some leads. Apply your line voltage. If your fuses didn't pop, you probably didn't short out anything. Go ahead, and see if you get +5 V over the wires. If you do, you're done. If not, it is time to troubleshoot.



My final product looks like shown above. You can see the 10 ohm resistor sitting next to the bit heat sink, held in place by two tie wraps. The front of the enclosure has the toggle switch and the LED indicator. My +5 V wires hang out the back, and measure as +5.06 V.

Next: Raspberry Pi board power design

Power requirements of the Raspberry Pi Model B

The Raspberry Pi (Model B) is a nifty little device. It isn't loaded with computing power, but there is enough on the board to make it a fully functional computer. Since it can be powered by a USB cable, and USB ports are supposed to provide up to 500 mA of current (at +5 V), I had hoped that grabbing a multi-port USB hub with external power could do the trick.

Of course, any time that I would have done the math, I should probably have known better. A dozen RPi's at 500 mA each would mean 6 A of current without blinking.

After inspecting the external power supply to my USB hub, I found that it was rated to provide only 2 A. Oops; that won't do. But, since it is a bad idea to believe what you read without giving it a go, I started connecting RPi's to the hub and began powering them up. Sure enough, after four devices, we ran out of juice and the boards didn't get the power they needed.

Well; that threw a wrench in the mix. For me to figure out how much current these things actually draw, I had to sacrifice a USB cable. USB wiring is simple; there are only four strands. Two of those are for power (the outer two pins on the connector; typically red and black in the cable) and two of those are for data. Since we don't use the hub for data transfer, we don't really care about those two wires.


The photo listed above shows the RPi connected via a cross-over cable to my laptop, a micro-USB cable that had been opened up and the ammeter connected via alligator clips. To my surprise, the RPi draws the highest current when it is booting up; even when having the processor run at full load after it boots, it doesn't peak much after that. Measurements were consistently between 410 mA and 450 mA. Note that in my scenario, I am only putting load on the network jack. I presume that adding stuff to the USB ports and to the HDMI port will lead to a higher draw.


At this point, I am looking at potentially up to 15 devices drawing 450 mA each. After adding some overhead, it seems like I need to be able to provide between 8 A and 9 A of current.