0

I want to connect up a relay module (wired up to control a normal desk lamp) to an mbed LPC1768 board. I have the circuit connected up successfully using an Arduino via the Arduino's 5V pin. From the control perspective, all I am doing is turning on/off the lamp; I have no problem from the code side, just the electronics!

Mains voltage-->relay module-->lamp
                     ^--mbed

From what I have read, the mbed's Vout is 3.3V. Some of the other pins are 5V tolerant, but looking at this datasheet, it seems to say that the pin has the same tolerance as Vdd(3v3), which has a max voltage of 3.6V.

The other option I have seen is using the VU pin. As far as I can tell, it is a 5V Out pin as long as the board is connected up via the USB cable. If so, then that makes life a lot easier. I have read mixed accounts of whether it is Out or In, but most people seem to be using it to power 5V peripherals, so I assume I can do that then. I couldn't find confirmation of this in the documentation, though, so if anyone knows more about this I would be grateful.

Fail this, then I would appreciate any suggestions on the best way to boost the voltage to run the relay. I imagine I will need a MOSFET or similar, but I know very little about how to wire them up. I saw this, but it blew my mind a little...

I am also not sure on the current requirements, but as it runs from the Arduino without a problem then I don't think it is too much to imagine that it would also run from the mbed. Feel free to berate me for assuming anything if incorrect!

  • Without knowing which relay or relay module you are using we cant help. – Passerby Jul 31 '15 at 14:29
  • It is a 250V (mains compatible) relay module which requires 5V to control it. It is basically the one found [here](http://www.instructables.com/id/Controlling-AC-light-using-Arduino-with-relay-modu/) – bladepanthera Jul 31 '15 at 14:53

2 Answers2

1

Simple, with a standard NPN transistor. You could also use a 3.3V mosfet, but an NPN what you need.

schematic

simulate this circuit – Schematic created using CircuitLab

The Relay Module will be powered from the same USB power supply needed for the mbed board.

The Module has an optocoupler that needs to be pulled low at Relay IN to enable the relay. The transistor is enabled by a GPIO HIGH.

Passerby
  • 72,580
  • 7
  • 90
  • 202
  • Ok, this looks great as I have a 2N3904 to hand! I have a question. If it is the voltage which needs to be boosted, why is the voltage line directly connected to the VU and the GPIO line regulated? The GPIO pins are 5V tolerant, so I thought that they would have no issues. – bladepanthera Jul 31 '15 at 15:41
  • @bladepanthera if the gpio you need control the module is 5V tolerant, you still wouldn't be able to control it properly. While the pin wouldn't be hurt by 5v IN, when it is HIGH it will still only be 3.3V, and that means the relay control optocontroller will still be ON. You could never turn the relay off. – Passerby Jul 31 '15 at 15:51
  • @bladepanthera the VU line is 5V USB. The Relay needs 5V to trigger. The control side of the module could work with a lower voltage, but would require having two voltage supplies, and modifying the board. Trust me, this resistor + transistor setup is needed for multiple reasons. – Passerby Jul 31 '15 at 15:53
  • The relay turns on and seems to have enough power through the transitor which is great, but now when I try to turn the lamp on and off by sending 1/0 signals to the pin it is connected to, the lamp doesn't change. It turns on initially when the relay is powered on and stays on all the time. Any ideas? (Using [this](https://developer.mbed.org/users/4180_1/notebook/relay-breakout-boards/) example code - pretty basic!) – bladepanthera Aug 03 '15 at 15:08
  • 1
    Ok, forget it! It works now :D I had it connected through the pin that I was using for the lcd board on the mbed expansion board! Works like a charm. Many thanks! – bladepanthera Aug 03 '15 at 15:13
  • is this solution also applicable to connecting 5V sensors to boards with 3V3 output? I'm using a different board which only has 3V3 and thought this might work in that case, too. – bladepanthera Aug 10 '15 at 11:29
0

You need also to tell the solenoid voltage of the relay and voltage of other DC source (shall be the solenoid relay voltage) to boost the output you have. Simple NPN transitor, base resistor and freewheeling diode will do the trick.

Marko Buršič
  • 23,562
  • 2
  • 20
  • 33
  • I read this and I think my soul departed as this flew over my head. After a quick google I'm using a relay, not a solenoid. They are different. Why do I have to "tell" it to boost the output voltage, considering that this voltage is coming from the mbed? I hope I'm not appearing standoff-ish, I just don't understand. And if I need those components, how on Earth do I connect them up?! And which ones exactly do I need? Even if you leave me to find that out, what does the circuit look like? Sorry, but I'm still pretty new to more in depth electronics so I'm still learning what things are. – bladepanthera Jul 31 '15 at 15:04