Skip to content

Instantly share code, notes, and snippets.

@alvesoaj
Last active August 9, 2018 01:33
Show Gist options
  • Select an option

  • Save alvesoaj/0b6662f5a0cc9b561001e41e98daded0 to your computer and use it in GitHub Desktop.

Select an option

Save alvesoaj/0b6662f5a0cc9b561001e41e98daded0 to your computer and use it in GitHub Desktop.
Conecting a Reed Switch with Arduino
/*
* AJ Alves (aj.alves@zerokol.com)
*/
const int REED_SWITCH_PIN = 3; // Reed Switch Pin
void setup() {
Serial.begin(9600); // Init serial 9600
pinMode(REED_SWITCH_PIN, INPUT); // Set pin as INPUT
}
void loop() {
int rsState = digitalRead(REED_SWITCH_PIN); // Reading pin value
if (rsState == HIGH) {
Serial.println("I can feel the magnet!");
} else {
Serial.println("Where is the magnet?");
}
delay(1000); // Wait for 1 second
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment