Stragen problem with arduino and relay Board

I am using Arduino Uno and 6 port relay module ( not opto isolated some local made) to operated solenoid valves.

Input method is push button attached with 10k Pull Down resistor to Grnd. Relay operated at +5V. It works perfectly with all push buttons and operate on timers assigned in Sketch to stop after some secs.

But I am encountering strange behavior with relays. Sometimes thy switch on (NC) itself without push button and have to stop manually with stop button. Is it the cause of Isolation or something else. We are using it 12 hrs non stop with approx 300 Start/Stop a day. It happens 10 to 15 times in 12hrs operation that all all or some relays switch on itself. Will opto Isolated relay module solve my problem ? Or something to do with Push button input apart of pull down resistor ??

Some code ref here:

//------------------------------

intervalA = 31000;

if (digitalRead(Button1) == HIGH && FillStatus == 0 ){ FillStatus = 1; ButtonStatus = 1; digitalWrite(Relay1, HIGH); TimerA = millis();

}

if (millis()-TimerA >= intervalA && FillStatus == 1 && ButtonStatus == 1){ FillStatus = 0; ButtonStatus = 0; digitalWrite(Relay1, LOW); }

//-------------------------------------------------------

thanks in advance.

Is TimerA unsigned long?

Always attach your complete sketch using the </> icon in the posting menu.

Yes TimerA is unsigned long…

</>
//const int ws = A0;
const int Button1 = 2;
const int Button2 = 3;
const int Button3 = 4;
const int Button4 = 5;
const int Button5 = 6;

const int Relay1 = 9;
const int Relay2 = 10;
const int Relay3 = 11;
const int Relay4 = 12;
const int RelayBuzz = 13;
//const int Relay6 = 13;

//const int CountRelay6 = 13;

int FillStatus = 0;
int ButtonStatus = 0;
i

long intervalA = 31000;
long intervalB = 32000;
long intervalC = 33000;
long intervalD = 34000;

unsigned long TimerA;
unsigned long TimerB;

void setup() {
// put your setup code here, to run once:
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(RelayBuzz, OUTPUT);
//pinMode(CountRelay6, OUTPUT);

//pinMode(ws, INPUT);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
pinMode(Button5, INPUT);

//Serial.begin(9600);
}

void loop() {

// Buzzer Alarm

// Button 1 is pressed

if (digitalRead(Button1) == HIGH && FillStatus == 0 ){
FillStatus = 1;
ButtonStatus = 1;
digitalWrite(Relay1, HIGH);
TimerA = millis();
}

if (millis()-TimerA >= intervalA && FillStatus == 1 && ButtonStatus == 1){
FillStatus = 0;
ButtonStatus = 0;
digitalWrite(Relay1, LOW);
}

// Button 2 is pressed

if (digitalRead(Button2) == HIGH && FillStatus == 0){
FillStatus = 2;
ButtonStatus = 2;
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
TimerA = millis();
}

if (millis()-TimerA >= intervalB && FillStatus == 2 && ButtonStatus == 2){
FillStatus = 0;
ButtonStatus = 0;
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
}

// Button 3 is pressed

if (digitalRead(Button3) == HIGH && FillStatus == 0 ){
FillStatus = 3;
ButtonStatus = 3;
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, HIGH);
TimerA = millis();
}

if (millis()-TimerA >= intervalC && FillStatus == 3 && ButtonStatus == 3){
FillStatus = 0;
ButtonStatus = 0;
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
}

// Button 4 is pressed

if (digitalRead(Button4) == HIGH && FillStatus == 0 ){
FillStatus = 4;
ButtonStatus = 4;
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, HIGH);
digitalWrite(Relay4, HIGH);
TimerA = millis();
}

if (millis()-TimerA >= intervalD && FillStatus == 4 && ButtonStatus == 4 ){
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
FillStatus = 0;
ButtonStatus = 0;

}

// Stop Button Pressed

if (digitalRead(Button5) == HIGH ){
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
FillStatus = 0;
ButtonStatus = 0;

}

}
</>

Can you post a complete schematic (including a schematic of the relay module)?

Also - can you describe (or better, diagram) how you have things arranged in this control system - that is, where the relays are located relative to the Arduino, where the switches are located relative to everything else, how the wires/cables to the switches and from the relays to the solenoids are arranged, as well as perhaps the location of any other machinery (especially electrical in nature!) in relation to the system.

Without this, we'll simply be making guesses.

Input method is push button attached with 10k Pull Down resistor to Grnd.

pinMode(Button1, INPUT);
This implies there is no PULLUP resistor to +5 volts.

Try this for all PBs
pinMode(Button1, INPUT_PULLUP);
Interenal PULL-UP ----- GPIO pin ---- one side of PB switch ---- other side of PB SWITCH ---- GND

OR
Normally this is what I use:
+5 ------ 10K -------- one side of PB switch AND digital I/P------- other side of PB SWITCH ------- GND

.

:wink:

</> there is an icon on the posting menu.
Click on it and you will be offered code backets.
You paste your copied sketch in the middle of these.

[code ] your sketch text goes here [/code ]

LarryD: pinMode(Button1, INPUT); This implies there is no PULLUP resistor to +5 volts.

Try this for all PBs pinMode(Button1, INPUT_PULLUP); Interenal PULL-UP ----- GPIO pin ---- one side of PB switch ---- other side of PB SWITCH ---- GND

OR Normally this is what I use: +5 ------ 10K -------- one side of PB switch AND digital I/P------- other side of PB SWITCH ------- GND

.

PullDown is there but no Pullup it will try with INPUT_PULLUP

Without proper termination, your input is floating and this can be causing your problems.

All inputs already with 10k Pull Down Resistor to Grnd. Do I still need pullup resistor or Input ?

If you don't have a PULLUP resistor (Internet or External) to +5v how is the input ever going to get to +5v? If it never gets to +5v it sits at an indeterminate level causing your problem, maybe its high maybe it's low maybe you will get false triggering ;)

Another way of connecting the switch is:

+5v ----- one side of the PB switch ------ other side of the switch AND the input pin ---- 10K pulldown---- GND

Take a look here: http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Got it. But pinMode(Button1, INPUT_PULLUP); and 10K pulldown --- GND will work ?? Means Pullup from arduino command and pulldown which is already with 10K ??

Another thing is there any possibility with selecting resistor value less than 10K like 4.7K ? May be 10K is much higher causing problem. I am using longer cable for push Button approx 10ft.

10K - 4.7K should both work. The smaller the resistor will offer a bit more noise immunity.

INPUT_PULLUP and your pulldown will work.

As mentioned earlier, a schematic is needed. It shows us exactely what you have so we offer you better help.

If you have or had no connection of any kind to +5V, your problem will be solved by having one.

.

Heres my very rough schematic buttons connected to pin 3,4,5,6,7 of arduino,

http://postimg.org/image/4fo0ezbr1/

Your 1st post mentions no connection between +5V and the switches. If this is the way you have things wired, no need to have pullups.

Try placing a .1uF capacitor across each resistor to filter out noise.

I am using Arduino Uno and 6 port relay module ( not opto isolated some local made) to operated solenoid valves.

Also, we need to see how these things are wired, attach a schematic. Please include kickback diodes and component values in the drawing.

LarryD: Your 1st post mentions no connection between +5V and the switches. If this is the way you have things wired, no need to have pullups.

Try placing a .1uF capacitor across each resistor to filter out noise.

+5V --- Push Button -- (10K to Ground pullDown) and -- Arduino Input Pin. No Pullup. This is my current scenario. But still getting fake inputs at arduino pin. I applied input_pullup today. Let me observe what happen.

Hi,

What is your application, what are you trying to do and what are you switching with the relays.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

If your sketch is too big, use REPLY rather than QUICK REPLY and it has an attachment facility, so you can post your sketch as an attachment, but try code tags first.

WHY???
You have the project infront of you, we don’t.
You know how it is wired, we don’t.
You know how you are powering the project, we don’t.
You know how you are outputting digital logic to the relays, we don’t.

A picture, a circuit diagram and a sketch is worth a thousand words and can save a thousand ill informed posts.

Tom… :slight_smile:
Sorry but we are up to #16 and still have no schematic, which you should have, if not draw one, the reverse engineering experience may help you locate your problem.

Simple setup. 4 Relays, 5 Push Buttons with 10K to Grnd (PullDown) Each Push button operate sets of relay and 5th to stop all. Relay operate at +5V (at High)

Sometimes it operates by itself without button press.

Unable to attach image tried with icon may be size issue. posting url

http://postimg.org/image/xfatqcv0f/