Need some electronics advice...

for all subjects/topics not covered by the other forum categories
Post Reply
User avatar
sweh
Posts: 1950
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Need some electronics advice...

Post by sweh » Mon Apr 30, 2018 11:23 pm

As previously mentioned, I used an arduino to replace a broken electronic safe controller and made it computer controlled instead:

https://www.sweharris.org/post/2017-10-09-digital_safe/

The circuit design is pretty simple: Image

But recently I've been having a problem; whenever I open the safe (click the relay) the Arduino reboots. I have three theories, but I dunno if any of them are reasonable nor how to test it :-)

1: Power adapter I'm using isn't powerful enough to drive the relay, solenoid and arduino so there's a power drop and a reboot. The original just used 4x1.5A batteries; this is using a USB 5V adapter.
2: Solenoid is causing a spike and a capacitor could smooth that out?
3: Solenoid is causing back-voltage and a diode would fix it?

Or something else :-)

Anyone have any ideas? Needing to dig up the "emergency key" each time I need to open the safe kinda negates the point of all this :-)
Rgds
Stephen

User avatar
lcww1
Posts: 274
Joined: Wed Mar 15, 2017 11:16 pm
Location: Moon Base Alpha
Contact:

Re: Need some electronics advice...

Post by lcww1 » Tue May 01, 2018 6:25 am

Here’s a thread from the arduino forum that addresses a very similar situation to yours - https://forum.arduino.cc/index.php?topic=439787.0
- you need a fly back diode!
Hope that link helps :D

User avatar
BigEd
Posts: 2060
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Need some electronics advice...

Post by BigEd » Tue May 01, 2018 7:14 am

I'd go for 2 and 3. If you've got a relay nearby, you've got a very electronics-unfriendly environment, and a capacitor or two (one big, one small) helps to keep things peaceful. You might also look at your power wiring: separate wires from the supply to the heavy duty stuff on one hand, and to the delicate electronics on the other, might help.

User avatar
1024MAK
Posts: 7787
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Need some electronics advice...

Post by 1024MAK » Tue May 01, 2018 7:44 am

Hi Stephan

I'm not surprised. A small 12V relay coil can crash a 74HC4060 binary counter!

Electromagnetic devices like relays and solenoids produce a very large voltage spike when you turn them off. The larger the physical size, the more energy is involved. So yes, if there is no existing reverse parallel diode, then fit one across the coil of the relay. And across the coil of the solenoid.

Each diode should be connected with the cathode (k)(if using a diode in an axial package, the end with the white band) to the positive coil connection. The anode (a) is then connected to the negative coil connection. The diode allows the energy from the collapsing magnetic field to become a current flow around and through the diode.

At the same time as fitting the diodes, also fit 50V or 100V 100nF ceramic capacitors across the coils.

Relays and especially solenoids draw a sudden and large amount of power from the power supply. so I recommend that you test your PSU to make sure that the output voltage does not change when loaded. If the output voltage does change, obtain a higher rated PSU.

Also instead of daisy chaining your positive 5V and the 0V/GND wiring. Do this:-
  • Run short wires from the PSU to a large electrolytic capacitor, say 4700uF
  • From this capacitor run supply wires to the relay and solenoid
  • Run separate wires from this capacitor to the Arduino
  • Across the power connection point on the Arduino, connect another electrolytic capacitor, say 470uF or 1000uF
  • Keep the power supply wiring for the relay and solenoid away from the Arduino and any associated circuitry
  • Similarly, keep the Arduino and any associated circuitry away from the relay and solenoid.
A spike may find it's way along the control circuit/wire to the Arduino, if you still have problems give us some more details.

Good luck :wink:

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

User avatar
sweh
Posts: 1950
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Need some electronics advice...

Post by sweh » Tue May 01, 2018 10:19 am

Thanks for the replies!

If I understand correctly, then I should put a diode between VCC and GND on the input to the relay side, with the cathode on VCC and the anode on GND. That's easy enough. Similarly another one between ON and GND on the output of the relay.

Should the capacitors be in the same places? In parallel or series with the diodes?

I have a horrible feeling I might need to get my soldering iron out... the horrors!

PS: Thanks, Mark, for the "end with the white stripe" comment; yes, that is the sort of stuff I do need to know :-) As you can guess, I really don't understand this too well!
Rgds
Stephen

User avatar
1024MAK
Posts: 7787
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Need some electronics advice...

Post by 1024MAK » Tue May 01, 2018 12:58 pm

One example:
Image
Notice how the diode is connected across the coil and not just across the power rails.
sweh wrote:Should the capacitors be in the same places? In parallel or series with the diodes?
The 100nF capacitor should be in parallel with the diode and the coil.

More info on diodes on this Wikipedia page. It includes a nice picture showing the symbol and images of diodes with the same orientation:-
Image

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

User avatar
sweh
Posts: 1950
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Need some electronics advice...

Post by sweh » Tue May 01, 2018 4:11 pm

I now have a weekend project :-)

Thanks!
Rgds
Stephen

User avatar
sweh
Posts: 1950
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Need some electronics advice...

Post by sweh » Sat May 05, 2018 9:28 pm

Looking through my box of randomness, the only diode type I have is 1N914. I've also got a bunch 0.1uF 50V capacitors.

It's funny that two components, so small, can make such a difference :-)
Rgds
Stephen

User avatar
1024MAK
Posts: 7787
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Need some electronics advice...

Post by 1024MAK » Sat May 05, 2018 11:00 pm

sweh wrote:Looking through my box of randomness, the only diode type I have is 1N914. I've also got a bunch 0.1uF 50V capacitors.

It's funny that two components, so small, can make such a difference :-)
The 0.1uF 50V capacitors are fine. The 1N914 should be fine for use across the relay coil. But are not likely to survive for long across the solenoid coil. But it depends on the power rating of the solenoid. A 1N400x (1N4001 to 1N4007) diode or even better, the fast version UF400x (UF4001 to UF4007) or any other silicon diode rated at 1A would be more suitable.

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

User avatar
sweh
Posts: 1950
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Need some electronics advice...

Post by sweh » Sun May 06, 2018 1:30 am

I can't tell what solenoid it is; it's very wrapped up ( https://www.sweharris.org/Safe/large/internals.jpg ). I can find lots of pictures, but I can't find any actual specs. I've seen some for sale on aliexpress claiming to be 6V 0.35A ( https://www.aliexpress.com/item/Solenoi ... 86657.html )

I'm powering the whole thing from a 5V 0.7A supply, which seems to be enough to open it. I wasn't sure it'd work, when I started; it originally was powered by 4*AA batteries.
Rgds
Stephen

User avatar
vanekp
Posts: 545
Joined: Thu Nov 30, 2000 7:09 am
Location: The Netherlands
Contact:

Re: Need some electronics advice...

Post by vanekp » Sun May 06, 2018 6:25 am

Looking at your 1st picture (if that's the same as your system) it looks like there is already a diode across the solenoid on the printed circuit board.
Peter.

User avatar
1024MAK
Posts: 7787
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Need some electronics advice...

Post by 1024MAK » Sun May 06, 2018 8:50 am

The datasheet for 1N914 diodes is here.
The normal maximum forward current is 300mA. They can take larger currents for short durations. In practice though, signal diodes like this don't like the large current that flows when the magnetic field of the inductive device collapses, even though the current flow is only a short duration (see note below).

There is no harm in trying a 1N914 if you wish too. Just make sure that you have a fuse between the PSU and the circuitry. A fuse is strongly recommended, as sometimes diodes go short circuit when they fail. The value of the fuse should be around 5 to 10% greater than the normal maximum current of the circuit, or 5 to 10% greater than the maximum rated current of the PSU. Although in practice the limited range of fuses means you just go for the next available value that is greater than the circuit current/PSU rating. Because you have a solenoid, you should use a time delay fuse, also known as anti-surge fuses.

If the relay is on a prebuilt module, the module may already have a diode across it's coils. For example like in this picture:-
IMG_7013.JPG
Relay module
Peter, Stephen is not using the control board that came with the safe.
Stephen, if you still have the old control board, you could remove the diode from it.
But as 1N4001 diodes are so cheap, it's just easier to buy some new ones. If you were nearby, I would give you some. For example, here's some listings on eBay.com.

Note: at work we used to operate a 1960's control system that used many twin coil relays (these are rather larger than the modern small 5V PCB mounting relays). These ran at 18V DC. We tried using modern signal diodes to replace any original failed diodes. But although they worked for a while, we soon started seeing failures. Some of the 'new' diodes had failed. However, keep in mind that some of these relays operated many times a day.

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

User avatar
vanekp
Posts: 545
Joined: Thu Nov 30, 2000 7:09 am
Location: The Netherlands
Contact:

Re: Need some electronics advice...

Post by vanekp » Sun May 06, 2018 12:37 pm

okay so what is the control board then is that just a relay board ?
Like this :-
Image
It's not clear from his write up, some photos would help as the block diagram tells you nothing.

User avatar
sweh
Posts: 1950
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Need some electronics advice...

Post by sweh » Sun May 06, 2018 1:29 pm

The initial link to my site goes into a bit more detail but, to make it simple, I wanted to replace the original (broken) controller board with an Arduino Nano. That'd let me do more "computer control" of the safe via a serial port.

Because I was pretty sure the Arduino wouldn't be able to supply enough current to make the safe solenoid open (I think the Arduino can supply 40mA max), I made it trigger a relay instead, and the relay controls the +5V to the safe solenoid. From my limited knowledge, I believe this is a standard design pattern.

So
serial-->ARDUINO-->relay-->solenoid.

The relay board is very similar to the one you saw; it has some activity LEDs to show the state and, yes, I had noticed there was a diode on the control side, which I assumed was sufficient (which makes sense; the board was designed for connecting to Arduino/Pi/etc so having the diode already there would be sensible).
relay.png
So I think I only needed to put stuff over the safe locking solenoid. Which, of course, is the higher powered side of the circuit and so likely to suffer the problems Mark is cautioning me about :-) I need a bigger diode!
Rgds
Stephen

User avatar
lcww1
Posts: 274
Joined: Wed Mar 15, 2017 11:16 pm
Location: Moon Base Alpha
Contact:

Re: Need some electronics advice...

Post by lcww1 » Sun May 06, 2018 2:06 pm

If I were wanting to control a solenoid using an arduino, I’d use a MOSFET transistor, or a TIP20 darlington pair, rather than a relay - here’s a nice step by step guide: https://www.bc-robotics.com/tutorials/c ... h-arduino/

User avatar
sweh
Posts: 1950
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Need some electronics advice...

Post by sweh » Sun May 06, 2018 2:28 pm

The transistor would work as a drop-in replacement for the relay, yeah. It doesn't prevent the need for the diode over the solenoid, though :-(
Rgds
Stephen

User avatar
vanekp
Posts: 545
Joined: Thu Nov 30, 2000 7:09 am
Location: The Netherlands
Contact:

Re: Need some electronics advice...

Post by vanekp » Sun May 06, 2018 2:39 pm

I would try the diode across the solenoid and capacitors that where suggested, as the relay already has the protection diode.
so either its the back surge from the solenoid causing a problem or overloading of the 5v when the solenoid is activated.
Peter.

User avatar
lcww1
Posts: 274
Joined: Wed Mar 15, 2017 11:16 pm
Location: Moon Base Alpha
Contact:

Re: Need some electronics advice...

Post by lcww1 » Sun May 06, 2018 2:48 pm

sweh wrote:It doesn't prevent the need for the diode over the solenoid, though :-(
Ye cannae change laws of physics, Jim :lol:

Bat
Posts: 165
Joined: Tue Mar 13, 2018 1:17 pm
Contact:

Re: Need some electronics advice...

Post by Bat » Sun May 06, 2018 10:47 pm

Hi,
The diode next to the relay takes care of the back EMF from the relay coil.
As you have the solenoid coil connected to the same supply as the computer the back EMF is going straight to it. That's why you need a further diode across the solenoid to clamp the back EMF from that.
Basically good practice is to put a diode across any DC coil.
Cheers,
Gavin :)

User avatar
sweh
Posts: 1950
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Need some electronics advice...

Post by sweh » Fri May 11, 2018 12:08 am

So I could buy 1 diode for around $1. Or I can buy 400 for $8.

I now have so many diodes I can rectify the world. (Hmm, maybe all of them together will rectify that Brexit idiocy?).

Hopefully I'll have time this weekend to try it out.
Rgds
Stephen

Bat
Posts: 165
Joined: Tue Mar 13, 2018 1:17 pm
Contact:

Re: Need some electronics advice...

Post by Bat » Fri May 11, 2018 6:41 am

sweh wrote: I now have so many diodes I can rectify the world. (Hmm, maybe all of them together will rectify that Brexit idiocy?).
Unfortunately I don't think there's anything that can sort that out short of sending May to a remote part of Siberia. :lol:
It costs me money every time she opens her mouth!
I too now have a large number of 4k7 and diodes on my desk for the same reason :roll:
Cheers :)

Post Reply