Pages: [1]   Go Down
Author Topic: Possibly defective board (random triggering of digital inputs)  (Read 359 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bought this Uno a couple months ago, just now trying it out. At first I tried it with MATLAB using the ArduinoIO package and I was seeing some strange behavior so I decided to test it with a proper sketch. I have the following sketch:

Code:
void setup()
{
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(12,INPUT);
}

void loop()
{
  if (digitalRead(12))
  {
    digitalWrite(4,HIGH);
    delay(250);
    digitalWrite(4,LOW);
    digitalWrite(5,HIGH);
    delay(250);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    delay(250);
    digitalWrite(6,LOW);
    digitalWrite(7,HIGH);
    delay(250);
    digitalWrite(7,LOW);
  }
}

I have 4 LEDs hooked up to pins 4-7. Each is in series with a 100 ohm resistor since it is using power from the board. Anyway, the problem itself:

Simply touching bare metal to pin 12 triggers the LED strobing; I have changed pins and it exhibits the same behavior. All I can think is that the board is defective. Simply touching metal to a single pin should not trigger anything. It also seems to just randomly trigger...the LEDs will just start and stop on their own. But there is a clear correlation with touching the selected input pin with wire (wire not connected to anything else...)
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This perfectly normal.  You have left the pin floating and nearby energy is being coupled into the pin.

After:  pinMode(12,INPUT); 
add:  digitalWrite(12, HIGH);

that will turn on the internal pull-up resistor.

For videos on what is going on see this:
http://www.cmiyc.com/tutorials/arduino-pull-ups/
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As you said, that was it completely. Never thought that it would be so sensitive like that.

So, to be clear, I should only see this behavior with things like switches, right? That is to say, I will be using my Uno with an optical sensor. I will make sure and invert the output from the sensor twice so that it's clearly either 0 or 5 volts, but that nearby energy isn't going to make the input fire incorrectly, will it?

Also, does this explain why I was seeing values of approximately 200-300 when reading values from the analog inputs in MATLAB?
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes regarding analog in.  You are making the false assumption (which most people do) that when nothing is connected, you should see 0V.  The problem is that the real world is analog, not digital.  Unless an input pin is pulled in a direction it is easily influenced.

What is an "optical sensor?"
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well for argument's sake, let's just say any sensor that's supposed to return high or low. If it's hooked up directly to something that either feeds it around 5 volts or low (<1.5? volts), it's not going to read high on accident, correct? This gotcha only occurs when used with switches and no contact whatsoever, right?
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was cautious to give a blanket response to "optical sensor" because there are different types of sensors out there.  So if you had a specific example in mind, it is better to address that one.

This gotcha only occurs when used with switches and no contact whatsoever, right?

Yes, this is true.

However, if a sensor features "open-collector" outputs, these work by effectively leaving their output floating.  This allows them to be "pulled-up" to whatever voltage you choose.   

An open-collector output would work like a switch with no contact.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1025
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem is called a "floating" input. Unless you tie it to either +5 or ground through a resistor it is somewhere in the middle. Depends on what signals are in the environment of that pin. Think things like florescent light noise, radio frequency noise (cell phones, wireless devices...) al can put a strong enough random field at an unconnected pin for it to read constantly changing values.

The only time it won't work is when you want that condition to exist, it will then stay at either 0 or 5V...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks everyone for your help/info.
Logged

Pages: [1]   Go Up
Jump to: