Dirty Ac power activating uno button

Hi guys, I am having a problem with a project I am doing with an Arduino Uno board. I am using the uno board to output a pwm signal to an led driver. It is activated by a button push. The sketch is using the onboard pull up resistor for the push buttons. My problem is if I have the uno powered by a USB wall outlet, or a 9v 1 amp switching power adapter it will activate the button randomly( usually when something in the house switches on) like the fridge or main Ac unit. The only way I can make it work consistently is to use a battery and feed it 5v through the vin pin. It is not on the same circuit as the fridge but the lines run parallel for a bit in the wall.

I have tried using 3 different uno boards, disabling the pull up resistor on the board and using a 10k resistor instead, I'm at a loss. Any ideas? I'm new to this so be gentle if I am doing something horribly wrong.

Sounds more like you have an appliance that needs fixing first !

Other than that have you tried a surge protector as they do tend to also remove some noise.

Hi,

Check that the earth pins on your mains outlets are connected to gnd.
Have you tried plugging in your project to other outlets around the house?

Have you tried putting a 0.1uF Cap from arduino gnd to the input that the switch is connected.
In your code you are reading the switch condition with digitalRead, not analogRead?

It is not on the same circuit as the fridge but the lines run parallel for a bit in the wall.

What does this mean, if you have the switch wire running parallel to the mains wiring then you are asking for trouble.
How long are the switch wires?
Twist the two switch wires around each other, see if it improves the situation.

Tom… :slight_smile:

Or you could use coax..

and try a 2k resistor.

regards

Allan

Does the same behaviour happens when you have the Arduino not connected to the Led driver? If no you might need some kind of isolation.

Another option might be adding a Debounce circuit to this button, but I would investigate it better before hide it.

musskopf:
Does the same behaviour happens when you have the Arduino not connected to the Led driver? If no you might need some kind of isolation.

Another option might be adding a Debounce circuit to this button, but I would investigate it better before hide it.

I tested it with my breadboard and a single led but not for long periods of time.

allanhurst:
Or you could use coax…

and try a 2k resistor.

regards

Allan

Great idea i have some cat 7 and some copper tape to shield the arduino, that will be one thing i will try.

TomGeorge:
Hi,

Check that the earth pins on your mains outlets are connected to gnd.
Have you tried plugging in your project to other outlets around the house?

Have you tried putting a 0.1uF Cap from arduino gnd to the input that the switch is connected.
In your code you are reading the switch condition with digitalRead, not analogRead?
What does this mean, if you have the switch wire running parallel to the mains wiring then you are asking for trouble.
How long are the switch wires?
Twist the two switch wires around each other, see if it improves the situation.

Tom… :slight_smile:

The outlet is a fresh install, the grounds are connected. I have a ground also connected to the arduino ground. I will try the 0.1uf cap to ground and yes it is reading the switch with digitalread. What i meant about the lines being parallel was the ac lines in the wall. The circuit i installed for the arduino and led driver runs parallel with the fridge ac line for about 4 or 5 feet in the wall. The switch wires are on top of the cabinets and are about 5 feet long each, i have 2 switches wired in parallel to pin 6.

Thanks for all of the ideas guys, i will try a few things and report back, thanks again.

I think this would work. Otherwise, opto isolation might be necessary. The RC time constant is 22ms so it should clean up any AC ripple and spikes and also act as button debounce. The 470Ω resistors in series with each pushbutton wire adds additional protection.

Without wanting to hijack the thread, can you explain the schematic? More specifically, why two 470 Ohm resistors instead of one 1K connected to the input; I do understand the RC part.

Also, you show shielding; is that supposed to be connected to ground as well?

Thanks

The outer of the twinax should be grounded at the arduino...

regards

Allan

Hi,
Is there any reason that you can put the Arduino at the button end and have the long wire become the connecting wires to the LED driver?
That way the button leads are as short as possible and not near AC mains wiring.

Tom… :slight_smile:

The image was only to depict any sort of cable.

I used a resistor on the GND wire to add some protection from ground noise or interference. Otherwise, I think a ferrite core would be helpful (cable wrapped through it as many turns as will fit).

An opto isolator would definitely work for this application and might be the simplest solution.

Hi dlloyd.... ok twinax or coax would both be good, as would standard audio screened twisted pair ( twinscreen)..

and of course the twisted pair balances out magnetic interference.

I'd go this way before bothering with optos.

regards

Allan

Yes, good suggestions with the cable types ... that in itself might be enough to resolve the problem. Hopefully we get an update from the OP soon.

Ok it has been a couple days without the lights turning on by themselves. I went the the electronics store and about a surge protector and some cat 7. The surge protector did not work, but the shielded cable seemed to have done it! I used a twisted shielded pair grounded on the arduino side to the button and it's been behaving normally. I also setup a test bed with a second uno a button and led on my breadboard and it have never turned on by itself so it was definitely interference. Thank you guys so much for all of the suggestions! I really appreciate it.

Josh

Bearing in mind you do seem to have some form of spikes I would still stand by having the surge protector in place for peace of mind.

I left the surge protector on. It has a usb pulg and one outlet for the led driver, so its perfect i do not have to use a power adapter for the arduino board.

you could "fix" it in software and say

if(buttonpress >= pressTime) execute desired code;

Hi,

One thing about most noise is that it is fairly fast relative to a required button debounce time. That means the input pin will see a high then a low then a high then a low again over and over which will oscillate fairly fast, and this will last for some time while the noise generating device generates that noise burst.

Considering that this is faster than a normal debounce time, we can use that to help eliminate false triggers. The idea is to detect both high and low levels and reset the debounce time on one or the other so that any opposite state starts the debounce time all over again.

So say we have 50ms debounce time. When the pin goes (say) high, we start the debounce timer. The debounce timer continue to run unless we see a low signal before the time is up. If we see a low signal, we stop the timer, then if we see a high again we restart the timer. So if a noise burst comes in the timer keeps starting and stopping and restarting but never times out the entire 50ms so we never enter the required routine.

Another example, we start the timer at t=0 when we get the first high input, then at t=40ms we get a low signal so we stop the timer, then at t=60ms we get another high so we restart the timer, then at t=110ms we have not yet received a low so we allow the program to enter the routine.

So all we really do is keep starting the timer on a high, and stopping the timer on a low and any time a high comes in we restart the timer. If we reach the 50ms we allow the program to enter the required routine, but if we never reach the 50ms timeout we never enter the routine.

In this way it doesnt matter how long the noise burst is, as long as it is not constant over the entire time of operation. For example, turning a line operated AC fan on and off will generate a noise burst but only during the turn on and turn off, and the signal seen at an input pin will be a noise burst that will have a state that changes from high to low several times within a 50 to 100ms period.

The debounce time may have to be increased somewhat but 50ms should work quite well. Some experimentation obviously will tell all.

j5coat: I left the surge protector on.

That protector was recommended without any numbers. Numbers say why it does nothing. For example it ignores everything on 120 volts until voltage well exceeds 330 volts. How often is your AC spike above 330 volts?

Noise is not a surge - ie single digit or maybe as much as a few tens of volts. Learn how this is made irrelevant in all other electronics. Rip open an electronic power supply to see filters on its front end. Using both inductors and capacitors - not resistors.

Learn about different types of currents - longitudinal and metallic. Your filter must also address common mode currents. Even better is to completely remove that filter from an old power supply. Now you have a front end filter designed by someone who actually knows how electricity works. Who is not so naive as to recommend near zero plug-in protectors.

Of course, best noise elimination starts at the source. More facts to consider if decisions are tempered by numbers.

CAT 7 does not do anything more than CAT 5. Again, too many recommend without first learning what anything does. Had they first learned numbers, then a recommendation would have been obviously bogus.

Another way of getting an engineered solution is to create 5 volts from a wall wart type power supply. Either a well regulate 5 volts wall wart. Or do what most electronics do. Get a poorly regulated wall wart. Then use the single chip power supply regulator to clean and further filter out 'dirty' electricity.

Plenty more answers are possible. Too many to discuss without further details. But this should be obvious. Any answer that is not tempered with perspective (ie numbers) is best ignored. That includes the surge protector, Cat 7, that resistor / capacitor circuit, and even discussions of the various current modes.

We make mistakes to learn. Now learn from mistakes including why a surge protector, et al were tried.

A problem must be first defined before any of these numerically defined solutions can be recommended. What is the incoming and a completely different outgoing path of that offensive current? Without first defining a problem, then any solution is called shotgunning. Shotgunning is done when one has virtually no useful knowledge - as indicated by answers that don't say why with numbers.

Odd that when I checked my surge protector some time ago when I had access to a scope it showed less ripple and a cleaner wave form.

Also odd that I haven't lost any devices due to brown outs drop outs etc etc since installing. I was also under the technical impression that 15 to 25% was the max spike before clamping or activation not almost double which would have fried a lot of devices before it kicks in. Quite a few of the better surge protectors also include extra circuitry for limited noise protection and snubbers.

No I don't have numbers but I do question 330 volt ?

Not all questions need to be defined by numbers either. You may be some form of genius but not everybody is had you cared to read a few more questions in the forums. Many users are clearly brand new to electronics in most forms and don't need a long winded lecture on ohms law etc to work out if a driver needs installing or an accidental reversed voltage popped a regulator.

If I can I will temper my answers based on the questions asked and how they were asked. Had you read the OP was using the USB outlets on the surge protector to also power the project.

I would agree on the CAT 6 / 5 though as for the purpose of this particular shielding either would have sufficed.