Pages: [1]   Go Down
Author Topic: Arduino UNO Pin 0 as input isn't working  (Read 1178 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
 smiley
I'm new to this forum, and actually I'm quite new to the Arduino World but I have already realized some little circuit with Arduino UNO and Arduino Mega.

Today I had a problem with Arduino UNO. I realized a board where I installed the arduino with 3 outputs and 6 input.

I created the program and then loaded, everythings seems to be fine when I realize that the variable that reads the pin 0 does never change. So I tried connecting the pin0 to the gnd and then the variable changed.

so the question is, why pin0 is not working if connected to the ground with the usual 10kohm resistor? is it damaged or I should use a different resistor value? I tried with 1kohm but nothing changed...
the other inputs pin works correctly with a 10kohm resistor, I solved the problem moving the input from pin 0 to pin 1


thanks all

bye
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I created the program

What program?

Quote
the variable that reads the pin 0 does never change
.

From what?

Quote
then the variable changed.

To what?

Pins 0 and 1 are used for Serial communication so you cannot use the pins if you are sending serial data, as I suspect you are based on knowing the value of the variables.
Logged

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

sorry, I didn't give you enought information.

I have to move an elettric pump and an idraulic valve, the inputs are for start pump and start valve command, other 2 input are proximity sensors to stop the actions and other 2 inputs are for security things like doors and IR leds.

I'm not using serial data trasmission, I just connected the door to pin 0 (normally closed) so the variable "doors" should be HIGH when doors are closed.  If the doors are open the variable "doors" should be LOW

When the sketch starts I see from a led that "doors" is HIGH and become LOW only if I connect pin0 directly to GND. If I use a resistor it doesn't change. Moving the wire from pin 0 to pin 1 and try to reprogram it demonstrate that the sketch is right.

I just can't understand why pin0 doesn't work...  smiley-roll-sweat

thanks for your help
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Again, what code?

A schematic/wiring diagram would also help a great deal, as well as a link to the datasheets of the devices you are using.
« Last Edit: January 08, 2013, 06:11:37 pm by Arrch » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would need to see a wiring drawing, but you do know that pin 0 is effectively pulled high via a 1K ohm resistor from the USB serial converter chip even if you are not using serial commands? This may be affecting your wiring scheme.

Lefty

Logged

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

I used this basic code to check if it was working, the complete code is very similar, a bit longer and with more inputs


Code:
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:   
    digitalWrite(ledPin, HIGH); 
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

I dont have the last sketch cause I'm using another PC at the moment...
Logged

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

I used the wiring as shown here for this pin



nothing more nothing less

Quote
but you do know that pin 0 is effectively pulled high via a 1K ohm resistor from the USB serial converter chip even if you are not using serial commands? This may be affecting your wiring scheme

mmm no I didn't, maybe this is the problem...
should I change resistor then?  smiley-roll-sweat
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

should I change resistor then?  smiley-roll-sweat
Better off changing the pin...

If the 1K is acting as a pull-up resistor, why try to use a pull-down resistor at all?
« Last Edit: January 08, 2013, 06:25:31 pm by Arrch » Logged

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

should I change resistor then?  smiley-roll-sweat
Better off changing the pin...

If the 1K is acting as a pull-up resistor, why try to use a pull-down resistor at all?

cause I had no idea about it LOL smiley-grin

I already changed the pin from 0 to 1 but I had no idea why it wasn't working. So you never use pin0 as input/output?

I'm curious, which resistor should I use if I want to set it to LOW?

thanks to all, much appreciated
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So you never use pin0 as input/output?
Or pin 1, if you can avoid it. They are the serial port pins.

Your schematic shows that you are not using pin 0, anyway. I'm confused.
Logged

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

Quote
So you never use pin0 as input/output?
Or pin 1, if you can avoid it. They are the serial port pins.

Your schematic shows that you are not using pin 0, anyway. I'm confused.

that's not exactly my schematic, but an example taken from arduino.cc  but it is very similar, just imagine the wire going into pin0 instead of pin 2  smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but an example taken from arduino.cc  but it is very similar
That was done with Fritzing - a free application. It's worth spending a little time learning how to use it, so that you can provide schematics the way YOU wired stuff, when you differ from the suggested way.

Edit: stupid fat fingers and itty bitty keyboard laid out by a moron.
« Last Edit: January 08, 2013, 06:43:22 pm by PaulS » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So you never use pin0 as input/output?

Nope. I have a habit of leaving that for serial communication, even if the project doesn't require it.

Quote
I'm curious, which resistor should I use if I want to set it to LOW?

Well according to the datasheet, 0.2V is the maximum for detecting an input as LOW, so (in theory) the maximum voltage you could use would need to satisfy the equation voltage division equation: 0.2 = 5 * R / ( R + 1K).
« Last Edit: January 08, 2013, 06:39:32 pm by Arrch » Logged

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

forgive me Pauls, I'm just getting into this world and I have to learn a lot of things.

thanks to Arrch too, now I know the rule "dont use pin0 and pin 1"  smiley-grin

everything's clear now!

I have other things to ask, but I want to try solving them on my own first.

thanks to all!!! 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
forgive me Pauls, I'm just getting into this world and I have to learn a lot of things.
Nothing to forgive. Just pencil it in for something to do in the future.
Logged

Pages: [1]   Go Up
Jump to: