Go Down

Topic: OutputPin allways HIGH (Read 501 times) previous topic - next topic

Almisl

Jan 16, 2013, 04:41 pm Last Edit: Jan 16, 2013, 05:02 pm by Almisl Reason: 1
Hello all,
I'm newest and sorry for my english.
Last week bought an Mega 2560 and try to starter with a simply code.

int Pin7 = 7;
int Pin40 = 0;

void setup() {
 
  pinMode(7,INPUT); 
  pinMode(40, OUTPUT);
  Serial.begin(9600);
}
void loop() {

  Pin7 = digitalRead(7); 
  if(Pin7 == HIGH)
  {
    digitalWrite (40,HIGH);
  }
  else
    {
    digitalWrite (40,LOW);
    }
  delay(100);
  Serial.print("  Pin7= ");
  Serial.print(Pin7);
  Serial.print("\t"); 
  Serial.print("  Pin40= ");
  Serial.print(Pin40);
  Serial.print("\n");
}

my surprise was when I switch on "Pin7" the led works ok but when switch off, the led remains ON during 3 seconds more without any INPUT.

What I do wrong?
Thanks in advance.

Carlos

tack

#1
Jan 16, 2013, 05:23 pm Last Edit: Jan 16, 2013, 05:26 pm by tack Reason: 1
First make your code easy to read and meaningful, so you don't confuse yourself as to what you THINK you're doing.

You have a variable called 'Pin40' and you assign it the value 0.

You then do a a digitalWrite(40,HIGH), turning Pin 40 NOT 'Pin40' (actually Pin 0) on.

Then in your serial output you go back to trying to display the state on your variable 'Pin40', which is actually Pin 0, a pin you never actually set state for!

Probably clearer to call your variables something less confusing, like signalInPin and signalOutPin.

Fix that first and see where your are ;-)

AWOL

Quote
but when switch off, the led remains ON during 3 seconds more without any INPUT.

Sounds like a floating input.
How is the switch wired?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Almisl

Thanks Tack I'm retyping the code.

int Pin40 = 40;

but the led wasn't collaborate :smiley-eek: it's remain On during 3 secons without In signal on Pin52.

AWOL, I'm using a protoboard just to try. But now I'm wired directly on the Arduino. Just one more, if I let the Arduino on the table ( wood table ) and only the led wired on pin 40 ( well, a litle pin post insert on pin 7 )and put my finger on the pin poste, the led blink on and off during a little time, non repetitive blinking.

Perhaps a shield is needed?, and Why you recomended wired in?
I'm use the IOREF for Inputs

The Arduino be supplied with a standard 223vAC to 12vDC 1.5A (18w) conversor

Thanks in advance

Carlos

AWOL

Quote
AWOL, I'm using a protoboard just to try.

No, I meant "What are the connections you have made between the switch, the Arduino, the supply rails and the pullup or pulldown resistors?"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Quick5pnt0

Do you have your button wired similar to this?


Almisl

Oh my god!. Thank you very much. WORKS PERFECT!!!!   :smiley-red: :smiley-red: :smiley-red: :smiley-red:

You can close this post
Carlos

JimboZA

Maybe you haven't found the tutorials yet?

By the way, best thing to do when you are satisfied with the answers to a thread is edit your first post and add the word "SOLVED" at the front of the subject. Don't close the thread.....
My hovercraft is full of eels.

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

Go Up