Doormat Activated Automatic Alarm System

by aceofspader in Circuits > Arduino

103 Views, 1 Favorites, 0 Comments

Doormat Activated Automatic Alarm System

done.jpg
1200px-All_Pressure_Plates.png

Ever wondered if something like a Minecraft pressure plate alarm where if you step on a seemingly normal doormat an alarm goes off would be possible in real life? I did, which is exactly why I started working on this project. I wanted to see if I could bring one of my favourite childhood games to live by replicating an iconic part of the game: the pressure plate.

Supplies

Needed materials for the prototype:

  1. Arduino Mega
  2. Breadboard
  3. Male/Female jumper wires
  4. Male/Male jumper wires
  5. Piezo buzzer
  6. Doormat
  7. Velostat (one sheet for each sensor)
  8. Conductive material like aluminium foil
  9. 10k Ohm resistors (one for each sensor)


Optional materials:

  1. Toggle switch (ON - OFF)
  2. Led switch (ON - OFF)
  3. Paint
  4. Paintbrushes
  5. Stickers


Needed materials soldering:

  1. Soldering iron
  2. Solder (either lead-free or not lead-free)
  3. PCB board
  4. Steelwool (to clean your soldering iron)


Needed materials 3D printing:

  1. 3D model for your box
  2. 3D model for your lid
  3. 3D printer
  4. Filament

Choosing Your Tunes

Picture1.png

The first step, before we do anything else is making sure music will be able to play when someone steps on the doormat! To do this, we first need to program in some music. For the prototype I used a piezo buzzer, but you can use any other sound producing arduino component to achieve this.


For my prototype I started with just one song, this song was "Carpe Diem" by Joker Out, but you can use any song you like for this! You will be hearing this song a lot during testing, so make sure it's a song or tune you actually like.


You can read sheet music and convert them into song manually like I did, but if your song has a midi file, you can use a midi to arduino tone converter and skip a huge part of the heavy work. Using this method, you don't need the functions that play the note. You can just drop whatever the converter gives you into an if-statement. Please do note that I have not tested the converter , so I cannot promise the quality is any good.


Midi to arduino Tone converter:

https://arduinomidi.netlify.app/


To test the music, I made use of a button that plays my chosen song when pressed. The picture above is the setup for this part of the project.

I also attachted a pressure sensor to potentially test with that component, but I didn't end up using it.


This is the code I used to program in Carpe Diem

int soundPin = 8; // Pin buzzer is connected to

// Notes for Carpe Diem
// https://musescore.com/user/36962362/scores/11076154 ,,, music read by me. So if it is out of tune, it is because my music theory skills suck
#define NOTE_A3 216
#define NOTE_B3 246
#define NOTE_CSHARP 277

// Duration of the notes
const int noteHalf = 1000;
const int noteQuarter = 500;
const int noteEight = 250;
const int noteWhole = 2000;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(soundPin, OUTPUT);
  pinMode(4, INPUT);
  pinMode(A0, INPUT);
}


void loop()
{
  int buttonState = digitalRead(4);
    }

    //Plays Carpe Diem if button is pressed
    if (buttonState == 1)
    {
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_B3);
      playEight(NOTE_A3);
      playQuarter (NOTE_B3);
      playHalf (NOTE_CSHARP);
      delay(2250);
    }


  }
}

// This part of the code makes sure every note you play lasts the same time

void playHalf(int frequency) {
  tone(soundPin, frequency, noteHalf);
  delay(noteHalf + 50);
  noTone(soundPin); // Stops note
  delay(50); // Adds a delay for the following note
}


void playQuarter(int frequency) {
  tone(soundPin, frequency, noteQuarter);
  delay(noteQuarter + 50);
  noTone(soundPin); // Stops note
  delay(50); // Adds a delay for the following note
}


void playEight(int frequency) {
  tone(soundPin, frequency, noteEight);
  delay(noteEight + 50);
  noTone(soundPin); // Stops note
  delay(25); // Adds a delay for the following note
}


void playWhole(int frequency){
  tone(soundPin, frequency, noteWhole);
  delay(noteWhole + 50);
  noTone(soundPin); //Stops note
  delay(50); //Adds a delay for the following note
}


Now, assuming that you connected everything correctly and didn't mess up the code, when you press your button, you should hear your song playing! Good job! You have succesfully completed the easy part of this project!

Making the Pressure Sensor

image00001.jpeg
image00002.jpeg

For this step, you will need your velostat and the conductive material of your chosing. Velostat is a material that is very sensitive to pressure, it is practically a big resistor that allows more electricity to pass through when pressure is applied, which means it is perfect for making pressure sensors such as ours!


For this project I didn't modify the velostat. I just used it right out of the package, as it was already the perfect size for this project. I ended up making 2 sensors, which means I used two sheets of velostat in total, but you can of course use as many or as little sensors as you wish.


To make the sensor, I sandwiched the velostat between two pieces of aluminium foil. I made the pieces of aluminium foil smaller than the velostat to make sure the two sides of the sensor wouldn't be able to touch one another. One sheet of aluminium foil was on the "front" of the velostat, and the other on the "back" of the velostat. Make sure the layers are conductive material -> velostat -> conductive material or your sensor will not work. Trust me, I made this mistake before!


Then, after my sensors were done I taped a wire to both sides of the velostat, making sure it touches the aluminium foil. This makes sure we can actually attach our sensors to our Arduino.

Connecting the Pressure Sensor With Arduino

velostatV3.png

So you made your Velostat pressure sensor! Great! Now it's time to connect it with Arduino.


To connect the pressure sensor, you connect one end of the sensor to the 5V pin of your arduino. The other end should be connected to an analog pin on your Arduino. Then, connect your 10k Ohm resistors from the same analog pin to ground. Make sure you do this for every sensor.


Now that your sensor is connected with your Arduino, it's time to add code so we can actually use the sensor we made.


This is the code I used. Please note that this is yet again with the song I choose at the beginning of the project: Carpe Diem by Joker Out. If you choose to use a different song, you will need to replace my code for Carpe Diem with the code you either wrote yourself or got through the Midi to Arduino tone converter.


int soundPin = 8; // Pin buzzer is connected to
const int numberSensors = 13; // Number of velostat pressure sensors
const int pressurePins[numberSensors] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12}; // Analog pins connected to the sensors
const int threshold = 500; // Decides when your alarm will go off

// Notes for Carpe Diem
// https://musescore.com/user/36962362/scores/11076154 ,,, music read by me. So if it is out of tune, it is because my music theory skills suck
#define NOTE_A3 216
#define NOTE_B3 246
#define NOTE_CSHARP 277

// Duration of the notes
const int noteHalf = 1000;
const int noteQuarter = 500;
const int noteEight = 250;
const int noteWhole = 2000;

void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 pinMode(soundPin, OUTPUT);
 pinMode(4, INPUT);
 pinMode(A0, INPUT);
}

void loop()
{
 int buttonState = digitalRead(4);
 int sensorValue = analogRead(A0);
 Serial.println(sensorValue);

//Makes sure you can read the values in the serial monitor
 for (int i = 0; i < numberSensors; i++) {
  int pressureValue = analogRead(pressurePins[i]); // Reads the analog value from the sensor
  Serial.print("Sensor ");
  Serial.print(i);
  Serial.print(": ");
  Serial.println(pressureValue);        // Prints the sensor value to the serial monitor

  //Plays "Carpe Diem" by Joker Out if threshold gets surpassed
  if (pressureValue > threshold) {
   playEight(NOTE_CSHARP);
   playEight(NOTE_CSHARP);
   playEight(NOTE_CSHARP);
   playEight(NOTE_CSHARP);
   playEight(NOTE_CSHARP);
   playEight(NOTE_B3);
   playEight(NOTE_A3);
   playQuarter (NOTE_B3);
   playHalf (NOTE_CSHARP);
   delay(2250);
  }

  delay(100); // Delay for stability

  // Plays music if button is pressed
  if (buttonState == 1)
  {
   playEight(NOTE_CSHARP);
   playEight(NOTE_CSHARP);
   playEight(NOTE_CSHARP);
   playEight(NOTE_CSHARP);
   playEight(NOTE_CSHARP);
   playEight(NOTE_B3);
   playEight(NOTE_A3);
   playQuarter (NOTE_B3);
   playHalf (NOTE_CSHARP);
   delay(2250);
  }


 }
}

void playHalf(int frequency) {
 tone(soundPin, frequency, noteHalf);
 delay(noteHalf + 50);
 noTone(soundPin); // Stops note
 delay(50); // Adds a delay for the following note
}

void playQuarter(int frequency) {
 tone(soundPin, frequency, noteQuarter);
 delay(noteQuarter + 50);
 noTone(soundPin); // Stops note
 delay(50); // Adds a delay for the following note
}

void playEight(int frequency) {
 tone(soundPin, frequency, noteEight);
 delay(noteEight + 50);
 noTone(soundPin); // Stops note
 delay(25); // Adds a delay for the following note
}

void playWhole(int frequency){
 tone(soundPin, frequency, noteWhole);
 delay(noteWhole + 50);
 noTone(soundPin); //Stops note
 delay(50); //Adds a delay for the following note
}


This is the part where you can really get creative! For example, you could create another if statement and make it play another tune based on how much pressure is applied. Or you could meassure the base pressure and make an anti-theft function, there is no limit to the creative little things you can add to this!

Test Your Pressure Sensor

Now that your sensor is connected to your Arduino, you can get on to testing and adjusting. If your pressure sensor is too sensitive, you can up the threshold so it requires more imput in order to make your song play. If your pressure sensor is not sensitive enough, you can lower the threshold.


If everything is working the way to, congrats! You have done everything you needed to do in order to get the mat to work! If you are satisfied, you can stop now and be proud of your work, all the steps following are optional.

Adding ON-OFF Button

47f0163d79f901a9210dd40a721906cd5e9ff1a0.jpeg
ONOFFV3.png

I wanted to be able to choose when the doormat works, so I can turn it off when it starts to bother me. For this, I used a LED ON-OFF switch, but you can achieve this with any button that has an ON and OFF state that stays in that position.


I connected my LED switch to my Arduino using the image above. Please note I did not make this diagram. Credit for that diagram goes to: https://forum.arduino.cc/t/need-help-with-wiring-a-metal-push-button-with-led/1174962/4


To make sure the music only plays when the button is turned ON, I modified the code from my IF-statement from earlier. This is the modified code that makes sure the music only plays when the LED switch is ON:


int soundPin = 8; // Pin buzzer is connected to
const int numberSensors = 2;  // Number of velostat pressure sensors
const int pressurePins[numberSensors] = {A0, A1}; // Analog pins connected to the sensors
const int threshold = 1000;  // Adjust this threshold based on your sensor's behavior


// Notes for Carpe Diem
// https://musescore.com/user/36962362/scores/11076154 ,,, music read by me. So if it is out of tune, it is because my music theory skills suck
#define NOTE_A3 216
#define NOTE_B3 246
#define NOTE_CSHARP 277

// Duration of the notes
const int noteHalf = 1000;
const int noteQuarter = 500;
const int noteEight = 250;
const int noteWhole = 2000;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(soundPin, OUTPUT);
  pinMode(4, INPUT);
  pinMode(A0, INPUT);
  pinMode(A4, INPUT);
}


void loop()
{
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  int buttonState = analogRead(A4);
  Serial.print("button ");
  Serial.println(analogRead(A4));


  for (int i = 0; i < numberSensors; i++) {
    int pressureValue = analogRead(pressurePins[i]); // Read the analog value from the sensor
    Serial.print("Sensor ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(pressureValue);               // Print the sensor value to the serial monitor


    //Plays "Carpe Diem" by Joker Out
    if (pressureValue > threshold && buttonState <= 1000) {
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_B3);
      playEight(NOTE_A3);
      playQuarter (NOTE_B3);
      playHalf (NOTE_CSHARP);
      delay(2250);
    }
}


    //delay(100); // Delay for stability

  }
}


void playHalf(int frequency) {
  tone(soundPin, frequency, noteHalf);
  delay(noteHalf + 50);
  noTone(soundPin); // Stops note
  delay(50); // Adds a delay for the following note
}


void playQuarter(int frequency) {
  tone(soundPin, frequency, noteQuarter);
  delay(noteQuarter + 50);
  noTone(soundPin); // Stops note
  delay(50); // Adds a delay for the following note
}


void playEight(int frequency) {
  tone(soundPin, frequency, noteEight);
  delay(noteEight + 50);
  noTone(soundPin); // Stops note
  delay(25); // Adds a delay for the following note
}


void playWhole(int frequency){
  tone(soundPin, frequency, noteWhole);
  delay(noteWhole + 50);
  noTone(soundPin); //Stops note
  delay(50); //Adds a delay for the following note
}


If it isn't working, make sure you check if your LED button is connected properly. Depending on where you connect the pins on your arduino, it may function differently.

Adding an Extra Song

TOGGLESWITCHV2.png
wip.jpg

During the process of making this, I got pretty sick of hearing Carpe Diem over and over again. This inspired me to add one more feature to my design, this being the ability to change the song the doormat plays when stepped on! Luckily, adding such a feature is quite easy, and makes your design look and feel a lot more polished.


To do this, I used a simple ON-OFF switch.


This time, the song I added was Feel Good Inc. by Gorillaz, but the second song can be any song you like. Just like in the first step, you can convert the notes into frequencies manually or use the Midi to Arduino tone converter.


I modified my if-statement from earlier and added a second if-statement in order to make sure you could switch between the different songs. This is the modified code that lets you switch between the different songs. Once again this code is written with my chosen songs. If you want your doormate to play your chosen songs, make sure to modify the code accordingly.


int soundPin = 8; // Pin buzzer is connected to
const int numberSensors = 2;  // Number of velostat pressure sensors
const int pressurePins[numberSensors] = {A0, A1}; // Analog pins connected to the sensors
const int threshold = 1000;  // Adjust this threshold based on your sensor's behavior


// Notes for Carpe Diem
// https://musescore.com/user/36962362/scores/11076154 ,,, music read by me. So if it is out of tune, it is because my music theory skills suck
#define NOTE_A3 216
#define NOTE_B3 246
#define NOTE_CSHARP 277


//Notes for Feel Good Inc
// https://musescore.com/user/31042027/scores/5581330 ,,, music read by me once again. I also can't read bass clef very well.... Take this with a grain of salt
#define NOTE_D3 147
#define NOTE_E3 164
#define NOTE_F3 174


//Code for Feel Good Inc
//playHalf (NOTE_D4);
//playEight (NOTE_D4);
//playEight (NOTE_E4);
//playEight (NOTE_F4);
//playEight (NOTE_B5);
//playWhole (NOTE_A5);


// Duration of the notes
const int noteHalf = 1000;
const int noteQuarter = 500;
const int noteEight = 250;
const int noteWhole = 2000;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(soundPin, OUTPUT);
  pinMode(4, INPUT);
  pinMode(A0, INPUT);
  pinMode(A4, INPUT);
  pinMode(2, INPUT);
}


void loop()
{
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  int buttonState = analogRead(A4);
  int switchState = analogRead(A7);
  Serial.print("button ");
  Serial.println(analogRead(A4));
  Serial.println(analogRead(A7));


  for (int i = 0; i < numberSensors; i++) {
    int pressureValue = analogRead(pressurePins[i]); // Read the analog value from the sensor
    Serial.print("Sensor ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(pressureValue);               // Print the sensor value to the serial monitor


    //Plays "Carpe Diem" by Joker Out
    if (pressureValue > threshold && buttonState <= 1000 && switchState == 0) {
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_CSHARP);
      playEight(NOTE_B3);
      playEight(NOTE_A3);
      playQuarter (NOTE_B3);
      playHalf (NOTE_CSHARP);
      delay(2250);
    }


     if (pressureValue > threshold && buttonState <= 1000 && switchState >= 400) {
      playHalf (NOTE_D3);
      delay(150);
      playEight (NOTE_D3);
      playEight (NOTE_E3);
      playEight (NOTE_F3);
      delay(200);
      playEight (NOTE_B3);
      delay(200);
      playWhole (NOTE_A3);
      delay(2250);
    }


    //delay(100); // Delay for stability
  }
}


void playHalf(int frequency) {
  tone(soundPin, frequency, noteHalf);
  delay(noteHalf + 50);
  noTone(soundPin); // Stops note
  delay(50); // Adds a delay for the following note
}


