Connecting Arduino--mains circuit PLUS usb connection damages Arduino

Thread Starter

Mark Flint

Joined Jun 11, 2017
75
I have a mains powered device. I take live and neutral before the device switch and this goes to a 12v transformer. This then goes to a 5v switching regulator that powers my Arduino and a sensor. The chassis of the device is grounded to the mains/house ground.

I was having trouble with a low amp voltage appearing on the chassis so I grounded the 12v transformer to the chassis, which solved the problem. All good so far.

Now when I attach the Arduino to my computer to debug the sensor code I get damage on the Arduino. Not necessarily immediately but turning off and on a few times seems to be enough to cause the damage. (This is my 3rd Arduino!) The damage seems to occur at the raw pin, or VCC if I use that pin.

Here is a rough sketch of what I'm doing. Any pointers would be appreciated.

IMG_2434.JPG
 

Attachments

Last edited:

Papabravo

Joined Feb 24, 2006
12,514
Where is your transformer? Nobody I know connects a regulator to the mains. You seem to have a hole in your knowledge base.

What you should be doing is connect mains to transformer to step down the AC voltage. Rectify the AC voltage, filter it with a capacitor, feed that DC voltage to a regulator and so forth. In a 240 V system I'm not sure what the third wire is actually connected to. AFAIK it could be "EARTH" or it could be something else.
 

Thread Starter

Mark Flint

Joined Jun 11, 2017
75
Where is your transformer? Nobody I know connects a regulator to the mains. You seem to have a hole in your knowledge base.

What you should be doing is connect mains to transformer to step down the AC voltage. Rectify the AC voltage, filter it with a capacitor, feed that DC voltage to a regulator and so forth. In a 240 V system I'm not sure what the third wire is actually connected to. AFAIK it could be "EARTH" or it could be something else.
Sorry - the 12v "regulator" is a 240vac to 12vdc transformer - it's just one of those light ones without much of a coil in it. But it's a smooth DC output. The earth connects to the house ground rod which the mains uses.

Please note: I have edited the original post from "12v regulator" to "12v transofmer".
 

Raymond Genovese

Joined Mar 5, 2016
1,658
I can't say what is causing your problems, but I can't help but think that it could be related to how and when the Arduino is switching power to the board when two voltage sources are present. When the barrel jack and USB are both connected, there is some agreement that the higher voltage will be used for the board. But, you are not using the barrel jack, and instead going through Vin (or Vraw) and the normal choosing between voltages is defeated....I think.

Take a look at this thread http://forum.arduino.cc/index.php?topic=22132.0 along with the Arduino schematic and any searches involving USB+Vin or Vraw - there is a lot on this.

Again, I am not sure that this is the issue that is causing problems, but you may want to look into it.
 

Thread Starter

Mark Flint

Joined Jun 11, 2017
75
I can't say what is causing your problems, but I can't help but think that it could be related to how and when the Arduino is switching power to the board when two voltage sources are present.
Thanks for the input Ramond. I have never had a problem using both 5v on VCC and the USB connection on my laptop. I have a feeling it's something to do with the ground setup. The 12v transformer is referenced to earth (mains ground). This is the same ground going into the 5v regulator, but of course a laptop on battery power is not referenced to earth. I need to debug sensor code while the mains device is running.
 

dl324

Joined Mar 30, 2015
9,147
You need to rectify the AC and put a cap on the regulator input. A cap on the regulator output wouldn't hurt either.

The output of the transformer won't be 12VDC. It's going to be closer to 18V pulsing DC.
 

dl324

Joined Mar 30, 2015
9,147
Sorry - the 12v "regulator" is a 240vac to 12vdc transformer - it's just one of those light ones without much of a coil in it.
There's a difference between a 12VAC transformer, and a 12VDC wall wart type thing.
But it's a smooth DC output.
How do you know? Are you measuring the output with an oscilloscope?
 

Thread Starter

Mark Flint

Joined Jun 11, 2017
75
There's a difference between a 12VAC transformer, and a 12VDC wall wart type thing.How do you know? Are you measuring the output with an oscilloscope?
The transformer is sold as "no noise whatsoever" on the output so I presumed it was smoothed already. I've not checked it on a scope. But caps wouldn't harm any. Do you mean between the positive and negative output from the transformer? I've used the same transformer into the same 5v regulator into the same model of Arduino in other projects that have been running for over 6 months with daily use. However, in the other project I do not connect the transformer negative output to earth ground, that's really the only difference. But for some reason if I don't earth it I end up with a voltage on the device chassis.
 

dl324

