Introduction: Arduino Reed Switch

Hello everyone!

The Reed devices are electronic or electromechanical components that work using the technology of the reed contacts, realized for the first time by the Bell.

The Reed contact switch is a lamina (normally open) which closes in the presence of a magnetic field.

The reed contacts have found use in the production of various types of sensors. There are two modes of use of these contacts:

simple pure contacts, for the detection of a magnetic field; complex equipment, in which the reed contact is used as the transduction element. In this guide I'll show you how to use this switch to turn on an LED.

Step 1: The Circuit

We will need:

- Arduino Uno

- Breadboard (base)

- Wires for links

- Reed Switch

- A resistor 10KOhm

- A resistor 220ohm

- An LED

Once procured components assemble the circuit:

Step 2: The Sketch

Now we can load the sketch on our board.

const int pinSwitch = 12; //Pin Reed

const int pinLed = 9; //Pin LED

int StatoSwitch = 0;

void setup()

{

pinMode(pinLed, OUTPUT); //Imposto i PIN

pinMode(pinSwitch, INPUT);

}

void loop()

{

StatoSwitch = digitalRead(pinSwitch); //Leggo il valore del Reed

if (StatoSwitch == HIGH)

{

digitalWrite(pinLed, HIGH);

}

else

{

digitalWrite(pinLed, LOW);

}

}

Step 3: Video

Comments

author
FlorianE3 (author)2017-02-07

Is there any particular reason why you're not using the internal pull-up resistors of the Arduino and just use the switch as the connection to ground?

author
edcalles (author)2016-11-06

Why does it works backwards to me? If I don't approximate a magnet, the led is on, and if I approximate a magnet, the led is off.

author

Try to reverse HIGH with LOW in the sketch

author

Yes, it works now. Thank you for replying. :)

author
dev.alessiobigini (author)2015-03-13

Yes

author
JRV31 (author)2015-03-13

I published the Beginning Arduino collection I mentioned earlier.

It's available here: https://www.instructables.com/id/Beginning-Arduino...

Do I have your permission to add this to my collection.

author
dev.alessiobigini (author)2015-03-12

Thanks

author
tomatoskins (author)2015-03-12

I love reed switches! This is a wonderful intro to them!

About This Instructable

40,596views

37favorites

License:

More by dev.alessiobigini:3D Printed Tunnel Carpal TutorLEDFader Arduino LibraryHow to Program a LilyPad Without FTDI Converter
Add instructable to: