ARDUINO REED SWITCH Tutorial – How to use Arduino REED SWITCH

ARDUINO REED SWITCH Tutorial

Hello guys, welcome back to my blog. This tutorial includes what is the Arduino Reed switch and how does works Arduino Reed switch. We can use this reed switch for security systems, alarm systems, automotive projects, and refrigerator doors.

What is the Arduino Reed switch?

The Reed switch is an electromagnetic switch. These are used to control the current in a circuit. This reed switch is made by inserting two or more ferrous tubes into a small glass tube. When a magnetic field is carried near this switch, the ferrous Reeds become magnetic. Then these tubes touch each other. Then electricity begins to flow through this. When the magnetic field is removed again, the reeds return to their previous state. Then the electricity stops flowing. This Reed switch acts as a gate in a circuit. We can easily control this Reed switch by magnetic fields.

There are two types of reed switches.

  1. Normally open Reed switch.
ARDUINO REED SWITCH Tutorial

This includes two tubes made of ferrous material. When a magnet is carried near this, one tube is pulled by the other. Then the circuit is completed and electricity passes through it. When the magnet is removed, it returns to its previous state.

2. Normally closed Reed switch.

ARDUINO REED SWITCH Tutorial

When there is no magnetic field, the tubes touch each other and complete the circuit. Also, when a magnet is placed near this, the tube is repulsed and the circuit is disconnected.

Well, now we will test the functionality of this using the module created by inserting this reed switch. Here we can see 3 main pins. Through this, we can also get a digital signal. The potentiometer here can change the sensitivity of the digital value.

ARDUINO REED SWITCH Tutorial
  • Do — Digital signal can be obtained through this.
  • VCC – This should be given a 5v potential.
  • GND — Ground of this module.

Ok, we will test this sensor with the Arduino UNO board. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect these components using the circuit diagram below.

ARDUINO REED SWITCH Tutorial

Step 3

Now, we will create the necessary program for this. It is as follows.

  • The complete program of this project – Download
/*Reed sensor with Arduino UNO board.
  created by the SriTu Tech team.
  Read the code below and use it for any of your creations.
  
Home Page
*/ #define Sensor 5 #define LED 6 void setup() { Serial.begin(9600); pinMode(Sensor, INPUT); pinMode(LED, OUTPUT); } void loop() { bool value = digitalRead(Sensor); Serial.println(value); if (value == 0) { digitalWrite(LED, HIGH); Serial.println("LED on"); } else { digitalWrite(LED, LOW); } }

Code explanation

Here we first define the  Arduino PINs that connect the sensor and the LED.

#define Sensor 5
#define LED 6

In the void setup, the LED pin is set to the OUTPUT pin and the sensor pin to the INPUT pin.

void setup() {
  Serial.begin(9600);
  pinMode(Sensor, INPUT);
  pinMode(LED, OUTPUT);
}

In the void loop, the sensor value is read and inserted into the Boolean variable called “value”. Also, check that value with an if condition, and if its value is 0 then the LED is active, and if not the LED is off.

off.
void loop() {
  bool value = digitalRead(Sensor);
  Serial.println(value);
 
  if (value == 0) {
    digitalWrite(LED, HIGH);
    Serial.println(“LED on”);
  } else {
    digitalWrite(LED, LOW);
  }
}

Step 4

Finally, select the board and port. Then, upload this code to the  Arduino board.

Now you can check this project using a piece of magnet. The full video guide is below. So we will meet in the next tutorial. Have a good day.

ARDUINO REED SWITCH Tutorial – How to use Arduino REED SWITCH

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *