Reed switches

Hello everyone,

please is this conection right?

If I use a port 3, it is ok but with port 2 no. Where is a problem?

Yes, pin 2 and 3 is ok, but 220ohm resistors is overkill.
It burns 2*23mA for nothing if the reed switch is closed.
10k (0.5mA) is low enough.

If the switches are very close to the Arduino, then you don’t need resistors at all.
Just connect the switch between pin and ground.

Use the internal resistors of the chip in pinMode.

pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);

Reverse logic now.
A closed reed reads LOW, and an open reed reads HIGH.

I am sorry I used wrong resistors - I have a 10k resistors. But when I disconnect resistors, my schema don't work.

If I use a program:

Example sketch for SparkFun's Reed Switch
Jim Lindblom @ SparkFun Electronics
May 3, 2016

The reed switch is a two-terminal, magnetically-actuated, normally-open switch.
Connect one end of the switch to ground, and the other to Arduino's D2 pin.

The D2 pin's internal pull-up resistor is used to bias the pin high. When the
switch closes, the pin should go low.

Development environment specifics:
Arduino 1.6.7
const int REED_PIN = 3; // Pin connected to reed switch
const int LED_PIN = 13; // LED pin - active-high

void setup() 
  // Since the other end of the reed switch is connected to ground, we need
  // to pull-up the reed switch pin internally.
  pinMode(LED_PIN, OUTPUT);

void loop() 
  int proximity = digitalRead(REED_PIN); // Read the state of the switch
  if (proximity == LOW) // If the pin reads low, the switch is closed.
    Serial.println("Switch closed");
    digitalWrite(LED_PIN, HIGH); // Turn the LED on
    Serial.println("Switch open");
    digitalWrite(LED_PIN, LOW); // Turn the LED off

Only first sensor is function - first sensor is connected into pin 3 and I use this in program, but when I change in program REED_PIN to 2, the second sensor don't function I think that is problem in my all conection on the breadbord :o


This line expects that NO external resistors will be used, so remove them.

const int REED_PIN = 2; // reed switch connected between pin2 and ground

This should work for pin2. If not, check your wiring, or post a picture. Leo..

And use byte, not int. Unless you're planning pin #s higher than 255.

This seems to be a Sparkfun example that I didn't want to change. It could confuse OP more. Leo..

Mirusena: But when I disconnect resistors, my schema don't work.

Maybe you overlooked that the switch must be connected between pin and ground?

Using one of these?

... or one of these?

Thank you @dlloyd problem was in breadbord I don´t have a power in second part. So when I connect switches closer it is in function :slight_smile: :slight_smile: