Author Topic: Moteino, 4 AAA 1.5V batteries and two relays  (Read 13552 times)

chspter

  • NewMember
  • *
  • Posts: 10
Moteino, 4 AAA 1.5V batteries and two relays
« on: February 20, 2017, 08:47:25 AM »
Disclaimer: noob alert, fundamental knowledge on electronics missing.

I am trying to build a really simple remote switch (two relays) using two moteinos. Initially I planned to power it up with 4 1.5V alkaline batteries, but now I am finding out that the board resets when the two relays are powered on at the same time. The relays are triggered using two NPN connected to the 3.3 out pin on the moteino. Not knowing better I assumed the power was not enough and tried with a 9V alkaline, with similar results. Out of ideas, I connected a Li-ion 3.7V 800mAh battery from a phone I had around and everything worked fine.

At this point, I am missing the piece of knowledge that explains this. I assume that Li batteries discharge at a different rate than alkaline ones, or just the AAA batteries cannot hold the load from two relays? I wasn't thinking on using LiPo batteries for this project, as it will assume more parts and taking care of charging them, but maybe it's the only way.

Crude schematic attached in case my explanation lacks. The switches I am actually using are ralux RN 3v.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #1 on: February 20, 2017, 09:17:53 AM »
In your circuit the two relays are being powered by the Voltage Regulator of the Moteino, which probably can't handle the extra load.  I would recommend changing the circuit so that the two NPN transistors have their emitters tied to ground, the base tied to the control pin but through a resistor to limit the current into the base (470 ohm should be fine).  Then the collector of each transistor drives the low side of the coil.  Then connect the high side of the relay directly to the battery (if its a 3V relay then connect to the middle tap of the 4 batteries).  This takes the load off of the voltage regulator.

The other problem you have, which may actually be causing the reset, is that you do not have a clamping diode across the relay coils.  When you pump current into a big inductor like a relay coil, as soon as you try to remove the current (turn off the transistor) the inductor will attempt to continue flowing the same amount of current until it dissipates.  What happens without a clamp diode is that the emittors will be driven to a negative voltage until the transistor's base tries to pull the Moteino output pin below ground.  This is NOT good and could damage the processor.

Net:  put a silicon diode (1N4001 or some such) with the anode on the low side of the coil and the cathode on the high side.  When the transistor is turned on, the diode will be reverse biased and won't conduct.  When you turn off the relay, the coil will drive the diode into conduction and the diode will clamp the voltage to about 0.7 volts.

Good luck and have fun!

Tom

KrisK

  • NewMember
  • *
  • Posts: 26
  • Country: us
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #2 on: February 20, 2017, 11:21:51 PM »
Tom is the guru... 

Here are my points.   I had a similar project using a POLOLU microchip and 2 relays.   I discovered the better solutions was to direct wire the relay's from the VIN and Ground then use the micro chip to simply activate them.   I had a physical switch that sent power to both the Relay's and the Micro.  That way I could power off the relay with the switch and not drain the battery.     Another reason to isolate the power to the relay instead of driving power via the micro was;  When power started to drop or it was cold outside the microchip voltage regulator wouldn't control the relay very well and I would see the relay flutter quickly giving me inconstancy on the circuit the relay was controlling.    I had a similar event with an electronic counter.   I wired it as described above and my problems went away.      Lastly, verify the relay can handle the low volt output from the micro.

I like you, don't understand the electrical side like Tom and Felix and the other contributors on this site..   

Anyway.. hope the suggestions help.

chspter

  • NewMember
  • *
  • Posts: 10
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #3 on: February 21, 2017, 06:24:35 AM »
In your circuit the two relays are being powered by the Voltage Regulator of the Moteino, which probably can't handle the extra load.  I would recommend changing the circuit so that the two NPN transistors have their emitters tied to ground, the base tied to the control pin but through a resistor to limit the current into the base (470 ohm should be fine).  Then the collector of each transistor drives the low side of the coil.  Then connect the high side of the relay directly to the battery (if its a 3V relay then connect to the middle tap of the 4 batteries).  This takes the load off of the voltage regulator.

The other problem you have, which may actually be causing the reset, is that you do not have a clamping diode across the relay coils.  When you pump current into a big inductor like a relay coil, as soon as you try to remove the current (turn off the transistor) the inductor will attempt to continue flowing the same amount of current until it dissipates.  What happens without a clamp diode is that the emittors will be driven to a negative voltage until the transistor's base tries to pull the Moteino output pin below ground.  This is NOT good and could damage the processor.

Net:  put a silicon diode (1N4001 or some such) with the anode on the low side of the coil and the cathode on the high side.  When the transistor is turned on, the diode will be reverse biased and won't conduct.  When you turn off the relay, the coil will drive the diode into conduction and the diode will clamp the voltage to about 0.7 volts.

Good luck and have fun!

Tom

Thanks Tom! Just to see if I am following this correctly, I attached an updated crude schematic :)

Still have a couple of questions.

1. Wouldn't tapping in the middle of the batteries drain two of them at a different rate than the other two? Initially I wanted to avoid powering the relays directly from batteries in order to not think about regulating the power to the 3V that the relays use. I like the freedom of connecting "anything" between 3.7 and 12V into the board. Maybe I could get a power shield and power the relays from the 5V out? Also, solid state relays?

2. Why does the voltage regulator from the moteino handle the load when using a 3.7V Li-ion (800mAh) battery, but not when using Alkaline batteries? Is this related to the voltage spike caused by the coil on my circuit without the mentioned clamping diodes?

Tom is the guru... 

Here are my points.   I had a similar project using a POLOLU microchip and 2 relays.   I discovered the better solutions was to direct wire the relay's from the VIN and Ground then use the micro chip to simply activate them.   I had a physical switch that sent power to both the Relay's and the Micro.  That way I could power off the relay with the switch and not drain the battery.     Another reason to isolate the power to the relay instead of driving power via the micro was;  When power started to drop or it was cold outside the microchip voltage regulator wouldn't control the relay very well and I would see the relay flutter quickly giving me inconstancy on the circuit the relay was controlling.    I had a similar event with an electronic counter.   I wired it as described above and my problems went away.      Lastly, verify the relay can handle the low volt output from the micro.

I like you, don't understand the electrical side like Tom and Felix and the other contributors on this site..   

Anyway.. hope the suggestions help.

Glad to know, I will try Tom's solution and report back. So far I am having a great deal of fun with this, looking forward to learn more!
« Last Edit: February 21, 2017, 06:46:29 AM by chspter »

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #4 on: February 21, 2017, 08:16:51 AM »
Thanks Tom! Just to see if I am following this correctly, I attached an updated crude schematic :)
Yes, this is exactly what I suggested.
Quote

Still have a couple of questions.

1. Wouldn't tapping in the middle of the batteries drain two of them at a different rate than the other two? Initially I wanted to avoid powering the relays directly from batteries in order to not think about regulating the power to the 3V that the relays use. I like the freedom of connecting "anything" between 3.7 and 12V into the board.
In this case, you could use another NPN transistor and use it as a voltage follower.  As a 'follower', the collector is tied to Vin.  The base is tied to 3.3V, the emitter to the power supply of the relays.  I did not check on how much current the relays draw, but if it's a lot (which it may be, being low voltage relays), then you'll need a Power NPN transistor and possibly a heat sink if you do plan to operate from 12V.  You can calculate power as W = Ir * Vd, where Ir is total current of the two relays (in Amps),  Vd is the voltage drop across the power transistor and is equal to Vin - (3.3-0.7)   0.7 is the voltage drop from the Base to Emitter.  The advantage of this circuit is very low quiescent current when the relays are off.
Quote
Maybe I could get a power shield and power the relays from the 5V out? Also, solid state relays?
Generally speaking, solid state relays are usually the best choice with microprocessors unless you can not tolerate the voltage drop across the relay 'contacts'.
Quote
2. Why does the voltage regulator from the moteino handle the load when using a 3.7V Li-ion (800mAh) battery, but not when using Alkaline batteries? Is this related to the voltage spike caused by the coil on my circuit without the mentioned clamping diodes?
I don't know the answer, but I suspect it was the voltage spike.  That doesn't make sense from a purely 'spike' perspective, but may have to do with some unknown behavior of the voltage regulator operating at 6V with the spike vs 3.7V with the spike.

In any case, you're on the right track.

Tom

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #5 on: February 21, 2017, 10:44:34 AM »
2. Why does the voltage regulator from the moteino handle the load when using a 3.7V Li-ion (800mAh) battery, but not when using Alkaline batteries? Is this related to the voltage spike caused by the coil on my circuit without the mentioned clamping diodes?

If this was your original circuit with the NPN's on 3.3V, the coil would try to make the emitter go negative when it's turned off. However the substrate diode of the MCU (between ground and the base drive signal) would then conduct and the NPN would stay on until the energy in the coil dissipates. You effectively have a clamping diode in circuit (albeit with the NPN transistor also in that clamping circuit and the MCU substrate diode being the diode part). My guess is it's something to do with the internal resistance of the batteries causing a voltage drop on turn-on, not spikes during turn-off.

Mark.

chspter

  • NewMember
  • *
  • Posts: 10
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #6 on: February 25, 2017, 08:00:22 AM »
Quick update: I tried the circuit, relays connected to power (with the diode bridge) and NPN collector, signal to base with resistance and emitter to ground. All looks good, although now I need to correct the power for handling the relays safely between voltages (let's say, 4V to 9V) as Tom said.

However, and just for the sake of completeness, the rebooting problem still stands when using the 3.3 out from the moteino. 4 half depleted AAA batteries (around 4.5 V) handled it fine (although couldn't power the two relays at the same time for more than 5 seconds), a 9V battery reboots, and the Li-Ion battery keeps working. Mark, you are probably right.

At this point I am ready to write off using the 3.3 out, it was a silly idea. I now understand the 3.3 out is there just to output voltage into buttons, switches and leds.

Since this post was moved to projects, I will keep posting followups about it. Thanks for the help so far, really! Further feedback will be greatly appreciated.

I need to ask my dad what kind of current will go through the relays. Depending on that, maybe I can switch to solid state relays or even optocouplers (? please correct me if an optocoupler is not suit for switching low power independent circuits).
« Last Edit: February 26, 2017, 11:32:34 AM by chspter »

chspter

  • NewMember
  • *
  • Posts: 10
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #7 on: February 26, 2017, 07:43:17 AM »
Attaching the schematic of my 'slave' board. There's a DIP to configure the client id (which later is translated onto which relay to activate), a push switch to test it and a terminal to connect an external switch (bridging the push). One LED indicates the switch (or external) circuit being closed. The other LED indicates an ACK from the 'master' board.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #8 on: February 26, 2017, 08:03:31 AM »
The schematic looks good, but I'd make one minor change.  Since this is battery operated, you want to avoid circuits that have a continuous drain on the battery.  The DIP configuration switches will potentially have one or more switches that are always closed.  The pull down resistors, therefore, will always have current through them.  If you disconnect the common of the switches from 3.3V and connect the common to a spare GPIO, you can set the GPIO as an output and only drive it high in your setup code.  Then you read the switch setting, save it in a variable, then turn off the GPIO - the current drain will only occur for a brief amount of time and you have a permanent record of the setting.

Tom

chspter

  • NewMember
  • *
  • Posts: 10
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #9 on: February 26, 2017, 10:02:15 AM »
The schematic looks good, but I'd make one minor change.  Since this is battery operated, you want to avoid circuits that have a continuous drain on the battery.  The DIP configuration switches will potentially have one or more switches that are always closed.  The pull down resistors, therefore, will always have current through them.  If you disconnect the common of the switches from 3.3V and connect the common to a spare GPIO, you can set the GPIO as an output and only drive it high in your setup code.  Then you read the switch setting, save it in a variable, then turn off the GPIO - the current drain will only occur for a brief amount of time and you have a permanent record of the setting.

Tom

This is a really good idea. Thanks Tom!

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #10 on: February 26, 2017, 10:37:59 AM »
Just to add to that, you'll probably want some series resistors in line with the LEDs to control the current, currently the current will be limited by the I/O pin and that could be many 10s of mA (essentially the I/O pin will see that as a partial short circuit).
Mark.

chspter

  • NewMember
  • *
  • Posts: 10
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #11 on: February 26, 2017, 11:24:45 AM »
Just to add to that, you'll probably want some series resistors in line with the LEDs to control the current, currently the current will be limited by the I/O pin and that could be many 10s of mA (essentially the I/O pin will see that as a partial short circuit).
Mark.

I assumed that IO pins were limited to 10mA and it was all good without a resistance for a 5mm LED. Say, then, 220 ohms?

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #12 on: February 26, 2017, 12:27:08 PM »
Just to add to that, you'll probably want some series resistors in line with the LEDs to control the current, currently the current will be limited by the I/O pin and that could be many 10s of mA (essentially the I/O pin will see that as a partial short circuit).
Mark.
good catch, Mark.  I totally missed that.   220-470 would probably be good values.  It depends on whether the LEDs are 'high brightness' or not.  High Brightness Red could probably get away with 1K.  Use some clip leads and try out some values.

Tom

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #13 on: February 26, 2017, 01:00:17 PM »
I assumed that IO pins were limited to 10mA and it was all good without a resistance for a 5mm LED. Say, then, 220 ohms?

There is a max output current the pin could supply to be above the logic 1 threshold or sink to be below the logc 0 threshold, but that's a minimum specification, it doesn't mean it is limited to that current. Fitting resistors allows you to define that current more accurately, and to protect against violating the max current per pin specification. In general it's not good practice IMO to rely on the output impedance of the pin driver to limit current.

To work out the resistance use the formula (Vcc - Vf)/I = R, where Vf is the forward voltage of the LED and I is the current you want through it. For example Vcc = 3.3V, Vf = 2.2V, and 4mA is your required current, then R = (3.3 - 2.2)/0.004 = 270R.

Mark.
« Last Edit: February 26, 2017, 01:06:36 PM by perky »

chspter

  • NewMember
  • *
  • Posts: 10
Re: Moteino, 4 AAA 1.5V batteries and two relays
« Reply #14 on: March 01, 2017, 07:25:38 AM »
There is a max output current the pin could supply to be above the logic 1 threshold or sink to be below the logc 0 threshold, but that's a minimum specification, it doesn't mean it is limited to that current. Fitting resistors allows you to define that current more accurately, and to protect against violating the max current per pin specification. In general it's not good practice IMO to rely on the output impedance of the pin driver to limit current.

To work out the resistance use the formula (Vcc - Vf)/I = R, where Vf is the forward voltage of the LED and I is the current you want through it. For example Vcc = 3.3V, Vf = 2.2V, and 4mA is your required current, then R = (3.3 - 2.2)/0.004 = 270R.

Mark.

I tried to measure the voltage drop from the LED with the multimeter. Out is 3.3, out on the ends of the LED is 2.4, so around 1V. That would give 575R.

However, I tested it with two 220R on series and the LED is too dim. Between no resistance and 220R, both are good, so I will go with 220R. Probably I miscalculated the forward voltage of the LED.
« Last Edit: March 01, 2017, 07:39:30 AM by chspter »