Back to Parent

//TEST CODE TO CHECK IF HALL EFFECT SENSOR IS WORKING BEFORE PUBLISHING TO CLOUD AND CONNECTING TO IFTTT

int hallPin = A0;
int redPin = D0;
int greenPin = D1;


void setup(){

  pinMode( redPin, OUTPUT);
  pinMode( greenPin, OUTPUT);
  pinMode (hallPin, INPUT);
}

void loop(){
  int hallState = digitalRead( hallPin ); // to store and read state of hall effect sensor

 if( hallState == LOW ) // LOW = vacant, HIGH = occupied
 {
   digitalWrite( redPin, LOW);
   digitalWrite(greenPin, HIGH); // green when vacant

   }
   else{

   digitalWrite( greenPin, LOW);
   digitalWrite(redPin, HIGH); // red when occupied

   }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0