Arduino magnetic reed switch module for Sensor Shield
The magnetic reed switch module is a wonderful tool for designers who would like to turn a circuit on and off based on proximity. A digital “high” value is given when approached by magnet in around 1 inch (depends on strength of the magnet)
Building interactive work is as easy as piling bricks, just plug it to our Sensor Shield with a buckled cable, and make it looks professional and neat.
Free buckled cable is included.
Example code to turn off LED when approached by a magnet:
int ledPin = 13; // choose pin for the LED
int inputPin = 2; // choose input pin (for magnetic switch)
int val = 0; // variable for reading the pin status
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare magnetic switch as input
}
void loop()
{
val = digitalRead(inputPin); // read input value
if (val == HIGH)
{ // check if the input is HIGH
digitalWrite(ledPin, LOW); // turn LED OFF
} else
{
digitalWrite(ledPin, HIGH); // turn LED ON
}
}
ข้อมูลเพิ่มเติม www.warf.com