Pages: [1]   Go Down
Author Topic: OutputPin allways HIGH  (Read 414 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: January 16, 2013, 11:02:16 am by Almisl » Logged

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ;-)
« Last Edit: January 16, 2013, 11:26:12 am by tack » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26273
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

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

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

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26273
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?"
Logged

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

NE PA
Offline Offline
Full Member
***
Karma: 5
Posts: 156
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have your button wired similar to this?

Logged


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

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

You can close this post
Carlos
Logged

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 95
Posts: 4312
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Pages: [1]   Go Up
Jump to: