Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Conecting a Reed Switch with Arduino
* AJ Alves (
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
You can’t perform that action at this time.