Interference on my digital input - suggested fixes?

The fact that it sounded the alarm as soon as I turned on the lights seems to indicate to me electromagnetic interference rather than faulty switches. Especially as fluorescent lights are notorious for buzzing and carrying on when you first switch them on.

Yes, but the reed switch / magnet is also electro-magnetic ... does the problem go away if you short out (bypass) the switch at the door?

(i.e. test by removing capacitor, bypassing reed switch then switching florescent lighting on/off)

EDIT (re: reed switch failures)

SecurityWorld Magazine
EMI #4 reason for reed switch failure

The Security Industry's Dirty Little Secret
Electro-magnetic interference (EMI) from nearby powerlines and cables or large appliances can disrupt its proper function as well.

Where is 12V coming from? Is it an actual battery? Are you using twisted pair? I know, I know, only 5cm...

You might ground the negative side of the 12V supply, thereby grounding the relay coil.

It's a switch-mode power supply (I think) constantly plugged into a nearby power point.

Hi Nick, did you finally, have resolved your problem?

You must have a free-wheel diode in the relay winding circuit - otherwise its a spark-gap
transmitter. better still use one across the push switch and one across the relay.

Hang on...

15 meters of wire from the 12V power supply to the switch and relay coil. 15 meters.

It is possible that the power supply is going bad and is allowing line transients through, and those are getting coupled through the relay body to the Arduino wiring.

MarkT is correct, you've been burning the switch contacts all these years.

motodaddo:
Hi Nick, did you finally, have resolved your problem?

Yes it is fixed. Doesn't the change (which includes diodes across the wire from the relay which is therefore across the contacts) fix the sparking issue?

Diodes across the relay coil? If not, no.

I got a notification about a response to this thread, namely:

[b]This works[/b]:

The push button is connected to pin d3.
d4 is jumpered to d2

A button press less than about one second does not trigger the interrupt.



[code] #define SWITCH_1 3
#define in_terrupt 2
#define signal 4
#define ledpin 13
unsigned long  time;
unsigned long elapsed_time ;
int val;
volatile boolean interrupt_occured = false;

void setup() 
{
pinMode(SWITCH_1,INPUT);
pinMode(in_terrupt,INPUT);
pinMode(signal,OUTPUT); 
Serial.begin(19200);
attachInterrupt(in_terrupt, switchPressed, FALLING); 
}

void loop() 
{
  

  val= digitalRead(SWITCH_1);
  if (val == LOW) 
    {
       time = millis();
      
           do  
             {
                elapsed_time = millis();
        
         val= digitalRead(SWITCH_1);
             } while (elapsed_time - time < 250 ) ;
             
               if (val == LOW) 
                 { 
                 
                    digitalWrite(signal, LOW);
                    digitalWrite(ledpin, HIGH);
                    delay(500);
                    digitalWrite(ledpin, LOW);
                    delay(500);
                    Serial.println("Switch press");
      &n
 bsp;             interrupt_occured = true;
                    
                 }
                 
     }
  
      if (interrupt_occured)
 { 
 Serial.println("Switch pressed");
 }
      interrupt_occured = false;
      // elapsed_time = millis();
}

void switchPressed()
{  
    interrupt_occured = true;
}

[/code]

I don't have the energy to interpret this crap.

I don't have the energy to interpret this crap.

It's not crap. It's garbage, the digital kind generated by a computer, not a human.