void playQuarter(int frequency) {
  tone(soundPin, frequency, noteQuarter);
  delay(noteQuarter + 50);
  noTone(soundPin); // Stops note
  delay(50); // Adds a delay for the following note
}


void playEight(int frequency) {
  tone(soundPin, frequency, noteEight);
  delay(noteEight + 50);
  noTone(soundPin); // Stops note
  delay(25); // Adds a delay for the following note
}


void playWhole(int frequency){
  tone(soundPin, frequency, noteWhole);
  delay(noteWhole + 50);
  noTone(soundPin); //Stops note
  delay(50); //Adds a delay for the following note


After this, I decided my doormat had all the features it needed, so I got ready to finish up the project.

Soldering

Screenshot 2024-06-19 174539.png
IMG_7135.jpg

After making sure everything works the way I wanted it to, I soldered the entire thing together.


To make this process easier on myself, I drew out my project so I could follow my drawing while soldering and check off the parts I had already soldered. This way, I was sure I wouldn't overlook things during the soldering proces and would minimise the chance of me making careless mistakes.

Decorating

IMG_7141.jpg
decorated 2.jpg
decorated.jpg
done.jpg

The next step was my personal favourite, making everything we made so far nice and pretty! Right now, your project is probably just a bunch of wires on a PCB board. In this step, we will decorate it so it looks more finished and professional.


The first thing I did was make the doormat look more inviting, in the hopes people will ignore the very obvious wires coming from underneath it. The idea is to make it look SO NICE, people will not be able to resist stepping on your invention.


To stay in the theme, I painted my doormat to fit Joker Out and Carpe Diem by painting the Joker Out logo on the doormat, but you can of course paint your doormat in whatever colours and theme you like or leave it completely blank. It is up to you!


For the soldered components of the doormat, I made a 3D model of a box that I later 3D printed. I made this model in Maya. The model consists of one box with holes where i wanted my components to be and a lid that closes the box, kind of like a puzzle.


This model was made to scale to ensure every component would fit in the box perfectly. I meassured each component with a ruler and took notes on the length and width of each component and then figured out the layout of my box. Because I meassured every component pretty quickly and therefore inaccurately, I made sure to give each component some wiggle room so they could be adjusted if I so desired. Unfortunately, I did mess up the measurements for how the box would click together, which resulted in a box that could not be closed.


After I had both my box and the lid, I painted my box to fit with the theme of Joker Out. I added the logo of the band to the lid of the box, so it would match with the doormat itself and decorated the box with "clouds" and stickers.


To indicate what song was being played, I added stickers. I choose to do this so I could easily replace the stickers if I were to program in other songs at a later time. Using stickers instead of painting on the song name is a less permanent way to indicate which song is playing and ensures you are flexible to experiment and change things in the future.


Then after all the paint had dried, I put my soldered components in the box together with my arduino mega and made sure each component was in the right place.

Finished!

Arduino Minecraft IRL Pressure Plate Demonstration

Congrats! Now you have made the iconic Minecraft pressure plate! In the video you can see me demonstrating all the features.


This was my first big Arduino project ever and I am honestly super happy with how it turned out. It has every feature I wanted to add and even has a couple of extra features to make it even more special. I was honestly quite worried I wouldn't be able to do it, due to my inexperience in both Arduino and coding in C++, but it turns out you can achieve a whole lot if you take it step by step and focus on the things that make a project worth it for you. I learned a lot of valuable skills during this project, the most important one being that you should never underestimate yourself. If you want to achieve something, the only one who can do so is you, and you shouldn't put yourself down before you even tried it. During this project, I relearned to solder, learned the basis of Arduino and C++ and learned that a lot of things are a lot less intimidating than we make them out to be.


I am incredibly proud of myself for what I have achieved, though if I were to do this project again I would probably remake the lid of the box, as it does not fit properly right now. Though my entire project works, the lid not closing properly bothers me and is something I'd like to iterate on in the future. I would also like to experiment with some other things, such as a possible anti theft function.


For now I am super proud of myself and my work, and I feel like Arduino as a whole is way less intimidating. If you were debating on wether to give Arduino a try, this is your sign to do it, because as it turns out, sometimes you just need to start doing things and get out of your own head. You are capable of much more than you think.