Things used in this project

Hardware components:
A000066 iso both
Arduino Arduino UNO & Genuino UNO
×1
Bread board b23zpsd8ys
PHPoC PHPoC Bread Board
×1
09590 01
LED (generic)
×2
Mfr 25fbf52 221r sml
Resistor 221 ohm
×2
51gzz5eu9pl. sx425
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Adafruit industries ada1536 image
Buzzer
×1
RC522 Card Reader
×1
Real Time Clock
×1
Software apps and online services:
Ide web
Arduino Arduino IDE

Schematics

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

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

Credits

Icona canale ulrv1z1uga
Simone Adobs

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

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Water Softener
Easy
  • 265
  • 5

Full instructions

Sweeping frequency magnetic hard water conditioner

Know the Temp of Your Home From Anywhere with Arduino Cloud!
Easy
  • 1,246
  • 9

Full instructions

Ever wanted to know the temperature of your home from somewhere? Here's an easy way to do it with Arduino Cloud and the Yun Shield!

Simple Obstacle Senor With Arduino
Easy
  • 88
  • 2

Full instructions

I am gonna show you how to make a simple obstacle sensing system with cheap parts like IR LED and photo diode.

Safe City: A Device to Keep You Safe
Easy
  • 630
  • 6

Full instructions

The device will keep you safe. Just have to click a button and your precise location will be shared.

Arduino UNO Home Automation using Bluetooth HC05 module
Easy
  • 13
  • 1

Protip

Home Automation Attributes: Turning ON/OFF light bulb (AC 220V). Automatically Turning the Led ON/OFF depending on light intensity.

Connect Your Thinxtra Xkit Using Sigfox
Easy
  • 130
  • 2

Protip

Learn how to build an IoT application over Sigfox integrated with Ubidots - send temp readings based on motion sensors.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog