const int Reed = A0; //define reed switchconst int led = 10;//define led to pin 10int reedVal; //define the reed switch value
void setup() {pinMode(led, OUTPUT); //set led as an outputpinMode(Reed, INPUT);//set reed switch as an inputSerial.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 monitorif (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}}