Arduino Forum

Using Arduino => Project Guidance => Topic started by: cncb on Jul 14, 2012, 11:39 pm

Title: Arduino has some strange reactions
Post by: cncb on Jul 14, 2012, 11:39 pm
Well, needless to say I have some gremlins in the panel that I need to work out. I took the time to go back and print in all of my I/O so that I could get a better idea on the serial bus what it was doing, or what it was being told to do. To keep it simple, on a low voltage, and logic level this works perfectly. With just the arduino and a sainsmart 4 relay board, usb cable, it does exactly what I intend.

The problem however is that in the small control box I also have also have an AC transformer for some solenoids, as well as a large AC contactor, ac bus and I'm switching larger relays with the sainsmart board with AC loads. I did my best to keep everything away from each other but inevitably in a small panel there is only so much you can do to not cross LV/HV wiring.

Anyhow, my first question when reading the serial bus and this happens quite randomly, but the arduino seems to restart for the lack of better terms when I am switching off a high voltage output. But it happens completely randomly and with no rhyme or reason. I did notice however is that the serial bus shows this:



Exhibit A: A snippet of the code it's running including a snippet from the setup to show the serial start

Quote
void setup() {
// Initialize the pins, define digital I/O Pin Usage
  //Inputs
 pinMode(S1, INPUT);
 pinMode(S2, INPUT);
 pinMode(S3, INPUT);
 pinMode(S4, INPUT);
  //Outputs
 pinMode(K1, OUTPUT);
 pinMode(K2, OUTPUT);
 pinMode(K3, OUTPUT);
 pinMode(K4, OUTPUT);
 digitalWrite(S1, HIGH);
 digitalWrite(S2, HIGH);
 digitalWrite(S3, HIGH);
 digitalWrite(S4, HIGH);
 Serial.begin(9600);
 Serial.println("System Initialized");
}


Code: [Select]
// Begin Water Tank 1 Logic
 if (digitalRead(S1) == LOW && curS == 0)
 {
   Serial.println("Water Tank 1 Low");
   digitalWrite(K1, HIGH);
   Serial.println("Solenoid 1 Open");
   delay(3000);
   digitalWrite(K4, HIGH);
   Serial.println("Pump On");
   Serial.println("Filling Water Tank 1");
   curS = S1;  
 }
 else if (digitalRead(S1) == HIGH && curS == S1)
 {
   Serial.println("Water Tank 1 Full");
   digitalWrite(K4, LOW);
   Serial.println("Pump Off");
   delay(3000);
   digitalWrite(K1, LOW);
   Serial.println("Solenoid 1 Closed");
   curS = 0;
 }


Exhibit B: The serial Monitor

Quote
Water Tank 1 Low
Solenoid 1 Open
Pump On
Filling Water Tank 1
Water TùSystem Initialized


^^ What would cause this last line?

What drew me to this was that sometimes when switching one output off, it would turn another one on, but again randomly. When I got my meter out and checked the input driving the output turned on randomly, it wasn't being driven low, even though the output was being driven by the arduino, being high. Weird to say the least, I think these two issues could be related.

Thanks for your help.
Title: Re: Arduino has some strange reactions
Post by: AWOL on Jul 14, 2012, 11:43 pm
Quote
^^ What would cause this last line?

A reset?


Quote
A snippet of the code it's running

That was a snippet of an answer, BTW.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Jul 14, 2012, 11:50 pm
Quote
Weird to say the least, I think these two issues could be related.

Not weird just lack of supply decoupling.
Title: Re: Arduino has some strange reactions
Post by: cncb on Jul 15, 2012, 12:11 am

Quote
^^ What would cause this last line?

A reset?


Quote
A snippet of the code it's running

That was a snippet of an answer, BTW.


That's what I thought, so what could cause the arduino to reset without being told to? Besides loss/lack of appropriate power obviously.
Title: Re: Arduino has some strange reactions
Post by: cmiyc on Jul 15, 2012, 12:41 am

That's what I thought, so what could cause the arduino to reset without being told to? Besides loss/lack of appropriate power obviously.


All your serial prints suggest you could be running out of ram.  Without seeing your full code it is tough to say.  You really should keep your serial.print strings in PROGMEM like this:
Serial.print(F("stays in flash"));
Title: Re: Arduino has some strange reactions
Post by: cncb on Jul 15, 2012, 01:40 am
James,

Thanks for your response. I've enclosed the entire sketch for viewing with the serial prints modified as you suggested. It is at 3,752 bytes in sketch size. I really don't need all these serial prints to be honest, it was more about debugging and trying to see if it would help indicate my issues. As it stands this reset issue is my only one. As far as I can tell the arduino isn't resetting though, is there something else that would cause this? Thanks guys.

Code: [Select]
/*
  Water Controller
*/

// Digital Input Pin Constants
const int S1 = 2;    // Float Switch 1
const int S2 = 3;    // Float Switch 2
const int S3 = 4;    // Manual Switch 1 (Junction Box)
const int S4 = 5;    // Manual Switch 2 (Enclosure)
// Digital Output Pin Constants
const int K1 = 6;    // Relay K1 - Solenoid for Tank 1
const int K2 = 7;    // Relay K2 - Solenoid for Tank 2
const int K3 = 8;   // Relay K3 - Solenoid for Manual Use
const int K4 = 9;   // Relay K4 - Water Pump Relay

// Variables that will Change
int curS;

void setup() {
// Initialize the pins, define digital I/O Pin Usage
   //Inputs
  pinMode(S1, INPUT);
  pinMode(S2, INPUT);
  pinMode(S3, INPUT);
  pinMode(S4, INPUT);
   //Outputs
  pinMode(K1, OUTPUT);
  pinMode(K2, OUTPUT);
  pinMode(K3, OUTPUT);
  pinMode(K4, OUTPUT);
  digitalWrite(S1, HIGH);
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  digitalWrite(S4, HIGH);
  Serial.begin(9600);
  Serial.println(F("System Initialized"));
}

void loop() {
// Begin Water Tank 1 Logic
  if (digitalRead(S1) == LOW && curS == 0)
  {
    Serial.println(F("Water Tank 1 Low"));
    digitalWrite(K1, HIGH);
    Serial.println(F("Solenoid 1 Open"));
    delay(3000);
    digitalWrite(K4, HIGH);
    Serial.println(F("Pump On"));
    Serial.println(F("Filling Water Tank 1"));
    curS = S1; 
  }
  else if (digitalRead(S1) == HIGH && curS == S1)
  {
    Serial.println(F("Water Tank 1 Full"));
    digitalWrite(K4, LOW);
    Serial.println(F("Pump Off"));
    delay(3000);
    digitalWrite(K1, LOW);
    Serial.println(F("Solenoid 1 Closed"));
    curS = 0;
  }
// Begin Water Tank 2 Logic
  if (digitalRead(S2) == LOW && curS == 0)
  {
    Serial.println(F("Water Tank 2 Low"));
    digitalWrite(K2, HIGH);
    Serial.println(F("Solenoid 2 Open"));
    delay(3000);
    digitalWrite(K4, HIGH);
    Serial.println(F("Pump On"));
    Serial.println(F("Filling Water Tank 2"));
    curS = S2;
  }
  else if (digitalRead(S2) == HIGH && curS == S2)
  {
    Serial.println(F("Water Tank 2 Full"));
    digitalWrite(K4, LOW);
    Serial.println(F("Pump Off"));
    delay(3000);
    digitalWrite(K2, LOW);
    Serial.println(F("Solenoid 2 Closed"));
    curS = 0;
  } 
// Begin Manual Switch 1 Logic
  if (digitalRead(S3) == LOW && curS == 0)
  {
    Serial.println(F("Misc. Water Valve Open"));
    digitalWrite(K3, HIGH);
    delay(20);
    curS = S3; 
  }
  else if (digitalRead(S3) == HIGH && curS == S3)
  {
    Serial.println(F("Misc. Water Valve Closed"));
    digitalWrite(K3, LOW);
    delay(20);
    curS = 0;
  }
// Begin Manual Switch 2 Logic
  if (digitalRead(S4) == LOW && curS == 0)
  {
    Serial.println(F("Manual Pump Switch On"));
    digitalWrite(K4, HIGH);
    curS = S4;
    delay(20);
  }
  else if (digitalRead(S4) == HIGH && curS == S4)
  {
    Serial.println(F("Manual Pump Switch Off"));
    digitalWrite(K4, LOW);
    delay(20);
    curS = 0;
  }
}

Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Jul 15, 2012, 02:00 am
Quote
is there something else that would cause this

OK I will try again:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html (http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html)
Title: Re: Arduino has some strange reactions
Post by: cmiyc on Jul 15, 2012, 02:03 am
Probably not a memory issue.  (Keep in mind the "sketch size" reported is PROGMEM and has nothing to do with RAM usage).

Either it is a logic issue, or as Mike keeps pointing out, a power supply de-coupling issue.

Might be helpful to explain what you've done in that area.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Jul 15, 2012, 02:08 am
The point is that he said:-
Quote
To keep it simple, on a low voltage, and logic level this works perfectly. With just the arduino and a sainsmart 4 relay board, usb cable, it does exactly what I intend.

The problem however is that in the small control box I also have also have an AC transformer for some solenoids, as well as a large AC contactor, ac bus and I'm switching larger relays with the sainsmart board with AC loads.

So it works by itself but not in the presence of AC loads.
If that is not a decoupling issue banged to rights then I don't know what is.

It can't be a memory issue because it works correctly when it is by itself.
Title: Re: Arduino has some strange reactions
Post by: cncb on Jul 28, 2012, 10:39 pm
I've been investigating it a bit after you mentioned the power de-coupling.

Here are a few observations I made testing it:

1: The issues only happen (and quite consistently) when I have a solenoid load attached, and with my AC contactor switched. I have 3 switches, 2 of which do the same thing turning on a solenoid and a single contactor for the pump. The third only opens the third solenoid, doesn't require the pump. So it only happens when outputs to the contactor (120VAC) and the solenoid (24VAC) are on at the same time.

2. The problems always arise when the loads are switched OFF, not switched on.

3. I've tried this system with powering on the arduino, and relay board from a completely isolated power source (bench power supply)  from the rest of the system, as well as isolating the arduino from the relay board as well and get the same problems. When switching off the contactor and a solenoid it always causes other false triggers, sometimes only a flash and sometimes running an entire cycle of the sketch.

4. I've also tried isolating, bringing the inputs nearly completely outside the panel to see if it's a noise issue having some of these logic and high voltage conductors in the same wire duct. Also tried isolating bringing the solenoid outputs outside the box when running them and it still has the same problems.

Any input would be greatly appreciated. I'm hoping I can resolve these bugs! Thanks.

Title: Re: Arduino has some strange reactions
Post by: SurferTim on Jul 28, 2012, 10:51 pm
Quote
2. The problems always arise when the loads are switched OFF, not switched on.

That is when the flyback voltage from an inductor will be the greatest. That is what triggers a gasoline engine spark plug to fire. It is not the application of the current to the ignition coil (points closing) that fires the plug, it is the removal of the current (points opening).

Maybe an opto-isolator would help with that.

edit: And a flyback diode. I have also used a small value capacitor in parallel with the control coil to absorb some of the voltage spike.
Title: Re: Arduino has some strange reactions
Post by: cncb on Jul 30, 2012, 02:27 pm
The flyback diode makes sense, but all of my loads except for the LED pilot lights are AC loads (24VAC solenoids, 24VAC Contactor coil), so I can't use a diode on the load. And all of my relays are dry contacts anyways, so they are a bit more simple. I tried isolating the inputs and outputs outside the panel to rule out noise, and also tried powering the arduino/relay board with an independent variable bench supply and still get the same reactions. It's really odd.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Jul 30, 2012, 06:19 pm
Quote
It's really odd.

No it is not odd, it is exactly what is to be expected.

You have given little detail of how things are wired up either by photographs or schematically. You say you have isolated them but clearly you have not. Without details of what you have done we can't tell where you have gone wrong.

When ever you switch a load AC or DC you generate interference. If that interference is too great it will reset your system. You have to reduce that interference at source and also try and keep it out of your circuit with good design and layout.

To see what you can do about AC loads just google:- snubber circuit design
Title: Re: Arduino has some strange reactions
Post by: cncb on Jul 31, 2012, 02:29 am
Oh, don't get me wrong, it's not that I don't expect it; it's just that I am a bit frustrated with not being able to see the obvious just yet. But as always it's part of the challenge. Here is a photo of inside the controller.

From top to bottom:

Top Left: 120 to 24VAC control transformer for solenoids
Top Right: 4 Channel Sainsmart Relay Board
Upper DIN Rail: Protected AC Bus, AC to 12VDC PSU, and a protected DC BUS, followed by slim Finder Interface Relays
Lower DIN Rail: Line Bus including single pole circuit breaker, AC contactor, Motor terminal, and I/O field terminals. Arduino uno with screw shields are on the middle right

On the door is a selector switch, and 4 LED pilot lights for status.

I will post a detailed schematic tomorrow. But if you had any initial thoughts, any help will be appreciated. I will research on the snubber circuit as you referenced, thanks for that.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Jul 31, 2012, 07:39 am
Very neat setup, but I can't see where the extra decoupling is. Supply decoupling needs to be physically close to the device you are trying to decouple. So I was expecting to see a series inductor in the arduino's supply and a capacitor either side.
Title: Re: Arduino has some strange reactions
Post by: cncb on Jul 31, 2012, 05:43 pm
Thanks. There is no decoupling capacitor on the supply input for the arduino, I suppose I should really try that out. What would you suggest is a good type/value capacitor to start with? I'm powering the arduino with 12VDC from the din rail power supply. I've attached the spec sheet for reference, and as well as the schematic. Thanks for your help.

Title: Re: Arduino has some strange reactions
Post by: cncb on Jul 31, 2012, 05:43 pm
Spec sheet on the power supply attached.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Jul 31, 2012, 07:59 pm
Try a 100uF capacitor each side of a 1mH choke.
Also put this on the 5V line out from the arduino to the relay board.
You said earlier you have tried to isolate things, how have you tried to accomplish this?
Title: Re: Arduino has some strange reactions
Post by: cncb on Jul 31, 2012, 10:39 pm
So put a 100uF electrolytic cap on the power supply input (in parallel), as well as the 5VDC out to the relay board the same way? How do I wire the choke in? Thanks for your help.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Jul 31, 2012, 11:45 pm
The way the Pi circuit is shown here.
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html (http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html)
The inductor is in series with the supply with a capacitor to ground on each side of the inductor.
Title: Re: Arduino has some strange reactions
Post by: kf2qd on Jul 31, 2012, 11:57 pm
It would look  like you need to get some RC suppressors for the AC Relays. Whenever you switch off a coil you get are probably goint to get some noise - might get lucky and switch at zero crossing but...

They make RC suppressors that you can get from an industrial suppliers. Check for an Allen-Bradley distributor.

Another possible method is to put some ferite beads on the lines running to the Arduino board. ou are getting induced voltage spikes that are affecting the low voltage side of your control box.
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 01, 2012, 02:50 am

The way the Pi circuit is shown here.
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html (http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html)
The inductor is in series with the supply with a capacitor to ground on each side of the inductor.


Thanks for link and info. You mentioned to use a choke on "either side", what did you mean by that? The schematic on that page shows a choke/inductor wired in series with the + side of the supply to the IC, after the cap. Perhaps you meant on the +5VDC out to the relay board as well.

For the relay board, I take it that it would be best to put this at the input terminals, rather than on the arduino output since there is a decent separation of those points in wire length.

I tried even a preliminary try with a 100uF cap that I had with no noticeable difference yet. I will have to buy some different size chokes to try.

Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 01, 2012, 02:52 am

It would look  like you need to get some RC suppressors for the AC Relays. Whenever you switch off a coil you get are probably goint to get some noise - might get lucky and switch at zero crossing but...

They make RC suppressors that you can get from an industrial suppliers. Check for an Allen-Bradley distributor.

Another possible method is to put some ferite beads on the lines running to the Arduino board. ou are getting induced voltage spikes that are affecting the low voltage side of your control box.


Thank you for the advice. Perhaps that is what happening and why it is a bit random, depending on where it is switched. In regards to the RC suppressor I will investigate it more. I found a good writeup by S+S, http://www.sprecherschuh.com/library/techdocs/get/TECH_Surge_Suppression_109.pdf

I doubt that I will get this accessory for my contactor, as it isn't as high end as the S+S but I could try to replicate it with individual components.

My contactor is a 24VAC coil.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Aug 01, 2012, 09:03 am
Quote
You mentioned to use a choke on "either side", what did you mean by that?

No it was a capacitor on each side of the choke.

The other advice I have given you before is to use a snubber circuit. That is what cncb is saying.
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 05, 2012, 04:25 am
So I did some more testing and tried a few things. I have to buy some ferrite beads/chokes to play with, but I still wanted to isolate the power sources. This time I took it a step further, which I've detailed below.

1. The most apparent problems occur when the solenoid is switched off, however the contactor has some less noticeable issues.

2. Sometimes the AC contactor with no load, being switched "off" resets the arduino or ripples the DC supply enough to reset it. This isn't noticable by eye but by the way it reacts, it drops all outputs in a way (in my limited experience with the arduino) that could only be done by a reset, and prints the serial in a way that could only be done by reset.

3. Simple DC/AC Relay switching causes no apparent problems. (IE: Switch + Relay Board + Relay, no Load)

4. I tried adding an addon Contactor RC Snubber to the coil, no #2 problems with it installed, same as simple LL, LV operation. No resets apparent at all and no half flashes of LEDs on the relay board, it seems perfect.

5. Keeping the RC snubber in, and powering the dc bus from a bench supply on House Circuit 1, AC Transformer on House Circuit 2, and the rest of the power for the box on House Circuit 3, the problems are just as apparent if not worse than before. Sometimes causing up to 3 cycles on the solenoid inadvertently until it appears the arduino gets enough ripple to reset itself and de-energize the outputs, so to speak.

Any ideas on how this tiny AC solenoid load is causing these problems? Even being isolated on completely different circuits? I'm confident that the RC snubber has alleviated the problems on that side, and I even put a considerably larger inductive motor load on the contactor and it works flawlessly. Everything leads back to these darn solenoid valves! I will try the decoupling circuit when I get some of those components in from mouser.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Aug 05, 2012, 10:26 pm
Quote
Even being isolated on completely different circuits?

I think you are not understanding the term isolated. It means that the two systems have no common connections and that includes ground. In order to isolate a controller from the thing it controls you need an isolating circuit. The simplest of these is an optical isolator or opto isolator for short. I don't think you have these and so you can't claim your system is isolated.

Quote
how this tiny AC solenoid load is causing these problems

There are two ways that interference can get from one part of the circuit to the other.
1) Conducted - normally through ground connections or the power supply
2) Radiated - suppress with snubbers and ferrites
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 18, 2012, 05:32 pm
Mike,

I understand what you're getting at but I've isolated the power sources as far as I physically could. So let me describe my latest test results.

1. I isolated the AC transformer power to a precision lab grade power source, and I isolated the DC bus to another BK precision dc power supply. I left off the 120VAC bus because after that, the pump is the only thing needing AC power.

2. With the power sources provided as such the problems are just as apparent. I get misfires on outputs, followed by erratic output switching, it really takes a mind of it's own, all while keeping the input switch closed. I get multiple cycles as though it's latching onto the solenoid until the arduino appears to drop all and flicker the outputs on the way out, which I thought was a reset. However, as far as I can see, the "reset" and I use this term loosely is no way by that I can see caused by a ripple in the dc supply.

3. My earlier statement of this never happening on a LV level is false (just dc relays and arduino, real vanilla). I proved that yesterday and was stunned. I could get 20 program cycles with different inputs (no ac loads) and it works flawlessly. Then randomly it goes through a cycle of bad ones, flickering, misfires, wrong outputs switched etc as described above. Then I will get through a cycle of say 30 button presses, logic works flawlessly. It's completely random, has a mind of its own and has no consistency what-so-ever.

4. What is consistent and quite constant is that adding any AC coil load such as the solenoid or contactor, pump, severely magnifies that issue. So it's obviously two fold, there is a problem with my microcontroller internally and maybe some downstream stuff I need to deal with too. We are talking about the arduino switching one relay, and that relay switching another relay, two sets of dry contacts. The smaller relay only carries the load of a tiny led pilot light load and a relay coil, it's so small it's inconceivable to imagine that is being affected by flyback. The UNO responds in a way that isn't erratic as noise causes, it literally follows it's own logic, or gets screwed up and follows bits and pieces of my logic that I've written. Outputs aren't just fluttered or flashed, or held stuck open, they follow actual routines. Inconsistent routines, but routines none the less. I also tried a different but similar load inductive load, same problems. I also tested with the same value load but a resistive load, same erratic problems.

I've purchased another UNO that I will try Monday, but I'm baffled. Again I love the arduino and I'm not trying to state that it's the source of the problem but I want to rule it out. I'm totally open to suggestions, I think I've tried just about everything on my list.
Title: Re: Arduino has some strange reactions
Post by: Grumpy_Mike on Aug 18, 2012, 09:24 pm
Quote
The UNO responds in a way that isn't erratic as noise causes, it literally follows it's own logic, or gets screwed up and follows bits and pieces of my logic that I've written. Outputs aren't just fluttered or flashed, or held stuck open, they follow actual routines.

Yes that is noise induced erratic behavior. What happens is that, say a register, probably the program counter, gets a corrupt value in it and that sends the code off executing from some other place in the program. When a processor goes wrong it goes wrong in a big way not just fluttering outputs.

Quote
but I've isolated the power sources as far as I physically could

Maybe it is not enough?

Quote
I've purchased another UNO that I will try Monday

It could be you have a faulty processor, but I still think it is a interference problem. What about the case? Is that grounded to a solid mains ground?
What you are seeing is not usual but it is not unique either.
Quote
However, as far as I can see, the "reset" and I use this term loosely is no way by that I can see caused by a ripple in the dc supply.

Often this can be difficult to actually see. You need a good storage scope to catch the impulses. Have you probed round the rest of the circuit to make sure the waveforms are as you expect them to be?

There is only a limited number of things I can suggest remotely, it might be time to get a good consultant in to actually examine your system.

Title: Re: Arduino has some strange reactions
Post by: n3qik on Aug 19, 2012, 07:34 pm
May want to try this:
Add a 10uF cap between the reset pin and ground on the Uno board.
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 19, 2012, 10:39 pm

Quote
The UNO responds in a way that isn't erratic as noise causes, it literally follows it's own logic, or gets screwed up and follows bits and pieces of my logic that I've written. Outputs aren't just fluttered or flashed, or held stuck open, they follow actual routines.

Yes that is noise induced erratic behavior. What happens is that, say a register, probably the program counter, gets a corrupt value in it and that sends the code off executing from some other place in the program. When a processor goes wrong it goes wrong in a big way not just fluttering outputs.

Quote
but I've isolated the power sources as far as I physically could

Maybe it is not enough?

Quote
I've purchased another UNO that I will try Monday

It could be you have a faulty processor, but I still think it is a interference problem. What about the case? Is that grounded to a solid mains ground?
What you are seeing is not usual but it is not unique either.
Quote
However, as far as I can see, the "reset" and I use this term loosely is no way by that I can see caused by a ripple in the dc supply.

Often this can be difficult to actually see. You need a good storage scope to catch the impulses. Have you probed round the rest of the circuit to make sure the waveforms are as you expect them to be?

There is only a limited number of things I can suggest remotely, it might be time to get a good consultant in to actually examine your system.




Mike,

Thanks for the info, still new to this microcontroller tech and appreciate your advice. Other than using a battery to "isolate" the dc bus what would you do for true isolation of the arduino / relay board supply and the solenoid? (In a way that would be theoretically impossible to cause inductive issues)

I think the next thing will be getting in there with a probe and as you said try to capture different problem areas to get a better idea of what it's doing. I feel like I'm so close that I can't give up now.  8)
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 19, 2012, 10:45 pm

May want to try this:
Add a 10uF cap between the reset pin and ground on the Uno board.


From what I think I remember reading in the past this keeps the board from resetting on com port usage? What did you have in mind with this for this situation? Thanks!
Title: Re: Arduino has some strange reactions
Post by: n3qik on Aug 20, 2012, 12:00 am
Long shot, but maybe some of the interference is triggering the auto-reset circuit.
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 21, 2012, 03:29 am
Thanks for the suggestion, I tried it for kicks with the same results. Just the contactor coil even causes arduino resets when switching off the load.

I really want to say it's being reset because the arduino drops the outputs without logic or input to do so and prints this in the serial monitor:


"Water TýSystem Initialized"

It's sort of a half baked between Water Tank, and my serial begin printLN "System Initialized".

What else could cause this to happen if not a ripple in the supply? If the DC supply was perfect with no dip, are there any other things that can cause the uno to show that?
Title: Re: Arduino has some strange reactions
Post by: terryking228 on Aug 21, 2012, 03:39 am
Hi,
These EMC problems are hard to debug!

Here's some possible help from http://arduinoinfo.info

http://arduino-info.wikispaces.com/RelayIsolation

I think you need transient suppression across that solenoid coil.  A MOV (Metal Oxide Varistor) would be good.  A series combination of resistor-capacitor may work.  Try .1 uf (rated at 400V or more) in series with 47 ohms to start...
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 21, 2012, 03:45 am
Also I tried a new arduino for kicks, mostly because I wanted a second one and needed an excuse. Same things but I kind of expected that. My problems still lie within the system as a whole.
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 21, 2012, 03:49 am

Hi,
These EMC problems are hard to debug!

Here's some possible help from http://arduino-info.info

http://arduino-info.wikispaces.com/RelayIsolation

I think you need transient suppression across that solenoid coil.  A MOV (Metal Oxide Varistor) would be good.  A series combination of resistor-capacitor may work.  Try .1 uf (rated at 400V or more) in series with 47 ohms to start...



Thanks for the links. I've tried a redlion suppressor module with the same values you mentioned, in the past and it didn't seem to help at all. The contactor with a suppressor on the coil seemed better, but the water solenoid wasn't phased by it.
Title: Re: Arduino has some strange reactions
Post by: terryking228 on Aug 21, 2012, 04:18 am
Hm....

Wither Ground?  How are you powering Arduino? Is the ground side of Arduino connected to "Building Ground"? How?

If it's just back through a USB cable, that can be trouble. Ground can be bouncing..
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 21, 2012, 04:41 am
12VDC for the arduino and my general 12VDC bus is from an adjustable AC-DC power supply (din rail mount). I am only using a USB connection when trying to de-bug with the serial monitor.
Title: Re: Arduino has some strange reactions
Post by: terryking228 on Aug 22, 2012, 03:04 pm
I think you're down to physical separation between those power / solenoid devices, and possible shielding of the cables that go to Arduino.

Solenoids are, by definition, large inductors and when they are disconnected there is energy that has to go somewhere. MOV / R/C suppression across the solenoid is the usual answer.  Also, you might try switching the solenoid with an optically-isolated zero-crossing TRIAC type solid state relay (like these: http://goo.gl/RbCNb).  But sometimes the inductance of the solenoid make the voltage a current not be in phase. These should work at the 24VAC level OK with most solenoids.

People have beat these problems in lots of automated machinery.  The physical layout and shielding are often important.

Let us know how you're doing!

DISCLAIMER: Mentioned stuff from my own shop...
Title: Re: Arduino has some strange reactions
Post by: cncb on Aug 23, 2012, 02:37 pm

I think you're down to physical separation between those power / solenoid devices, and possible shielding of the cables that go to Arduino.

Solenoids are, by definition, large inductors and when they are disconnected there is energy that has to go somewhere. MOV / R/C suppression across the solenoid is the usual answer.  Also, you might try switching the solenoid with an optically-isolated zero-crossing TRIAC type solid state relay (like these: http://goo.gl/RbCNb).  But sometimes the inductance of the solenoid make the voltage a current not be in phase. These should work at the 24VAC level OK with most solenoids.

People have beat these problems in lots of automated machinery.  The physical layout and shielding are often important.

Let us know how you're doing!

DISCLAIMER: Mentioned stuff from my own shop...


I've tried a solid state relay with little success, a Carlo Gavazzi with zero cross switching. I will try some good probing with my scope in the coming days and see what I can find. Thanks.
Title: Re: Arduino has some strange reactions
Post by: cncb on Sep 04, 2012, 11:34 pm
Another few things that are important to indicate:

- Adding RC Suppressors do help a lot, one across the contactor coil and one each across the solenoid load directly at the load. The frequency of mysterious events drops significantly, almost enough to say screw it and go with the system as is. Yet the false triggers still make me want to find the issue at hand.

- The two ac loads in my system, a contactor and ac solenoids can function what appears to be perfectly if they are used individually. That is to say, with rc suppressors in place, if I only engage the contactor, or only switch the solenoid, one or the other, there are no problems apparent. It's the combination of the two that causes problems. Again, not nearly as much with the RC networks.

I've rewritten the code slightly, and enclosed it below. I've checked the DC supply to the arduino with my scope and only see a clean dc supply with no significant drops/ripple in the supply. I'm open to suggestions on perhaps probing the I/O to see what's actually happening. I would still really like to know how the arduino is having these seemingly random events, even with suppressing the ac loads. Thank you.

Code: [Select]

/*
  Water Controller

This system controls water flow with 1 pump, 3 Water Solenoids, 2 water tanks, 2 water level float switches, and 2 manual switches.
Conditions are set so that the pump is only feeding one source at any given time; to not choke the water supply or overload the pump.
Only the manual switch can activate it's solenoid to bring water in as it is feeding from one of the tanks. If two switches are low
at the same time the system will hold the others until the first one is high again.

Sketch Created July 7, 2012
by Brian
*/

// Digital Input Pin Constants
const int S1 = 2;    // Float Switch 1
const int S2 = 3;    // Float Switch 2
const int S3 = 4;    // Manual Switch 1 (Junction Box)
const int S4 = 5;    // Manual Switch 2 (Enclosure)
// Digital Output Pin Constants
const int K1 = 6;    // Relay K1 - Solenoid for Tank 1
const int K2 = 7;    // Relay K2 - Solenoid for Tank 2
const int K3 = 8;    // Relay K3 - Solenoid for Manual Use
const int K4 = 9;    // Relay K4 - Water Pump Relay
// Delay Times
const int DT1 = 3000;  // Solenoid/Debounce Delay Time
const int DT2 = 20;     // Manual Switch Delay Time for Debounce
// Variables that will Change
int curS;

void setup() {
// Initialize the pins, define digital I/O Pin Usage
   //Inputs
  pinMode(S1, INPUT);
  pinMode(S2, INPUT);
  pinMode(S3, INPUT);
  pinMode(S4, INPUT);
   //Outputs
  pinMode(K1, OUTPUT);
  pinMode(K2, OUTPUT);
  pinMode(K3, OUTPUT);
  pinMode(K4, OUTPUT);
  digitalWrite(S1, HIGH);
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  digitalWrite(S4, HIGH);
  Serial.begin(9600);
  Serial.println(F("System On"));
}

void loop() {
// Begin Water Tank 1 Logic
  if (digitalRead(S1) == LOW && curS == 0)
  {
    Serial.println(F("Water Tank 1 Low"));
    digitalWrite(K1, HIGH);
    Serial.println(F("Solenoid 1 Open"));
    delay(DT1);
    digitalWrite(K4, HIGH);
    Serial.println(F("Pump On"));
    Serial.println(F("Filling Water Tank 1"));
    curS = S1; 
  }
  else if (digitalRead(S1) == HIGH && curS == S1)
  {
    Serial.println(F("Water Tank 1 Full"));
    digitalWrite(K4, LOW);
    Serial.println(F("Pump Off"));
    delay(DT1);
    digitalWrite(K1, LOW);
    Serial.println(F("Solenoid 1 Closed"));
    curS = 0;
  }
// Begin Water Tank 2 Logic
  if (digitalRead(S2) == LOW && curS == 0)
  {
    Serial.println(F("Water Tank 2 Low"));
    digitalWrite(K2, HIGH);
    Serial.println(F("Solenoid 2 Open"));
    delay(DT1);
    digitalWrite(K4, HIGH);
    Serial.println(F("Pump On"));
    Serial.println(F("Filling Water Tank 2"));
    curS = S2;
  }
  else if (digitalRead(S2) == HIGH && curS == S2)
  {
    Serial.println(F("Water Tank 2 Full"));
    digitalWrite(K4, LOW);
    Serial.println(F("Pump Off"));
    delay(DT1);
    digitalWrite(K2, LOW);
    Serial.println(F("Solenoid 2 Closed"));
    curS = 0;
  } 
// Begin Manual Switch 1 Logic
  if (digitalRead(S3) == LOW && curS == 0)
  {
    Serial.println(F("Misc. Water Valve Open"));
    digitalWrite(K3, HIGH);
    delay(DT2);
    curS = S3; 
  }
  else if (digitalRead(S3) == HIGH && curS == S3)
  {
    Serial.println(F("Misc. Water Valve Closed"));
    digitalWrite(K3, LOW);
    delay(DT2);
    curS = 0;
  }
// Begin Manual Switch 2 Logic
  if (digitalRead(S4) == LOW && curS == 0)
  {
    Serial.println(F("Manual Pump Switch On"));
    digitalWrite(K4, HIGH);
    curS = S4;
    delay(DT2);
  }
  else if (digitalRead(S4) == HIGH && curS == S4)
  {
    Serial.println(F("Manual Pump Switch Off"));
    digitalWrite(K4, LOW);
    delay(DT2);
    curS = 0;
  }
}






Title: Re: Arduino has some strange reactions
Post by: dshay on Sep 05, 2012, 05:38 am
ideally when using AC loads you want a device that can time the shut off to the point where the wave makes the zero crossing or choose a DC Solenoid due to all the pain AC loads cause. DCs are easy to rectify.

If nobody has mentioned it yet try winding/twisting the pair of wires going to your solenoid as tightly as possible (if you do not have enough slack to do so run new longer wires) chock the wires up in a cordless drill and spin. This will have a magnetic cancelling effect that will help impede the inductive spike, while you're at it loop this wire through a couple ferrite beads.

To repeat what others are saying, separate your power supplies and keep your signal and power wires as isolated from each other as possible.

and this app note repeats what others have been saying, coil suppression is a common application in relays because the same voltage causes arcing and welds relay contacts shut.

http://relays.te.com/appnotes/app_pdfs/13c3311.pdf