Simone Adobs
Published © GPL3+

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

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.

BeginnerFull instructions provided2 hours14,936
A Very Compact Alarm with Card Reader and Real-Time Clock

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
PHPoC Bread Board
PHPoC Bread Board
×1
LED (generic)
LED (generic)
×2
Resistor 221 ohm
Resistor 221 ohm
×2
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
RC522 Card Reader
×1
Real Time Clock
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics with Fritzing

Schematics with Fritzing

Code

Very compact alarm

C/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;
}

Credits

Simone Adobs

Simone Adobs

3 projects • 25 followers
Hi, Hackster Community! I'm Simone Adobs and I am an Arduino fan. Take a look to all my projects! ;-)

Comments