Author Topic: using P5 as INPUT - always reads HIGH  (Read 2415 times)

tycen

  • Newbie
  • *
  • Posts: 18
using P5 as INPUT - always reads HIGH
« on: December 20, 2013, 04:31:57 pm »
I'm trying to use P5 as an digital input pin but it continually reads HIGH - even when I plug it directly to GND.  My sketch is below - what am I doing wrong?  Thanks for any help.

const int rebootPin=1;
const int powerOut=3;
const int rebootButton=5;
int var=0;
int rebootButtonState = 0;

void setup() {               
  pinMode(powerOut,OUTPUT);
  pinMode(rebootButton,INPUT);
  pinMode(rebootPin,OUTPUT); 
  digitalWrite(powerOut,HIGH);
  digitalWrite(rebootPin,LOW);
}

void loop() {
rebootButtonState = digitalRead(rebootButton);

if(rebootButtonState = HIGH) {
  digitalWrite(rebootPin,HIGH);
  delay (1000);
  digitalWrite(rebootPin,LOW);
  digitalWrite(powerOut,HIGH);
  delay (1000);
  digitalWrite(powerOut,LOW);
 }

MichaelMeissner

  • Full Member
  • ***
  • Posts: 166
Re: using P5 as INPUT - always reads HIGH
« Reply #1 on: December 20, 2013, 04:37:49 pm »
You are using = which is assignment, when you should be using == for comparison:

Code: [Select]
if(rebootButtonState = HIGH) {

should be:

Code: [Select]
if(rebootButtonState == HIGH) {

tycen

  • Newbie
  • *
  • Posts: 18
Re: using P5 as INPUT - always reads HIGH
« Reply #2 on: December 20, 2013, 04:44:09 pm »
That. exlains. so. much.  Thank you!  I'm just diving into arduino code and have been trying to do something by looking at example after example - I somehow missed that double == as being different from a single one.

Thanks for the quick reply and dead-on answer!