Friday, January 22, 2010

Simple Reed Switch Circuit

Ive taken the code from the adruino tutorials-
Button: use a pushbutton to control an LED.
I just replaced the Push Button switch with a Reed Switch i.e. a magnetic switch. The contacts close and complete the circuit when a magnet is brought near it.

Simple Reed Switch Adruino Code

// set pin numbers:

const int buttonPin = 3; // the number of the reedswitch pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the reedswitch pin as an input:
pinMode(buttonPin, INPUT);

void loop(){
// read the state of the reedswitch value:
buttonState = digitalRead(buttonPin);

// check if the reedswitch is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
else {
// turn LED off:
digitalWrite(ledPin, LOW);

No comments:

Post a Comment