Lesson: 16 – How to Use Reed Switch with Arduino | DIY Door Security Alarm System
1.7K views on YouTube
Lesson: 16 – How to Use Reed Switch with Arduino | DIY Door Security Alarm System
Hello and Welcome to Electro Nerds Academy, In this video we will learn how to use a Reed Switch with an Arduino, we’ll explain how reed switches work, how to connect them to an Arduino, and how to build a DIY simple door security alarm system using just a reed switch, a push button, and a buzzer.
What you’ll learn in this video:
✅ What is a reed switch
✅ Inner construction of the reed switch and how it works
✅ How to wire a reed switch with Arduino
✅ How to build a DIY Arduino security system for your room or project
👉 Whether you’re a hobbyist, student, or DIY maker, this Arduino project is simple, fun, and highly useful!
Code used in this video:
int buttonState = 0;
int sensorState = 0;
String mode = “de-active”;
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH); // Ensure the buzzer is off initially
}
void loop()
{
buttonState = digitalRead(2);
sensorState = digitalRead(3);
if (buttonState == LOW && mode == “de-active”) {
while (digitalRead(2) == LOW) {
// Wait for the button to be released
}
mode = “active”;
}
if (sensorState == HIGH && mode == “active”) {
digitalWrite(4, HIGH); // Buzzer off
} else if (sensorState == LOW && mode == “active”) {
digitalWrite(4, LOW); // Buzzer on
}
if (buttonState == LOW && mode == “active”) {
while (digitalRead(2) == LOW) {
// Wait for the button to be released
}
mode = “de-active”;
}
}
If you like this video then don’t forget to visit our youtube channel for more such content and be sure to like, subscribe, and hit the bell icon for more Arduino tutorials and DIY electronics projects!
#ArduinoProjects #ElectronicsDIY #arduino #arduinotutorials #embeddedsystems #electronicsforbeginners #electronerdsacademy #arduinoprogramming #circuitbuilding #Arduino #DIYProjects #alarmsystem #magneticswitch #ReedSwitch #roomsecurity