Joined Mar 30, 2015
9,147
I think you are referring to the wire that grounds the negative output of the transformer to the device chassis, which runs to earth ground.
You aren't drawing your schematic in the conventional way; that causes confusion. We usually have ground below the positive supply and use a ground symbol.
 

ebp

Joined Feb 8, 2018
2,332
"I was having trouble with a low amp voltage appearing on the chassis so I grounded the 12v transformer to the chassis, which solved the problem."
This needs some more explanation. I don't know what you mean by "low amp voltage." The reason for this voltage needs to be identified because it is quite likely what is killing things. A connection that ties two things together electrically at line frequency could still allow fast transient difference of tens of volts due to inductance.

The 12 V supply will be a switch mode converter. Typically there will be a low-value capacitor between one side of the DC output and some point on the side connected to AC mains. This is done to provide a local path for radio frequency noise to "return" from the output to the input. Normally this isn't a problem, but under the "right wrong" circumstances it might result in excessive voltage between an input on the Arduino and "something."

Another possibility is that neither the 12 V power supply nor the 5 V switcher are very good regulators. Some of the circuits are very crude, especially the "wall wart" types, and though they do a reasonable job of producing the right average output voltage, their transient response can be very poor. This can result in output voltage that deviates substantially from nominal with abrupt changes in load current or input voltage.

What is the Arduino connected to with regard to the line-powered device?
What is being turned on and off? The AC powered device or the Arduino?
 

Thread Starter

Mark Flint

Joined Jun 11, 2017
75
I don't know what you mean by "low amp voltage."

What is the Arduino connected to with regard to the line-powered device?
What is being turned on and off? The AC powered device or the Arduino?
I mean that I noticed a slight tingling as my hand brushed over the chassis. I measured a voltage of approx 80v between the chassis and the negative of the 12v transformer before I earthed it on the chassis (I think it was there, but it's a few weeks ago since I did this). I agree with you that I should find the reason for this, so that's my next task.

The Arduino is connected to two sensors: an air pressure sensor and a liquid level sensor. The Arduino is switching a relay (5v coil) to turn off the AC powered device depending on air pressure and liquid level readings.
 

spinnaker

Joined Oct 29, 2009
7,837
Why are you going through all this trouble trying to design your own power supply? Most people have tons of wall warts that they have collected. If ou don't have any then they can be found at second hand stores. Not found there then there is always Ebay,

I don't understand why you would be destroying Arduinos and risking electrocuting your self when there is an easy answer out there.

The Arduino even has a fairly large range of input voltages to make the wall wart selection easier. I would think at the most you would need to observe polarity, not even sure you would need to to that but I would want to do some research before saying for certain.
 
Last edited:

ebp

Joined Feb 8, 2018
2,332
If you are measuring 80 V (AC?) and can feel a tingle, there is definitely something there that is probably capable of destroying low voltage circuitry.

I have see some switching wall warts that are very unsafe designs and would not pass safety agency requirements for certification. Some Chinese manufactures put fake approval markings on their products.

Here's a test:
With the AC input disconnected and nothing else connected to the output of the 12 V supply, connect the positive to Earth ground through a 1k (anything in the range of 500 ohms to 5k should be OK). Connect the supply to AC mains as usual and measure the voltage across the resistor, both AC and DC. Turn of the power supply and repeat this test with the resistor from the negative to Earth ground.

If you are measuring anything more than a few millivolts across the resistor, calculate what the current would be. If the calculated current is very small, then you could repeat the test with perhaps 50 or 100 ohms - something that will allow more current, but not a very large amount.
 

spinnaker

Joined Oct 29, 2009
7,837
If you are measuring 80 V (AC?) and can feel a tingle, there is definitely something there that is probably capable of destroying low voltage circuitry.

I have see some switching wall warts that are very unsafe designs and would not pass safety agency requirements for certification. Some Chinese manufactures put fake approval markings on their products.
Still far safer than some home brew solution from an inexperienced hobbyist.
 

Thread Starter

Mark Flint

Joined Jun 11, 2017
75
Here's a test:
With the AC input disconnected and nothing else connected to the output of the 12 V supply, connect the positive to Earth ground through a 1k (anything in the range of 500 ohms to 5k should be OK). Connect the supply to AC mains as usual and measure the voltage across the resistor, both AC and DC. Turn of the power supply and repeat this test with the resistor from the negative to Earth ground.
Well. I tore up my board and started from scratch, re soldered it all. Put it into a plastic box. Now I don't get any voltage on the chassis even without grounding the negative of the 12v transformer. Unfortunately I'm no wiser about the error, but it looks like it's solved. I'm out of time today but will test thoroughly tomorrow. If I get errors I'll do this test you suggest. Thank you.
 
Top