rveitch
4/24/2017 - 3:30 AM

Photon Reed Switch

Photon Reed Switch

//--- Photon Reed Switch ---//

int led = D7; // LED is connected to D0
int reedSwitch = D4; // Reed Switch is connected to D4 and GROUND

// This routine runs only once upon reset
void setup() 
{
  pinMode(led, OUTPUT); // Initialize D7 pin as output for the Photon's LED
  pinMode(reedSwitch, INPUT_PULLUP); // Initialize D4 pin as input with an internal pull-up resistor
}

// This routine loops forever
void loop() 
{
  int reedSwitchState; 

  reedSwitchState = digitalRead(reedSwitch);

  if(reedSwitchState == HIGH) // HIGH = Door is closed
  { // If we push down on the push button
    digitalWrite(led, HIGH);  // Turn ON the LED
  }
  else // LOW = Door is open
  {
    digitalWrite(led, LOW);   // Turn OFF the LED 
  }

}