Arduino problem with sensitivity (24 Volts)

Hello,

I have a problem with the sensitivity of the Arduino Duemilanove board. I have 6 5v inputs declared (switchable by an pulsswitch) on the arduino with 10kOhm pulldown-resistors on it and I have 6 5v outputs. When a input becomes HIGH, a transitors becomes active wich is connect to the specific output. The transistor is switching a 5v relay (1 pin of the relay is connect to the transistor, the other pin is connected to an external 5v power supply). If the relay is active, there wil flow a current of 24V (AC) for valves that I switch. Now the problem:

When I switch 1 of the pulsswitches, the specific output becomes HIGH but somehow other random outputs becoma HIGH also. Is it possible that the 24V (AC) is having to much influence on the inputs of the Arduino? And how can I fix this problem?

I doubt that 24VAC is causing enough noise to falsely switch your transistors.

Can you post a schematic of how you have things wired up? And your sketch as well? Do your input switches make a connection to GND or 5V (I hope it's 5V else I don't see how it will work)? What resistance do you use between the 6 outputs and the transistors? etc. etc.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

Schematic (I hope it makes sense):

My input switches make a connection to 5V.

Explanation:

Input connector, an specific output becomes high on the Adruino -> 1kOhm resistor -> B548C transistor -> 5V relay (parallel a 4n4007 diode) -> output connector witch switches a 24V (AC) wire

I don't see a problem with the schematic (though it's a bit hard to read in places so I may be missing something).

The "random outputs" that become HIGH -- are they also relay (transistor) outputs or just other outputs on the Arduino? Did you remember to configure the outputs as outputs pinMode(pin, OUTPUT);?

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

All of the outputs are relay outputs switched by a transistor. I just checked if the outputs are set as output in my code and they are. The schematic is very simple, so I don't think you are missing anything.

I'm out of ideas then. The last question mark for me is your actual code. Can you show us that?

--
The Aussie Shield: breakout all 28 pins to quick-connect terminals

int mvm = 1; // cointaster
int mv1 = 2; // choiseswitch cabin 1
int mv2 = 3; // choiseswitch cabin 2
int mv3 = 4; // choiseswitch cabin 3

int sch1 = 5; // pulseswitch cabin 1
int sch2 = 6; // pulseswitch cabin 2
int sch3 = 7; // pulseswitch cabin 3

int lamp1 = 8; // indication-led shower 1
int lamp2 = 9; // indication-led shower 2
int lamp3 = 10; // indication-led shower 3

int klep1 = 11; // valve cabin 1
int klep2 = 12; // valve cabin 2
int klep3 = 13; // valve cabin 3

int state1 = LOW; // the current state of the output pin
int reading1; // the current reading from the input pin
int previous1 = LOW; // the previous reading from the input pin

int state2 = LOW; // the current state of the output pin
int reading2; // the current reading from the input pin
int previous2 = LOW; // the previous reading from the input pin

int state3 = LOW; // the current state of the output pin
int reading3; // the current reading from the input pin
int previous3 = LOW; // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.

long time1 = 0; // the last time the output pin was toggled
long debounce1 = 1000; // the debounce time, increase if the output flickers

long time2 = 0; // the last time the output pin was toggled
long debounce2 = 1000; // the debounce time, increase if the output flickers

long time3 = 0; // the last time the output pin was toggled
long debounce3 = 1000; // the debounce time, increase if the output flickers

long starttime1; // starttime coin-detection choiseswitch cabin 1
long starttime2; // starttime coin-detection choiseswitch cabin 1 2
long starttime3; // starttime coin-detection choiseswitch cabin 1 3

long currenttime; // current time of the Arduino

boolean set1; // variable for (true/false) coin-detection cabin 1
boolean set2; // variable for (true/false) coin-detection cabin 2
boolean set3; // variable for (true/false) coin-detection cabin 3

boolean shower1; // variable for (true/false) opening/closing valve on pulseswitch 1
boolean shower2; // variable for (true/false) opening/closing valve on pulseswitch 2
boolean shower3; // variable for (true/false) opening/closing valve on pulseswitch 3

long timetoshower = 180000; //standard showertime (this value + current value on influence of inserting coin)

long showertime1 = 0; // variable for showertime of shower 1 (depends on the amount of coins)
long showertime2 = 0; // variable for showertime of shower 2 (depends on the amount of coins)
long showertime3 = 0; // variable for showertime of shower 3 (depends on the amount of coins)

int mvm_debounce = 1000; // the time to wait to let the user insert more coins
long mvm_time1 = 0;
long mvm_time2 = 0;
long mvm_time3 = 0;

boolean insert_coin1 = false;
boolean insert_coin2 = false;
boolean insert_coin3 = false;

void setup()
{
pinMode(mvm, INPUT);

pinMode(mv1, INPUT);
pinMode(mv2, INPUT);
pinMode(mv3, INPUT);

pinMode(sch1, INPUT);
pinMode(sch2, INPUT);
pinMode(sch3, INPUT);

pinMode(klep1, OUTPUT);
pinMode(klep2, OUTPUT);
pinMode(klep3, OUTPUT);

pinMode(lamp1, OUTPUT);
pinMode(lamp2, OUTPUT);
pinMode(lamp3, OUTPUT);
}

void loop()
{
if (digitalRead(mv1) == HIGH) // mv1
{
insert_coin1 = false;

if (digitalRead(mvm) == HIGH && millis() - mvm_time1 > mvm_debounce)
{
insert_coin1 = true;

if (insert_coin1)
{
showertime1 = showertime1 + timetoshower;
insert_coin1 = false;
}

if (showertime1 > 0)
{
digitalWrite(lamp1, LOW);
digitalWrite(klep1, LOW);
set1 = true;
starttime1 = millis();
insert_coin1 = false;
}

mvm_time1 = millis();
}
}

if (digitalRead(mv2) == HIGH) // mv2
{
insert_coin2 = false;

if (digitalRead(mvm) == HIGH && millis() - mvm_time2 > mvm_debounce)
{
insert_coin2 = true;

if (insert_coin2)
{
showertime2 = showertime2 + timetoshower;
insert_coin2 = false;
}

if (showertime2 > 0)
{
digitalWrite(lamp2, LOW);
digitalWrite(klep2, LOW);
set2 = true;
starttime2 = millis();
insert_coin2 = false;
}

mvm_time2 = millis();
}
}

if (digitalRead(mv3) == HIGH) // mv3
{
insert_coin3 = false;

if (digitalRead(mvm) == HIGH && millis() - mvm_time3 > mvm_debounce)
{
insert_coin3 = true;

if (insert_coin3)
{
showertime3 = showertime3 + timetoshower;
insert_coin3 = false;
}

if (showertime3 > 0)
{
digitalWrite(lamp3, LOW);
digitalWrite(klep3, LOW);
set3 = true;
starttime3 = millis();
insert_coin3 = false;
}

mvm_time3 = millis();
}
}

if (set1)
{
currenttime = millis();

if (currenttime - starttime1 < showertime1)
{
shower1 = true;
digitalWrite(lamp1, HIGH);
}
else
{
digitalWrite(lamp1, LOW);
digitalWrite(klep1, LOW);
state1 = LOW;
shower1 = false;
set1 = false;
insert_coin1 = false;
showertime1 = 0;
}
}

if (set2)
{
currenttime = millis();

if (currenttime - starttime2 < showertime2)
{
shower2 = true;
digitalWrite(lamp2, HIGH);
}
else
{
digitalWrite(lamp2, LOW);
digitalWrite(klep2, LOW);
state2 = LOW;
shower2 = false;
set2 = false;
insert_coin2 = false;
showertime2 = 0;
}
}

if (set3)
{
currenttime = millis();

if (currenttime - starttime3 < showertime3)
{
shower3 = true;
digitalWrite(lamp3, HIGH);
}
else
{
digitalWrite(lamp3, LOW);
digitalWrite(klep3, LOW);
state3 = LOW;
shower3 = false;
set3 = false;
insert_coin3 = false;
showertime3 = 0;
}
}

if (shower1)
{
reading1 = digitalRead(sch1);

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading1 == HIGH && previous1 == LOW && millis() - time1 > debounce1) {
if (state1 == HIGH)
state1 = LOW;
else
state1 = HIGH;

time1 = millis();
}

digitalWrite(klep1, state1);

previous1 = reading1;
}

if (shower2)
{
reading2 = digitalRead(sch2);

if (reading2 == HIGH && previous2 == LOW && millis() - time2 > debounce2) {
if (state2 == HIGH)
state2 = LOW;
else
state2 = HIGH;

time2 = millis();
}

digitalWrite(klep2, state2);

previous2 = reading2;
}

if (shower3)
{
reading3 = digitalRead(sch3);

if (reading3 == HIGH && previous3 == LOW && millis() - time3 > debounce3) {
if (state3 == HIGH)
state3 = LOW;
else
state3 = HIGH;

time3 = millis();
}

digitalWrite(klep3, state3);
previous3 = reading3;

}
}

Is it possible that I have to change the 1KOhm resistor positioned for the transistor into 10KOhms of some other value? I still think that the 24V (AC) has to much influence on the Adruino inputs. I also could add 6 extra relay's wich be switched by the relay's that already are in the circuit so that the 12V (DC) power supply of the Arduino board and relay's and the 24V (AC) are separated. Or is this nonsense?

The schematic shows all the relay diodes connected to a common wire that is not the +5V rail - is that a mistake in the schematic or on the circuit itself?

The diodes are connected to the 5V of the external power supply wich feeds the relays. The external 5V is connected to 1 pin of each relay and to the good side of the diode.

As shown, your diodes are NOT reverse connected across the relay coils, in fact the D6 appears to be completely shortened out at Q6 collector. If your drawing is accurate then it is possible that the relay de=energisation spikes are feeding back into the arduino and causing mayhem.

All of the diodes are connected as shown in this image:

In the schematic are missing a couple of connections to, but the diodes are connected from the pin of the transistor to the 5V, parallel to the relay.

The outputs still become randomly high, the wire from the switch to the arduino has a length of about 5 meters, but I used a 10KOhm pulldown-resistor to decrease the noise or is this not enough due the length of the wire?

5m long wire needs to be shielded and I'd recommend a much lower pull-down for safety, 1k or so at the Arduino end. 100pF across it at the Arduino end might help if its picking up RFI and switching transients. Make sure the high-current parts of the ground wiring don't go through the Arduino and that there is only one point where Arduino ground and relay driver ground meet. You have adequate decoupling on every supply?

In the documentation about digitalpins of the Arduino is 10KOhm named as a common value. But I can change them to 1KOhm if that could help. I also wil place 100pF capacitor over the inputpins (these must be connected over the +5V and the specific input pin?)

Wich one of the schematics do I need?

By the way; what do you mean with: You have adequate decoupling on every supply?

No suggestions anymore?