Go Down

Topic: I used 5volts and 0(open) as digital inputs but i got problem with its outputs. (Read 373 times) previous topic - next topic

3kier

Hello Everyone!! im  novice in arduino i really need ur help..
i have 2 digital input pins(pin16 & pin17 actually i need 4)
just to test if it really gonna work.What i did is that
i just give 5volts or high to these pins as input data
but what happened there is that the 2 digitalOutput pins respectively
seems doesnt do to the conditions i gave, it seems it can affect the other condition..
Here is my code...

int sPin =16;
int sPin1 =17;
int ledPin7 =7;
int ledPin6 =6;

void setup(){

  Serial.begin(9600);
 
  pinMode(ledPin7,OUTPUT);
  pinMode(ledPin6,OUTPUT); 
   pinMode(sPin,INPUT);
   pinMode(sPin1,INPUT);
 
   Serial.begin(9600);
   
}

void loop(){

  Serial.println(digitalRead(sPin)); 
  delay(500);
 
 
  int val = digitalRead(sPin);

if (digitalRead(sPin) == LOW )
    { digitalWrite(ledPin7,HIGH);
    }
  if (digitalRead(sPin1) == LOW )
    { digitalWrite(ledPin6,HIGH);
    } 
   
  else
    digitalWrite(ledPin7,LOW);
    digitalWrite(ledPin6,LOW);
     
}

what i really want to do there is that,
   just have  4  inputs(that would be 5volts/0)
   and also give 4  outputs respectively..

i really need ur ideas, suggestions or any other alternatives guyz.. thnx

AWOL

You're not using the built-in pullups, so have you got external ones connected?
"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.

CrossRoads

Try changing these

   pinMode(sPin,INPUT);
   pinMode(sPin1,INPUT);

to

   pinMode(sPin,INPUT_PULLUP);
   pinMode(sPin1,INPUT_PULLUP);

As the pins may be floating as AWOL suggests.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

o_lampe

If you do it with the internal pullups, you might have to reverse your logic, because the input wouldn't change it's state, when you put it on 5V externally. You'd have to switch it to GND instead or use external pull-down resistors instead of the internal pullups.

BTW: the 'else' command is now only working for the lower 'if' routine:

Better put it that way:

if (digitalRead(sPin) == LOW )
    { digitalWrite(ledPin7,HIGH);
    }
  else
    digitalWrite(ledPin7,LOW);

  if (digitalRead(sPin1) == LOW )
    { digitalWrite(ledPin6,HIGH);
    } 
  else
    digitalWrite(ledPin6,LOW);
It's not my fault when my Posts are full of Errors. This stupid autocorrection from my browser is set up for german grammar.

Go Up