Arduino Reed Switch (magnet sensor) with LED
SOURCE CODE:
const int Reed = A0; //define reed switch const int led = 10;//define led to pin 10 int reedVal; //define the reed switch value
void setup() { pinMode(led, OUTPUT); //set led as an output pinMode(Reed, INPUT);//set reed switch as an input Serial.begin(9600); //start the serial port at 9600 bauds
}
void loop() { reedVal = analogRead(Reed); //read the reed switch Serial.println(reedVal); //print the value of the reed switch to the serial monitor if (reedVal <= 0){ digitalWrite(led, HIGH);//if the reed switch senses a magnet turn the led on } else{ digitalWrite(led, LOW);//if it doesn't sense anything turn the led off } }