Q: Output (pin 9) being switched without input

First of all I’m very new to all this so my forgive me if I don’t quite make sense.

Have been trying to set up a system to keep possums out of the garden, baically PIRs (XC4444) and a tripwire activated switch are the inputs (3.3v, pins 2, 3, 4, 5, 6. The tripwire is written into the code as pirPin5, it just switches 3.3v supplied from the uno to send a 3.3v signal back to pin 6, not sure if this is ok?), the output (pin 9)switches a relay which switches a solenoid valve setting off sprinklers.

It was working properly but all of a sudden it’s just started to continually cycle like it has a switched/HIGH input when it doesn’t, so switching the output (and sprinklers) with no input signal to tell it to switch.

If I physically remove all the input pins it stops. There is only around 50mV to 100mV (inducted/ghost voltage) on any of the input pins and definitely no real voltage (to check voltage I’m measuring back to a ground pin on the uno). If I put 3.3v onto any of the inputs it doesn’t seem to have any affect, it just keeps cycling like it was doing with input pins plugged in but without any of them switched/HIGH. So I remove the input pins it stops, as soon as I plug any of the input pins back in in any order it starts again even with them not switched.

It is like the 50mv - 100mV is causing the uno to see the input pins as written HIGH when it’s not supposed to.

I have rest the board and reloaded the code. It’s also doing this from both USB/computer power and just plugged into a power pack.

My questions, Is my arduino board fried for whatever reason? Or is there somethng wrong with my code that is causing the board to do this? Or are the boards sensitive enough to see milli volts as HIGH, if so can I change this so it has to see at least 3v or similar?

Code I’ve put together is below, is a bit of copy & paste with a bit of my own editing (I’m not sure how necessary the calabration of the sensors is??).

//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin1 = 2;    //the digital pin connected to the PIR sensor's output
int pirPin2 = 3;    //the digital pin connected to the PIR sensor's output
int pirPin3 = 4;    //the digital pin connected to the PIR sensor's output
int pirPin4 = 5;    //the digital pin connected to the PIR sensor's output
int pirPin5 = 6;
int RELAY = 9;



/////////////////////////////
//SETUP
void setup() {
  Serial.begin(9600);
  pinMode(pirPin1, INPUT);
  pinMode(pirPin2, INPUT);
  pinMode(pirPin3, INPUT);
  pinMode(pirPin4, INPUT);
  pinMode(pirPin5, INPUT);
  pinMode(RELAY, OUTPUT);
  digitalWrite(pirPin1, LOW);
  digitalWrite(pirPin2, LOW);
  digitalWrite(pirPin3, LOW);
  digitalWrite(pirPin4, LOW);
  digitalWrite(pirPin5, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
  for (int i = 0; i < calibrationTime; i++) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
}

////////////////////////////
//LOOP
void loop() {
  {

    if (digitalRead(pirPin1) == HIGH) {
      digitalWrite(RELAY, HIGH);
      delay(5000);
      digitalWrite(RELAY, LOW);
      delay(5000);
    }
  }
  {

    if (digitalRead(pirPin2) == HIGH) {
      digitalWrite(RELAY, HIGH);
      delay(5000);
      digitalWrite(RELAY, LOW);
      delay(5000);
    }
  }
  {

    if (digitalRead(pirPin3) == HIGH) {
      digitalWrite(RELAY, HIGH);
      delay(5000);
      digitalWrite(RELAY, LOW);
      delay(5000);
    }
  }
  {

    if (digitalRead(pirPin4) == HIGH) {
      digitalWrite(RELAY, HIGH);
      delay(5000);
      digitalWrite(RELAY, LOW);
      delay(5000);
    }
  }
   {

    if (digitalRead(pirPin5) == HIGH) {
      digitalWrite(RELAY, HIGH);
      delay(5000);
      digitalWrite(RELAY, LOW);
      delay(5000);
    }
  }
}

Thanks for any help.

Moderator replaced color tags with code tags

Please use code tags instead of a colour that gives headaches.

Non connected input pins are floating. That means that the Arduino will read them as high the one time and as low another time.

Are you using external pull-up or pull-down resistors?

sterretje:
Non connected input pins are floating. That means that the Arduino will read them as high the one time and as low another time.

Are you using external pull-up or pull-down resistors?

So I’m using 4 PIRs/motion detectors that are supplied with 12 volts, and send a 3 volt signal when motion is detected. The 5th input is just 3.3 volts supplied from the arduino uno switched by a trip wire switch.

I disconnected the PIRs as I thought one was faulty causing the uno to have the output constantly switched/HIGH. Turns out they are all fine but the output seems to be switched by anything plugged into the input pins, even just a bit of wire that might get a few milli volts on it. Can’t understand why, is it a fault of the arduino uno or me?

Edit:
No resistors besides whatever is in the PIRs.

Inputs are 3v HIGH, 0v LOW, so when disconnected should just appear as LOW. Problem is the uno seems to get a HIGH input reading off just a few milli volts… ? All voltage messurements taken to ground terminal on the uno and everthing is feed from the same power pack.

Can't understand why, is it a fault of the arduino uno or me?

It is you all inputs behave like this on all processors.

Inputs are 3v HIGH, 0v LOW, so when disconnected should just appear as LOW.

No that is not how electronics works. When disconnected the pin acts like an antenna and picks up electromagnetic radiation just like a radio and so can be high or low at any time.

Just like you were told in reply #2.

Grumpy_Mike:
It is you all inputs behave like this on all processors.
No that is not how electronics works. When disconnected the pin acts like an antenna and picks up electromagnetic radiation just like a radio and so can be high or low at any time.

Just like you were told in reply #2.

Ok so I just need to use a screened cable with a drain at one end connected to the negative or grnd and that should fix my problem? Assuming this is what is causing the arduino to see high input through milli volts when the intput is supposed to be low. The PIRs are running on a 12v power pack connected in parallel with the uno (long cable runs so to avoid volt drop).

Screened cable may help, but you need to terminate* whatever cable you use - to suit the signal and interfaces at each end.
The idea is to constrain the signal to stable, deterministic states.
Noise is not desirable in most cases, just like reflections and other crap.

  • not just the plugs themselves, but the impedance and other characteristics of the endpoints.

Newguy18:
Ok so I just need to use a screened cable with a drain at one end connected to the negative or grnd and that should fix my problem? Assuming this is what is causing the arduino to see high input through milli volts when the intput is supposed to be low. The PIRs are running on a 12v power pack connected in parallel with the uno (long cable runs so to avoid volt drop). ...

I don't think a shielded cable will help (much.) When you say "when the intput [sic] is supposed to be low", have you done anything to make it LOW? A pin that not set HIGH is not necessarily LOW (as several people have already said.) If you want to make the pin LOW, then you need to make it low by tying it to ground through a suitable sized resistor. Start with a very high resistance (like maybe half a meg), and reduce it until it works satisfactorily.

ps, as a related aside, an unconnected analog input pin that is neither high nor low is often used as a source of (somewhat) random numbers to use with randomSeed(), because it fluctuates it's state without any apparent cause.

Newguy18:
Ok so I just need to use a screened cable with a drain at one end connected to the negative or grnd and that should fix my problem? Assuming this is what is causing the arduino to see high input through milli volts when the intput is supposed to be low. The PIRs are running on a 12v power pack connected in parallel with the uno (long cable runs so to avoid volt drop).

I think that you first need to find out if the Arduino is still OK. Disconnect everything and run the below for each input.

const byte thePin = 2;
void setup()
{
  Serial.begin(9600);
  pinMode(thePin, INPUT_PULLUP);
}

void loop()
{
  Serial.println(digitalRead(thePin);
  delay(200);  // adjust to needs or omit
}

You should only see '1'.

Next short the pin to ground; you should only see '0'.

Repeat for other pins.

Post back the results.

Newguy18:
Ok so I just need to use a screened cable with a drain at one end connected to the negative or grnd and that should fix my problem?

No that will not fix your problem.

Why do you ask for advice and then ignore what people say? These people have had many years in electronics, probably more years than you have lived. But no you are the expert. If you were the expert you would not have the problems that you have with your simple project.

OP, I was just looking at your first post, and something struck me...

While good hardware practices are mandatory in all projects, perhaps you should also be adding code functionality to recognise simple ‘exceptions’ when signal states are not within limits, or a cable is broken etc...

Fail-safe methodology may. not be important in this instance - other than for simple fault-finding, but building it into your future coding strategy could save a (your) life one day when a sensor fails and the device takes out the user...!

Hi,
Can you post a link to where you bought the PIR units and any data on them.

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

Thanks.. Tom... :slight_smile:

Thanks everyone for helping... think I need to go buy a book on arduino and do a read up, learn about electronics.

In the mean time, I've replaced the signal cable from the PIRs with a screened 1 pair cable (mic cable), grounding the screen at the uno end. I also tidied up everything else, made sure of good segregation and that any unused cores in any of the other cables where also grounded. This seems to have done the trick and got rid of the ghost voltages I was getting, which was apparently enough register as an input.

So it's working fine now and seems reliable. And yeah the project is a bit simple for arduino atm but want to add more in the future, automated watering using RTC and moisture sensor... may need real help for that!

sterretje:
I think that you first need to find out if the Arduino is still OK. Disconnect everything and run the below for each input.

const byte thePin = 2;

void setup()
{
  Serial.begin(9600);
  pinMode(thePin, INPUT_PULLUP);
}

void loop()
{
  Serial.println(digitalRead(thePin);
  delay(200);  // adjust to needs or omit
}



You should only see '1'.

Next short the pin to ground; you should only see '0'.

Repeat for other pins.

Post back the results.

Thanks, saved this for use in the future.

lastchancename:
OP, I was just looking at your first post, and something struck me...

While good hardware practices are mandatory in all projects, perhaps you should also be adding code functionality to recognise simple ‘exceptions’ when signal states are not within limits, or a cable is broken etc...

Fail-safe methodology may. not be important in this instance - other than for simple fault-finding, but building it into your future coding strategy could save a (your) life one day when a sensor fails and the device takes out the user...!

Not familar with how to do this but all ears if you want to give an example... even add an example to the code I posted? Am still at a very basic level when it comes to coding so might take me a while to get to something like this.

ChrisTenone:
I don't think a shielded cable will help (much.) When you say "when the intput [sic] is supposed to be low", have you done anything to make it LOW? A pin that not set HIGH is not necessarily LOW (as several people have already said.) If you want to make the pin LOW, then you need to make it low by tying it to ground through a suitable sized resistor. Start with a very high resistance (like maybe half a meg), and reduce it until it works satisfactorily.

ps, as a related aside, an unconnected analog input pin that is neither high nor low is often used as a source of (somewhat) random numbers to use with randomSeed(), because it fluctuates it's state without any apparent cause.

Thanks, wasn't sure what people were meaning when talking about resistors but this makes sense. If I have more problems will look into this... or maybe I should do it anyway?

TomGeorge:
Hi,
Can you post a link to where you bought the PIR units and any data on them.

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

Thanks.. Tom... :slight_smile:

PIR: Arduino Compatible PIR Motion Detector Module | Jaycar Electronics

Sorry short on time to do pics. PIRs and Uno powered by same power pack (in parallel, done to avoid volt drop). 3v signal from PIRs connected to input pins 2 - 6 on the uno. Pin 9 is an output pin which signals a relay to switch, closing N/O contacts, sending power to a 24vAC solenoid valve turning on sprinklers.

Grumpy_Mike:
No that will not fix your problem.

Why do you ask for advice and then ignore what people say? These people have had many years in electronics, probably more years than you have lived. But no you are the expert. If you were the expert you would not have the problems that you have with your simple project.

If you want a friend just say so! Just because I'm a nice guy :slight_smile:

Ps. It fixed my problem... for now :smiley: I'll pm you later if I need more help.

I found more info about this specific sensor.

It appears that the output is driven high or low - so indeed no pull-up or pull-down resistors needed. The signal will go high if motion is detected, low when not. So far so good.

Behaviour of the system (and the fact that shielded cables do solve it) sounds very much like electromagnetic noise, and a rather weak drive of the signals that can not overcome this noise. Usually this can be filtered out with capacitors, but it depends on the system.

For the fail safe part: you want to ensure that your sprinklers are off unless told to. That means in turn that your inputs must be low unless driven high - even when they're disconnected, floating as it's called. A disconnected input - especially one with a piece of wire attached to it - can easily read high at times. To stop this from happening, add a resistor between the input pin and GND, 10k is a common value for such an application. This way if a wire gets cut, your pin doesn't float and the sprinklers won't be activated randomly.

However with long wires or lots of electrical noise you may need a stronger pull-down, 4k7 or 2k2. The sensor will normally be able to drive the signal high easily even with the stronger pull-down, as it's no more than 1.5 mA of current that runs through those resistors.

If you were to build a security system, you would also add extra measures such as sensing that the wire is cut, or sensing that someone is modifying the circuit tapping the signal (and the current increases).

So it's working fine now and seems reliable.

Sigh!

It is teetering on the edge of malfunctioning if you connect nothing but a screened cable to it. Connect a sensor and as said above that will be fine.