Project tutorial
A Very Compact Alarm with Card Reader and Real-Time Clock

A Very Compact Alarm with Card Reader and Real-Time Clock © GPL3+

This is an alarm for your house that rings when a movement is detected, like when the door is open or when a body walks in front of it.

  • 7,237 views
  • 3 comments
  • 31 respects

Components and supplies

Apps and online services

About this project

This is my first project released on Hackster and every suggestion is accepted. Well, I've made this alarm just for fun and I hope you will like it!

How does the alarm work?

In order to see from the image to start the alarm, you must put the correct magnetic card on the RC522 Card Reader. If the card is indeed correct, the alarm will turn on automatically (green LED: on; red LED: off), but if the card isn't correct, nothing is happening (green LED: off; red LED: on).

When the alarm is started, the HC-SR04 Ultrasonic Sensor will capture any movement in front of it.

To shut down the alarm, we will again put the correct magnetic card on RC522 Card Reader (green LED: off; red LED: on).

What if you forget to turn on the alarm before going to sleep?

We can go to sleep without activating the alarm because the Real Time Clock will activate the alarm at a certain hour.

Here you can find some code explanation:

On line 29, you can set the code of your magnetic card.
 String codiceAutorizzato = "5545A93980";
On line 53, you can schedule the automatic start of the alarm (24 hours format).
 if (orario=="21:56" && statoattivato==0)
On line 65, you can set the maximum distance from which the sensor works (it must be expressed in centimeters). Beyond this limit, the sensor won't work and no movement will be notice.
 if (sr04.Distance()<120)

For every explanation or suggestion, feel free to comment below.

I'm sorry, I can't make my real schematics because with Fritzing I can't compact the circuit, please forgive me ;-)

You can try to compact the circuit on your own.

Have a NICE DAY.

Simone from Italy <3

Code

Very compact alarmC/C++
It is an alarm that capture any movement in front of it
#include <RFID.h>
#include <SPI.h>
#include <SR04.h>
#include <DS3231.h>
#include <Wire.h>
String ora;
String mins;
String orario;
DS3231 Clock;

#define ECHO_PIN 3
#define TRIG_PIN 4
#define green 5
#define red 6
#define buzz 8
#define RESET_DIO 9
#define SDA_DIO 10

#define delayRead 600

SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
RFID RC522(SDA_DIO, RESET_DIO); 

bool h12;
bool PM;
int attivo=false; 
int statoattivato=0;
String codiceLetto;
String codiceAutorizzato = "5545A93980";

void setup(){ 
  Wire.begin();
  SPI.begin(); 
  RC522.init();
  pinMode(buzz,OUTPUT);
  pinMode(red,OUTPUT);
  pinMode(green,OUTPUT);
  digitalWrite(green,LOW);
  digitalWrite(red,HIGH);
}
 
void loop(){
  ora=Clock.getHour(h12, PM), DEC;
  mins=Clock.getMinute(), DEC;
  orario=ora+":"+mins;
  byte i;
  if (RC522.isCard()) {   
    if(verificaCodice(lettura())) {
      rilevatore();
    }
    delay(delayRead);
  }
  if (orario=="21:56" && statoattivato==0) {
    statoattivato=1;
    rilevatore();
  }
}

void rilevatore() {
  if (attivo==false) {
    attivo=true;
    digitalWrite(red,LOW);
    digitalWrite(green,HIGH);
    while (attivo=true) {
      if (sr04.Distance()<120) 
        tone(8,262,500);
      if (RC522.isCard()) {
        if (verificaCodice(lettura())) {
          attivo=false;
          digitalWrite(green,LOW);
          digitalWrite(red,HIGH);
          break;
        }     
      }
    }
  }
}

boolean verificaCodice(String codiceLetto){
  if(codiceLetto.equals(codiceAutorizzato)){
    return true;
  }
  else{
    return false;
  }
}


String lettura(){
  byte i;
  RC522.readCardSerial();
  String codiceLetto ="";
  for(i = 0; i <= 4; i++) {
    codiceLetto += String (RC522.serNum[i],HEX);
    codiceLetto.toUpperCase();
    }
  return codiceLetto;
}

Schematics

Schematics with Fritzing
allarme_ultrasuoni_e_ora_pEiHvFbWpj.fzz
Schematics with Fritzing
Allarme ultrasuoni e ora iguzqrvwry

Comments

Similar projects you might like

Alarm Clock

by Tittiamo

  • 46,985 views
  • 59 comments
  • 47 respects

Arduino Ethernet Rfid card reader

Project tutorial by David Smerkous

  • 30,697 views
  • 15 comments
  • 50 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project tutorial by LAGSILVA

  • 12,677 views
  • 11 comments
  • 50 respects

Real-Time Clock Controlled Herbal Garden Watering System

Project tutorial by Maximilian Dullo

  • 7,239 views
  • 2 comments
  • 15 respects

Plant watering alarm system with arduino

Project tutorial by Giannis Arvanitakis

  • 3,397 views
  • 1 comment
  • 5 respects

Distance Alarm System

Project tutorial by Darwin Dela Cruz

  • 2,973 views
  • 3 comments
  • 14 respects
Add projectSign up / Login