Skip to main content

How to use a Reed Switch

What is a Electromagnet?Reed Switch?

The GroveReed ElectromagnetSwitch is a type of magnetic actuatorswitch that becomeschanges magnetizedits whenstate anin electricthe currentpresence passesof througha it.magnetic Whenfield. poweredIt on,contains it can attracttwo small ferromagnetic objectsreeds suchsealed asinside nails,a screws,glass or paper clips.tube. When a magnet comes close, the currentreeds stops,attract iteach immediatelyother losesand itsclose magnetism.the Thiscircuit; makeswhen itthe usefulmagnet is removed, the circuit opens again.

Reed sensors are commonly used in applicationsdoor/window likesensors, speed detection, and magnetic locks,limit robotic grippers, and simple magnetic control experiments.switches.

This Adafruit Magnetic contact switch (door sensor) is also a reed switch.

Wiring

  1. RedOne VCCEnd to 5VPin (Power)2
  2. BlackOne GNDEnd to GND
  3. Yellow SIG to PIN 2

Getting started

TheAfter followinguploading codethe demonstratescode, howyou can use a magnet to controltrigger the Grove Electromagnet by toggling it onswitch, and off using a digital pin.

When the signalbuilt-in pinLED iswill setlight to HIGH, the electromagnet turns on and attracts metallic objects. When set to LOW, it turns off and releases them.up.

const int electromagnetPinREED_PIN = 2; // ElectromagnetPin connected to digitalreed switch
const int LED_PIN = 13; // LED pin 2- active-high

void setup() 
{
  pinMode(electromagnetPin, OUTPUT)Serial.begin(9600);
  // SetSince the other end of the reed switch is connected to ground, we need
  // to pull-up the reed switch pin asinternally.
  OUTPUTpinMode(REED_PIN, Serial.begin(9600)INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);
}

void loop() 
{
  int proximity = digitalRead(REED_PIN); // TurnRead the electromagnetstate ONof digitalWrite(electromagnetPin,the HIGH);switch
  if (proximity == LOW) // If the pin reads low, the switch is closed.
  {
    Serial.println("ElectromagnetSwitch ON"closed");
    delay(2000)digitalWrite(LED_PIN, HIGH); // Turn the electromagnetLED OFFon
  }
  else
  {
    digitalWrite(electromagnetPin,LED_PIN, LOW); Serial.println("Electromagnet// OFF");Turn delay(2000);the LED off
  }
}