This is the tutorial explains about how to connect the reed switch with arduino
the simple program for the reed switch
//Turn on LED while reed switch is closed
#define LED 13 //pin for the LED
#define SWITCH 7 //input for REED SWITCH
int val = 0; //used to store input value
void setup() {
pinMode(LED, OUTPUT); //tell arduino LED is an output
pinMode(SWITCH, INPUT); //SWITCH is input
}
void loop(){
val=digitalRead(SWITCH); //read input value and store it
//check whether input is HIGH (switch closed)
if (val==HIGH) {
digitalWrite(LED, HIGH); //turn LED on
} else{
digitalWrite(LED, LOW);
}
}
#define LED 13 //pin for the LED
#define SWITCH 7 //input for REED SWITCH
int val = 0; //used to store input value
void setup() {
pinMode(LED, OUTPUT); //tell arduino LED is an output
pinMode(SWITCH, INPUT); //SWITCH is input
}
void loop(){
val=digitalRead(SWITCH); //read input value and store it
//check whether input is HIGH (switch closed)
if (val==HIGH) {
digitalWrite(LED, HIGH); //turn LED on
} else{
digitalWrite(LED, LOW);
}
}
pls check the video how the reed switch will work
No comments:
Post a Comment