NextPCB
Published © CC BY-NC-SA

How to Use a Magnetic Door sensor

N this tutorial we will use one magnetic - contact door sw / sensor and a buzzer for making a "noise" when a door is opened.

BeginnerProtip1 hour14,225
How to Use a Magnetic Door sensor

Things used in this project

Story

Read more

Schematics

Schematics

Code

Code

Arduino
const int buzzer = 3; 
const int sensor = 4;

int state; // 0 close - 1 open wwitch

void setup()
{
	pinMode(sensor, INPUT_PULLUP);
}

void loop()
{
	state = digitalRead(sensor);
	
	if (state == HIGH){
		tone(buzzer, 400);
	}
	else{
		noTone(buzzer);
	}
	delay(200);
}

Credits

NextPCB

NextPCB

21 projects • 45 followers
We share Electrical, Electronics, Power, Robotics, Software, Communication, IOT “Internet Of Things”, based projects

Comments