A stupidly simple way to connect 3.3V logic to a Sainsmart relay board

A lot of hobbyists are using Sainsmart relay boards with their projects because the boards cost less than buying the relays, or come really close. The boards include circuits to drive the relay coils so that a typical logic output can be connected directly to the board. Each driver circuit uses an optocoupler so that the driver and the coils only share a ground potential. This is a great scheme to allow the driver to work at a different voltage than the relay coils, but the board was intended for use with 5 volt supplies for both. The drivers start to work reliably from around 3.8V up to 5.5V or so. The result doesn’t work well with a 3.3V supply for the drivers operated by 3.3V logic; some relays will function, and others won’t. The solution is to give the drivers a 5V supply, but then the floating driver inputs should rise to 5V; the drivers are connected to the positive supply, and are two LEDs and a resistor in series that connect to an input pin. A common solution to using 3.3V logic with the Sainsmart board is to add another driver circuit to drive the driver circuit on the board. I thought that was annoying and sounded rather silly, so I investigated further and found a simpler method.

Test setup

Test setup with 10MΩ probe

I started by hooking up 5V supplies to the board and measuring the voltage of one of the driver inputs when left floating. This setup is in the picture; channel 1 (left) is measuring the voltage on a driver input, and channel 2 (right) is measuring the 5V supply. The first results showed a drop of about 2.2V from the driver’s supply. This occurs even when the only wire connected to the board, besides the measuring probe, is the positive power end, VCC, to the drivers. This voltage drop is made possible by the current passing through the probe; connect the probe’s reference potential to the board’s VCC instead of ground, and the voltage measured is zero.

I measured using a 1MΩ probe. With the supply voltage measured at just over 4.8V, I get 2.5V on an otherwise disconnected driver input. The current flowing through the driver is adequate for the LED to make a very dim light.  By switching the probe to 10MΩ (as pictured), the voltage measured is over 0.27V, meaning the voltage on the input is 2.7V.

This indicates that a small current is all that is needed to keep the drivers below 3.3V when using a 5V supply. Connecting a 3.3V logic output directly to one of the board’s driver circuits should work just fine without adding an additional driver circuit. In many cases, though, some 3.3V processor is used and its general purpose I/O lines are initialized as inputs after a reset. Clamping diodes are often present and can probably handle the small current through the relay board’s drivers trying to pull the line to 5V. Adding a 10MΩ resistor to ground should save the clamping diodes from any work, while connecting it to the 3.3V supply should work almost as well while eating even less power. The small current draw of the input might actually take care of the problem, but I lack any measuring equipment that can confirm this without drawing the small current that will take care of the problem.

Circuit to connect 3.3V logic to a Sainsmart relay board

Circuit to connect 3.3V logic to a Sainsmart relay board

I’ve been asked to post a circuit diagram for the solution I mention above, so here it is. I threw it together in Inkscape even though I don’t really know how to use Inkscape. The circuit will work for the Sainsmart relay boards like the one I tested when the drivers on the board are given a 4V to 5V power source.


Tags: , , , ,

8 Responses to “A stupidly simple way to connect 3.3V logic to a Sainsmart relay board”

  1. Smartsenses Says:

    Reblogged this on SainSmart.

  2. aogriffiths Says:


    I’m a little new to this and confused. It sounds like exactly the solution I need to interface a sainsmart relay with 3.3v logic (from a raspberry pi).

    I’m struggling to see exactly where the diode clap and resisters go together. Would you mind drawing a diagram of your solution?


    • jjackowski Says:

      I added a diagram of the solution to the post. There are no diodes involved. Current from the driver’s VCC connection flows through two resistors and an LED in series, so it doesn’t take much current to keep it below the VCC voltage.

  3. thebuilder@briccces.com Says:

    Another really cheap way to do it is to buy a cheap micro-usb arduino uno clone. I’ve seen them around for almost nothing.
    buy a cheap phone charger cable for 50 cent ( or use the one that’s bound to live somewhere in your cuploard) at voila.

    You can just write a simple script that does serial communication with the pi over usb to transfer the desired state of your arduino and power it.

    • thebuilder@briccces.com Says:

      The arduino uses 5v , will interface perfectly with the relay board and if you blow it up, chuck it out and get a new one. Your lovely pi will still be fine.(probably)

    • thebuilder@briccces.com Says:

      I know , it’s 2017 not 2014 but ppl still get to this page when searching how to do this.

    • jjackowski Says:

      It is also possible to use a shift register, like a 74164 or 74595, with simple voltage level conversion, or an I2C GPIO device, like the MCP23017. Thanks to the pull-up on the I2C data line, there is a good chance that no voltage level conversion will be needed.

      The problem with microcontroller solutions is that they put software in two places rather than just one, which can complicate matters. Simple software can be used on the microcontroller, but even simple software may have bugs. Since the Sainsmart relay driver circuit can work with a 3.3V signal, and there are other simple ways to get a 5V output without a microcontroller, I think the microcontroller option makes the best sense if running some more complex software on it is valuable for the specific use.

      But, if you can get it a microcontroller cheap enough, it won’t make any real difference if you don’t mind writing its software. I got a few ATtiny88’s from Digikey recently for $1.02 each, less than their $1.24 price for a MCP23017. With that price difference, it makes the most sense to go with the simpler option that will work for a personal project rather than the cheaper one.

      On the other hand, something like this might make for a good simple introduction to using Arduinos or microcontrollers.

      • Bob Says:

        Sure, as a statement extra programming makes for extra errors is simply true. But in this particular case it would be like calculating in the risk of getting 1+1=2 when computing escape velocities and satellite slingshots. A program doing some multiplexing and a basic form of error detection of the level needed here would need to be really bad for any errors to creep in. Still .. your point is undeniable.

        As for precision/speed of the communication between the IC and the PI a 74595 can be driven quite a bit faster than a serial link at 9600 baud. A relay the caliber of those used on the sainsmart board however should probably only be switched somewhere between 50 and 400 times per second ( lower than lowest number if you want your relays to live for a while ) Which makes 9600 baud about double what’s needed in the most extreme case.

        As a learning experience for programming, using an arduino would be good practice for an electronics hobbyist I agree. But for someone familiar with programming but less with electronics using a 74595 on a mini breadboard sounds like a challenge as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: