Created
June 4, 2018 10:08
-
-
Save elktros/2a174a7a603a11d9fec290e2b25179a8 to your computer and use it in GitHub Desktop.
Code for Interfacing a Reed Switch with Arduino.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int reedPin = 2; | |
const int ledPin = 12; | |
bool switchState = HIGH; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(reedPin, INPUT); | |
pinMode(ledPin, OUTPUT); | |
digitalWrite(ledPin, LOW); | |
} | |
void loop() | |
{ | |
switchState = digitalRead(reedPin); | |
if (switchState == LOW) | |
{ | |
digitalWrite(ledPin, HIGH); | |
Serial.println("Reed Switch is Closed. LED is ON"); | |
} | |
else | |
{ | |
digitalWrite(ledPin, LOW); | |
Serial.println("Reed Switch is Open. LED is OFF"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment