Enrique
Published

Door Sensor with Arduino Nano Every

Make it play "La Cucaracha" when your door closes

IntermediateFull instructions provided10,651
Door Sensor with Arduino Nano Every

Things used in this project

Hardware components

Arduino Nano Every
Arduino Nano Every
×1
SparkFun Solder-able Breadboard - Mini
SparkFun Solder-able Breadboard - Mini
I will be using a white one.
×1
Buzzer, Piezo
Buzzer, Piezo
×1
9V battery (generic)
9V battery (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
9V Battery Clip
9V Battery Clip
×1
Reed Switch, SPST-NO
Reed Switch, SPST-NO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Door Magnetic Sensor

Open using Fritzing

Door Magnetic Sensor (Screenshot)

This is a screenshot of the Fritzing program.

Code

Door Magnetic Sensor

Arduino
int times = 150;
int times2 = 75;
int times3 = 133;

void setup() {
  // put your setup code here, to run once:
 pinMode(9,INPUT);
 pinMode(LED_BUILTIN,OUTPUT);
 
}

void loop() {
  // put your main code here, to run repeatedly:
 int sensorValue = digitalRead(9);

  if (sensorValue == HIGH){
    digitalWrite(LED_BUILTIN,HIGH);
  // Get ready for... LA CUCARACHA
  tone(8,261,times2);    //First part
  delay(times);
 tone(8,261,times2);
  delay(times);
 tone(8,261,times2*1.5);
  delay(times);
 tone(8,349,times2*2);
  delay(times*1.5);
 tone(8,440,times2);
  delay(times);
 tone(8,261,times2);
  delay(times);
 tone(8,261,times2);
  delay(times);
 tone(8,261,times2);
  delay(times);
 tone(8,349,times2*2);
  delay(times*1.5);
 tone(8,440,times2);
  delay(times*2);
  
 tone(8,349,times2);    //Second part
  delay(times3);
 tone(8,349,times2);
  delay(times3);
 tone(8,329,times2);
  delay(times3);
 tone(8,329,times2);
  delay(times3);
 tone(8,293,times2);
  delay(times3);
 tone(8,293,times2);
  delay(times3);
 tone(8,261,times2*2);
  delay(times*3);
  }else{
    digitalWrite(LED_BUILTIN,LOW);
  }
  delay(10);
}

Credits

Enrique

Enrique

3 projects • 4 followers

Comments