Introduction: Use 3 Arduino Pins to Control As Many Devices As You Want !

This is a simple project that will allow you to control as many devices as you want with only 3 GPIO pins on a microcontroller !


Step 1: Overview

I couldn’t get pictures of the finished project yet ( I used it in a more complex project, and really don’t feel like taking it apart to get pictures :( I’ll make new ones when I get the components to do so) I will update this instructable when I can have good pictures

Microcontrollers are awesome (I use Arduino but any of them works!) ! But you may be a bit frustrated by the too small amount of GPIOs… Anyway I am !

If you want to increase the number of outputs, there is a simple integrated circuit called « shift register ». I’ll explain how it works later on.

Another thing I find annoying is that you can only control low voltage devices, with a limited amount of current.

A simple way to be able to use higher voltage outputs is to use a relay. But those are not very reliable in my experience, at leat the cheap ones. Moving parts are always a weakness, they are too slow to switch rapidly (therefore not usable for PWM… though we can’t use PWM with this PCB anyway) and they are a bit noisy too… That’s why transistors are great ! We’ll use a NPN darlington TIP120 for this PCB. They do the same thing (even more), are cheaper and more reliable !

So I looked online to find a PCB combining those two features and couldn’t find anything I liked… So I made my own ! I’m no pro (this is among my first creations) but this is a simple circuit and it works fine !

With this PCB you will be able to turn on and off 8 DC devices (up to 60V) with only 3 GPIO pins ! Cool isn’t it ? Not impressed ? Well, if you want to use even more, you’re lucky ! The shift registers ar chainable ! You just have to connect one to another and you can have as many outputs as you wish ! Still using only 3 GPIO pins ! Amazing isn’t it ?

Step 2: Materials

All the components are THT and not SMD. Be carefull when you choose them !

1 x PCB (design below)

1 x 74HC595 8 bits Shift register (multiplexer) (other shift registers should work too)

1 x 16 pin socket (optional)

8 x 1N4004 Diods (any of the 1N400X series should work)

8 x 2.2 Kohms resistors (if using arduino or other 5V GPIO devices. Details about other microcontroller later )

8 x TIP120 transistors

14 x Screw headers (5mm pitch) or direct solder to a wire or any connector with a 5mm pitch. (optional)

8 x Heatsinks depending on the current you draw (optional)

8 x plastic washers and screws.(optional)

Thermal Tape (optional)

Depending on the material you use, quantities you buy, where you buy it etc … the price of each completed PCB varies. They are around 5 to 10 €/£/$ each.

Step 3: Understanding the TIP 120 Transistors

There are lots of different types of transistors making lots of different stuff… They have literally been a revolution in electronics and you can find some in almost every electronic device. The inventors of the transistor in 1948 even got a Nobel for it !

The ones we are going to use are TIP120 , a Darlington NPN type, rated up to 60V and 5A in a TO220 package.They have 3 pins, called Base, Collector and Emitter. (The back metal plate with a hole is the Collector too).

The Emitter is connected to the common ground (so it’s sometimes called « Out Pin »).

The Collector is connected to the VCC (up to 60V DC) via the device you want to control (so it’s sometimes called « In Pin »)

The Base is connected to the control device, here the 74HC595 but it can be used directly by an Arduino pin or a simple pushbutton (so it’s sometimes called « Control Pin »).

When 5V is applied to the Base, it allows current to run from the Collector to the Emitter. If no voltage is applied to the Base, current won’t flow. Very simple !

Transistors produce heat. The more current your transistors will have to deal with, the more heat they’ll produce. But if they get too hot they will die.

So you may need heatsinks to cool them down. Just be carefull that your heatsinks don’t shortcut the collector plates to each other. So use one heatsink for each transistor, making sure they don’t touch, or one big heatsink insulated with plastic washers and screws. For better heat tranfer you should use thermal paste or thermal tape.

Whether you use heatsinks or not, you must NOT enclose the PCBs in a completely closed box. Heat must be able to dissipate in the air, through grid, holes or else...

Step 4: Understanding the Resistor ?

The datasheet of the TIP 120 says the Base-Emitter voltage is 5V. But in most schematics I could find online they use a 2,2Kohm resistor, wich lower the voltage applied to the Base. I can’t really understand why this is necessary, but I do it anyway… and it works fine. I’d love to have your insight about that in the comments ;)

I only used this PCB with an arduino. Their GPIOs use 5V. Raspberry Pi or ESP32 use 3,3V GPIO. So maybe the resistors have to be adjusted.

If you don't put any resistor, the voltage won't be reduced. So it may be okay with those controller or even with an arduino. In that case you can just put a wire instead of the resistor. Do it at your own risk … and please let me know ;)

Step 5: Understanding the Diode

The diod is not necessary if you control a LED, for example. But if you use a motor, it keeps spinning a bit after the power is off, therefore generating opposite current, for a very short time, but it can be harmfull to your transistor. This diode prevent unwanted current to kill your transistor, so I advice you use it ! They’re cheap and you can plug anything you want to the PCB without need to know whether it is mandatory or not. I you don't use it , do not put a wire istead as you would do with the resistors or you'll shortcut your circuit and risk damaging it.

Note that diode have polarity. They have to be soldered properly (there is a stripe on one side that is drawn on the PCB label).

Step 6: Understanding the 74HC595 Shift Register

Well it’s "quite" simple… and there is a LOT of documentation online that explain it much better than I could ever do !

I’ll try to summerize anyway.

There are 2 power pins : the VCC is connected to 5V, GND to... well GND!

There are 3 input pins : the « latch » pin (STPC), the « clock » pin (SHPC) and the « data » pin (DS).

There are 8 output pins that are LOW or HIGH, depending on the data the 74HC595 has been fed with. These are pins Q0 to Q7.

There is also another output pin called Q7’ (different from Q7 ) This one allows you to send extra data to another 74HC595.

There are 2 pins we won't really use, the MR (Master Reset) that will be kept HIGH (connected to 5V) ant the OE (Output Enable) that will be kept LOW (connected to GND)

So how does it work? To change the outputs configuration (which output is on or off) you need to :

- First turn the latch LOW. It enables the 74HC595 to receive data.

- Then you have to

- turn the clock LOW, so the 74HC595 knows you're sending a bit

- send the 1st bit of data (if LOW it is a 0, if HIGH it is a 1)

- turn the clock HIGH so the 74HC595 knows the bit has been sent

- repeat it for the 8 bits (or 16 if you use 2 chained registers, or 24 if you use 3 of them, etc... We'll talk about it later on) : clock LOW, 2nd bit, clock HIGH ; clock LOW, 3rd bit, clock HIGH, etc...

- Finally you have to turn the latch HIGH so the 74HC595 knows you’re done with it and refresh the state of its outputs.

Tadaa ! You have a new outputs state !

Step 7: Making the PCB

Here are the files you need to make this PCB. Image files are just here to illustrate this instructable. Use PDF files for manufacturing.

Well, there are lots of ways to get your PCB. By etching, milling etc … There are tons of tutorials to teach you how to do it.

Since I used an online PCB manufacturing service I won’t show you these techniques. (I used JLCPCB, but there are others such as PCBWAY , ELECROW and others) It costed me less than 5€ for 10 PCBs (and 5€ more for delivery). You still can use the files I provided if you want to DIY.

To have your PCB manufactured by an online maker, it's super easy. Just download the gerber files , click "add gerber" on the site you chose, choose the number of PCB you want an all the default settings are fine (You may want to change the colour though...). Then choose the shipping you prefer and pay !

The design is for double layer PCB, which is great for online manufacturing but can be a problem if you use home technics. The top side is all the data pathes, while the bottom side is all the power pathes.

Since I made it on easyeda.com you can easily re-design it for your needs. Just clone/duplicate it and change it as you want !

I may make a 1 side PCB some day and upload it here, but if you do it before me please let me know and let me use it here!

LINK TO THE GERBER FILES

LINK TO THE EASYEDA EDITOR PROJECT


Step 8: Mounting the Components

Pictures coming soon...

That’s the fun part !

This PCB is quite straightforward since each component is labelled directly on the PCB and there are few of them.

I’ll detail them anyway :

- 74HC595 : make sure it is on the top side (where the label is) and that the notch on the chip is on the proper side (as labelled) You may solder a socket instead and then plug the 74HC595 on it

- Resistors : They don’t have polarity. Just solder them on the top side (or the bottom one, it doesn’t really matter)

- Headers : You can use an kind of header that fits (5mm pitch) or directly solder wires. The PCB side you solder it on doesn’t really matter. I like screw headers because they are practical…

-Diodes : They have polarity. Make sure the striped side is as the labelled stripe. It doesn’t matter which side you solder them on as long as the polarity is respected. I prefer to solder them on the bottom side so they are not in the way of the headers.

-Transistors : I designed it so the transistors are monted on the bottom side of the PCB, with the collector metal plates face outward in order to put heatsinks on the side of the PCB and that the transistors are not in the way of the output wires (There is no label on the bottom side though, be carefull to mount it properly ). You can solder them on the top side anyway but make sure they are reversed ( metal plates facing inward as labelled). If you want to bend the transistors I advise you bend them before soldering, otherwise the pins tend to become brittle (I broke some by bending them in and out…) Bended transistor plates will face topwise if you solder them to the bottom side and bottomwise if you solder them to the top side. Make sure the Collector metal place don’t touch each other or you'll have a nice shortcut !

-Adding heatsinks : well, that depend on the heatsinks you’ll use. Just be carefull that they are insulated from the transistor itself as said earlier in the « understanding the transistors » paragraph.

It’s done !

Step 9: Coding

This coding section is made for people who know arduino code basics. If you never used arduino or coding, I doubt this is the best first project for you... But it is simple enough to be amongst your first ones !

As explained in the "understand the 74HC595" paragraph, there is quite a few steps to have the shift register working.

Since it’s a bit long to code all of this there are smart developpers who made a nice function in Arduino. It’s called… shiftOut() !

There a lots of tutorials online that will explain it better but here I go!

First you need to understand that the 8 outputs can be either HIGH or LOW. So they can be written with a set of 1 and 0. And what’s 8 1s and 0s in a row ? A Byte !

On this PCB all the positive are connected, so you have to turn an output LOW to turn on the device connected to it. A bit counter-intuitive at first but come on… you can do it ! There’s a tip later on to make it easier anyway.

So if you send 00000000 to the 74HC595, all the outputs are on. If you send 11111111, they are all off. And if you send 01100100… well it’s not that simple ! let’s see how this function works shall we ?

The shiftOUT() function need 4 parameters :

- the number of the pin connected to the DS of the 74HC595. I use a « #define SR_DATA» (SR for shift register) so it’s simpler. you can just set a variable for the same result, or type the number of the pin you'l use. Basic arduino stuff.

- the number of the pin connected to the SHCP of the 74HC595. (The same with SR_CLOCK)

-The way you want the byte you send to be read (MSBFIRST or LSBFIRST depending if you want your byte to be read from right to left or left to right)

- The byte you want to send. It can be either in binary (don’t for get the « B » before the byte, eg : B00101010) or in decimal

Since the « 1 » turn off and the « 0 » turn on,you can use the « ~ » sign to change each bit to its opposite(eg : 42 is 00101010, ~42 is 11010101) (I told you there was a tip !)

WARNING : the shiftOUT() function only send one byte at a time. If you are using several chained 74HC595s you need to use this function for each of them, the latest in the chain first, up to the first in the chain last. Each time you use this function, it « pushes » the data to the next 74HC595.

Note that you still have to turn the latch LOW and HIGH if you use this function.

byte byteToSend = 42 ;

digitalWrite(SR_LATCH, LOW) ;

shiftOut(SR_DATA, SR_CLOCK, LSBFIRST, ~byteToSend);

digitalWrite(SR_LATCH, HIGH);

You can even make a function out of it so it’s super easy to insert in your code

ShiftRegisterUpdate(byteToSend){

digitalWrite(SR_LATCH, LOW) ;

shiftOut(SR_DATA, SR_CLOCK, LSBFIRST, ~byteToSend);

digitalWrite(SR_LATCH, HIGH);

}

You then just have to use it like that :

ShiftRegisterUpdate(42) ; // if you want only the 4th, 6th and 8th devices to be on ( 42 is 00101010)

If you have several 74HC595 chained, use as many shiftOut() as you need

e .g. for 3 chained 74HC595 :

ShiftRegisterUpdate(3rdByteToSend,2ndByteToSend,1stByteToSend){

digitalWrite(SR_LATCH, LOW) ;

shiftOut(SR_DATA, SR_CLOCK, LSBFIRST, ~1stByteToSend);

shiftOut(SR_DATA, SR_CLOCK, LSBFIRST, ~2ndByteToSend);

shiftOut(SR_DATA, SR_CLOCK, LSBFIRST, ~3rdByteToSend);

digitalWrite(SR_LATCH, HIGH);

}

Note that the order of the parameters are reversed because the last chained 74HC595 receive the first byte sent

ShiftRegisterUpdate(42,86,220) ; // that will have a result of 00101010,01010110,11011100, where 1s are on and 0s ares off.

Don't forget to enable your pins to be outputs in your setup (using the pinMode() function as usual).

I'll upload a few full code examples very soon, as soon as I get the components I need to make new PCBs, Since I don't want to upload code with errors, I'll wait to be able to try it in situ ! ;)

Step 10: Connecting the PCB(s)

Since I lack some components this picture is not really a proper one, but it gives you an idea of how to daisychain those PCs

Well, it’s very simple. The first PCB need to be connected to the microcontroller . The « Data In » connexions must be connected to 3 different GPIOs (you choose which one, they all work), The « Power » +5V must be connected to the microcontroller 5V output (or an external 5v source), the GND must be connected to the microcontroller GND and the external power(s) GND (common ground) and the VCC must be connected to the external power positive.

The other PCBs you’ll use can be daisy chained, which means you just have to plug the « Data Out » pins of the first one to the « Data In » of the next one an so on. It’s the same for the « Power » pins. Unless…

If you want to use several outputs with different voltages, you can either apply the highest voltage you need to the VCC an use serial resistors on the lower voltage devices according to their own specifications. Another way to do it is to use several PCBs, one for each voltage needed, and to power each VCC pin with the proper voltage. You can then have a 9V PBC next to a 12V one, next to a 24V one etc … You get my point. All the GND must be connected together though !

Step 11: A Great Project for Classroms !

All the components are very cheap, the PCB is simple but not simplistic, and they can be used together. So I think this can be a good introduction (or maybe a level 2) to electronics and coding. As an example you can use it to make a column of « pixels » for each board using powerfull leds ( maybe 12V such as these or these )

Each student can make one, then they are chained together to build an 8 by X (number of students) matrix connected to an arduino.

Then each student can make a code to run on the arduino to display whatever you (or they) want.

A nice an simple thing to display on a matrix of 8 LEDs height is text. There are nice fonts that ca be used. You can have it moving etc …

That’s a nice way to learn about bitwise operators too.

I’d love you let me know if you used it in class !

Step 12: Conclusion

That quite simple PCB can be very helpfull, I think. There is probably a better way to do it, and I would love to know what emprovement could be done.

The comment section is open for any remark, suggestion and question. I’ll try to answer all of them ! And let me know if it was use

Have fun !

PCB Design Challenge

Participated in the
PCB Design Challenge