Go Down

Topic: Arduino UNO Pin 0 as input isn't working (Read 1 time) previous topic - next topic

Met88

Hi all,
:)
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

Arrch


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.

Met88

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

Arrch

#3
Jan 09, 2013, 12:08 am Last Edit: Jan 09, 2013, 12:11 am by Arrch Reason: 1
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.

retrolefty

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


Met88

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: [Select]
// 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...

Met88

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:

Arrch

#7
Jan 09, 2013, 12:23 am Last Edit: Jan 09, 2013, 12:25 am by Arrch Reason: 1

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?

Met88



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 :D

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

PaulS

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.

Met88


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  :)

PaulS

#11
Jan 09, 2013, 12:36 am Last Edit: Jan 09, 2013, 12:43 am by PaulS Reason: 1
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.

Arrch

#12
Jan 09, 2013, 12:37 am Last Edit: Jan 09, 2013, 12:39 am by Arrch Reason: 1

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).

Met88

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"  :D

everything's clear now!

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

thanks to all!!! 

PaulS

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.

Go Up