I deleted the post and reposted it where it belonged when I realized that I had mistakenly responded to your link to an older post of yours (Reply#9 of the following post). As you can see , it is no longer here.
I don't know why all that garbage is there. As you can see, it is not in the following post that I reposted:
The real post is here (Reply#20)

@raschemmel - I wasn't attacking what you wrote, only the format in which the forum sends it to me. :slight_smile:

Understood.

I knew that since I had already removed the post, that I couldn't be held accountable for whatever the forum did with the removed post, (especially since the re-post didn't have any garbage). I will confess it could have been avoided if I had not lost tract of where I was while browsing through the thread. When I
saw you link "Look here" and clicked on it I was transported back in time about two weeks. At that point I
think my wife called me for dinner and when I got back I forgot I was in the old post and not the current one. (oops...)

Hi everyone, I'm hoping to get a bit more information here.

My background is hobby level. If this should be a new topic please advise but it seems right on with the discussion here.

Intentions:

Wanted to have control over lights initially and later also power plugs on the walls. Using Arduino Mega. Eventually want to incorporate timers in the code and the like as well as motion detection and light detection. So this is kind of the first step but maybe went a bit too far too fast w the wiring.

I'm in a situation where I definitely have 240v cables running along the same routes as the data lines. The ethernet cables used are not shielded so just twisted pairs. Bad decision but alas not easy to fix.

The house is brick and stone and changing out the wires now would be a huge job. So that is the very last option I want to entertain.

I'm using optically isolated relays running to the Arduino to control the 240VAC to lights - the lights are all LED lights so don't draw a lot of power, which works fine when testing but the cable runs are several meters long and a I say inside brick walls next to power lines which are not yet active.

Those power lines will of course also have the higher capacity devices such as dishwasher, oven, TV etc. can't test those yet as I don't have the grid connected.

I'm concerned about the effect of the AC power on the digital line to the arduino inputs which run in parallel once the power is connected and on after reading articles on the WWW.

As I understand the posts I could end up with seeing up to 240v on the digital line just from the AC running in close proximity to the signal cable.

Currently in the logic on Arduino I'm set up to trigger on pin to ground.

So when I see the pin go to ground or LOW - I change the state of the relay by setting the output pin to the Relay opposite of what it was before (I maintain state) - so if it was HIGH I set it LOW and vice versa. Simply flip flopping.

The switch I'm using is just a momentary switch that connects to ground when pressed through a 100Ohm resistor and when not pressed the pin connects through a 10k resistor to +5v. Since that is the only path left.

If held LOW I wait until I detect a HIGH state and only allow another change after that so I track the previous state detected on the PIN and react only if the last state was HIGH. Seems straightforward.

When I test this with even a 15m cable with a 700W water heater also running along side where we live now I don't find any side effects so far ... but I'm worried after reading some of these articles as it seems I should add some protection to the potential that could arise due to the effect from the 240V AC cables running next to the data wiring plus also possible current.

It seems based on the information out there I could fry the Arduino with this excessive Voltage that could appear on the input PIN. I do have a resistor there.

Also is it likely that I'd have false triggers due to the effect of the oscilating Voltage in the adjacent power lines?

PIN 23 (configured as input) connected to +5V through a 10k Resistor, PIN 23 is also connected to one side of the switch. Other side of switch is connected to ground through 100Ohm resistor.

PIN 22 (configured as output) connected through 100Ohm resistor to 5V relay

The length of wire between the relays and the arduino is only a few centimeters and I measure about 2ma per pin from what I can tell when going to +5V on the Relay board and only about 200uA when going to ground.

thanks very much for any practical insight

There's no denying that running digital lines close to 240V AC lines will result in some inductive coupling. That's physics. I think what needs to be clarified here is that the nature of digital signals and the magnitude (or lack thereof) of the induced noise is such that if you were not aware it was a bad practice, you would never notice the difference. I have built numerous prototypes where digital lines were not far from ac lines, but the engineer said it wouldn't be an issue and it wasn't. Ideally, they should not be right next to each other but if you crunch the numbers, the induced magnetic field drops rapidly beyond 1 cm from the ac line. So unless you plan to wrap your digital lines around the ac lines (not a good idea), I don't think you will see any issues. The change in voltage necessary to change a 0 to a 1 or vice versa is great enough that you probably couldn't get your digital circuit to behave erratically even if you tried. And just for the record, yes, you should start a new post. IMO, this is a dead issue but I'll let you make that call.

Digital wires can see interference from other digital signals with fast changing edges, known as crosstalk. The edges from one can cause spikes of voltage change on the other.
Where you are driving relays and LEDs, which are for all practical purposes static signals, any switching noise the output lines may pick up from other signals would not even be noticed.
On the input side, you have a pullup that is connected to Gnd when the button is pressed. That low needs to exist for a long time for the Arduino to capture it, relatively speaking, so noise there will also not be a problem. The switch is pressed, held low for thousands of microSeconds by your finger, the code eventually samples it with a polled digitalRead most likely. Any noise would then have to be huge to get the grounded signal above 1.5V to not be a LOW and above 3V for definite HIGH, and be there the same thousands of microSeconds for digitalRead in the code to get around to reading it.
The times where crosstalk on signal lines is critical is when it appears on clock lines and causes intended switching to occur in other circuits. If the power lines ran right over the top of the chip on the board, that might be problematic. I assume you could avoid that pretty easily.

Thanks, you're both making me feel a bit better.

I will have temporary power in there tomorrow I'm told so we'll test this out on Saturday - fingers crossed.

Once I have this I hope to extend it with an ethernet bridge so that I can use a browser based application to control things.

Ah the dreams :slight_smile:

Used a 8266 nodemcu for getting a telegram when somebody pressed the doorbell switch. Plenty interference from fluorescent lamps in garage, which switch on with a PIR. Changed wires from door-switch to nodemcu with utp cable, connected white/color wires to gnd. Interference problem solved.