Project tutorial
Door Sensor with Arduino Nano Every

Door Sensor with Arduino Nano Every

Make it play "La Cucaracha" when your door closes

  • 5,494 views
  • 3 comments
  • 11 respects

Components and supplies

Apps and online services

About this project

So, in this proyect, we will make a sensor for your door. We will programe it so that when the door closes, It plays La Cucaracha. We will use a function called tone.

Code

Door Magnetic SensorArduino
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);
}

Schematics

Door Magnetic Sensor
Open using Fritzing
door_magnetic_sensor_ANbE4IL2b7.fzz
Door Magnetic Sensor (Screenshot)
This is a screenshot of the Fritzing program.
Door magnetic sensor fzz   fritzing   vista de protoboard (placa de prototipos) 07 03 2020 16 28 18 pnty7munje

Comments

Similar projects you might like

Touch Sensor and Sound Sensor Controlling AC/DC Lights

Project showcase by Anbumachi

  • 3,488 views
  • 2 comments
  • 7 respects

LED Matrix + Motion Sensor Door Display [Arduino Holiday]

Project tutorial by HeathenHacks

  • 7,109 views
  • 5 comments
  • 24 respects

Easy Motion and Gesture Detection by PIR Sensor & Arduino

Project tutorial by ElectroPeak

  • 67,447 views
  • 13 comments
  • 311 respects

Eye Motion Tracking Using Infrared Sensor

Project tutorial by HomeMadeGarbage

  • 18,739 views
  • 15 comments
  • 89 respects

The Quantified Cactus: An Easy Plant Soil Moisture Sensor

Project tutorial by Jen Looper

  • 11,265 views
  • 3 comments
  • 30 respects
Add projectSign up / Login