Making a simple door alarm with Arduino UNO

Hello there !

I'm new to this forum and my english isn't that good, either.

I'm trying to make a door alarm with an arduino uno, a 433mhz receiver, and a 120db siren.

At the moment i connected a 55N03LTA to pin 8 as an output, in series with the mosfet's drain i've added a switch and the siren. The switch is obviously connected to the door.

The problem is that as soon as the door is closed, the alarm stops.

Here is my code:

#include <RCSwitch.h>

#define TEST 1671578x
#define ARMARE 1671577x
#define DEZARMARE 1671578x

#define ENABLE_Sniffer true


RCSwitch mySwitch = RCSwitch();  // Create an instance of RCSwitch


void setup() {
 pinMode(13, OUTPUT);
 pinMode(8, OUTPUT);
 Serial.begin(9600);
 mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
 tiltServo.attach(3);
}

void loop() {

 if (mySwitch.available()) {

   long value = mySwitch.getReceivedValue();

   if (value == 0) {
     Serial.print("Unknown encoding");
   } 
   else {

     if (ENABLE_Sniffer) {
     Serial.print("Received ");
     Serial.print( value );
     Serial.print(" / ");
     Serial.print( mySwitch.getReceivedBitlength() );
     Serial.print("bit ");
     Serial.print("Protocol: ");
     Serial.println( mySwitch.getReceivedProtocol() );
     
     }

     switch (value) {

     case TEST:
       tone(11, 350, 500);
       delay(3000);
       break;

     case ARMARE:
       delay(5000);
       digitalWrite(8, HIGH);
       break;

     case DEZARMARE:
       digitalWrite(8, LOW);
       break;
       
     }

   }
   mySwitch.resetAvailable();
 }                        
}

The following code is my attempt in solving the problem:

#include <RCSwitch.h>

#define TEST 1671578x
#define ARMARE 1671577x
#define DEZARMARE 1671578x

#define ENABLE_Sniffer true


RCSwitch mySwitch = RCSwitch();  // Create an instance of RCSwitch

const int sensor = 3;     // the number of the pushbutton pin
const int mosfet =  8;      // the number of the LED pin

// variables will change:
int sensorState = 0;         // variable for reading the pushbutton status


void setup() {
 pinMode(3, INPUT);
 pinMode(8, OUTPUT);
 pinMode(13, OUTPUT);
 Serial.begin(9600);
 mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2

}

void loop() {

 if (mySwitch.available()) {
   long value = mySwitch.getReceivedValue();
   
   sensorState = digitalRead(sensor);
   
    if (sensorState == HIGH) {     
   // turn LED on:    
   digitalWrite(mosfet, HIGH);  
 } 
 else {
     switch (value) {

     case TEST:
       tone(11, 350, 500);
       delay(3000);
       break;

     case ARMARE:
       delay(5000);
       digitalWrite(8, HIGH);
       break;

     case DEZARMARE:
       digitalWrite(8, LOW);
       break;
       
     }
   }
 }
   mySwitch.resetAvailable();
 }

Id like the siren not to shut down when the door is closed back.

Thanks in advance !

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

You haven't said how the alarm is to be turned off.

You can get it to stay ON by setting a variable when the switch is triggered. - like this pseudo code

if (switch is triggered) {
   alarmOn = true;
}

if (alarmOn == true) {
  // sound alarm
}

You will need some code somewhere else to set alarmOn back to false to make the sound stop.

...R

Sorry.

I'm sending arm/disarm/test through a remote control.

I want to arm the alarm from the remote control and make it wait for the switch to be triggered, and start the siren. When disarming button is pressed, to stop the siren and ignore the switch on the door. If armed with door open, to start siren.

Can you complete my code with the right one, please ? Thank you very much !!

Diygenes:
Can you complete my code with the right one, please ?

You will learn a great deal more if you make the first attempt. If it does not work then post the code and explain what it actually does and what you want it to do.

...R

Hello !

For the past 8 hours i tried different codes, combinations of codes, but nothing worked. I even managed to wreck the code without having a back-up, but fortunately i took the code back from my post. I need this circuit by sunday morning to put it at my grandma's home. Please help me with this, because if i don't manage to make the code by miself i will be constrained to buy an alarm system that makes the same thing...

Diygenes:
I need this circuit by sunday morning to put it at my grandma's home. Please help me with this,

There are a few days to go before Sunday.
I'm happy to help, but I am not going to write the code - that's your role.

...R

PS you will be in very exalted company if your computer project is overdue, over budget and under performs.

Robin2:
PS you will be in very exalted company if your computer project is overdue, over budget and under performs.

(Robin2 slips in a subtle reference to the Forum software here).

Diygenes:
Hello !

For the past 8 hours i tried different codes, combinations of codes, but nothing worked.

Post what doesn't work so we can see your thinking processes. It shouldn't be rocket science.

  • If the switch opens sound the alarm (and leave it on).
  • If the disarm code is received turn the alarm off.

Hello again !

Thank you very much for your replies !

I made it ! I don't know if it's the right way or not, but it works as expected.

The remote control is now turning on/off the pin 13 when arming/disarming, while pin 7 is awaiting for a command.

#include <RCSwitch.h>
#define TEST 1671578x
#define ARM 1671577x
#define DISARM 1671578x
#define ENABLE_Sniffer true
RCSwitch mySwitch = RCSwitch();

void setup() {
  pinMode(7, INPUT);
  pinMode(8, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(13, OUTPUT);
  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  Serial.begin(9600);
}
void loop() {
  long value = mySwitch.getReceivedValue();
  
  int buton = digitalRead(7);
  if (buton == 1) {
    digitalWrite(8, HIGH);
  } else {
    
  switch (value) {

      case TEST:
        tone(11, 350, 500);
        break;

      case ARM:
        digitalWrite(13, HIGH);
        break;

      case DISARM:
        digitalWrite(13, LOW);
        digitalWrite(8, LOW);
        break;
      }
    
  }
  Serial.println(buton);
  delay(100);
}

Video

Actually it had not crossed my mind - I was thinking more of multi - £million waste in the UK health service and similar debacles.

...R

Diygenes:
I made it ! I don't know if it's the right way or not, but it works as expected.

... and with a nice sense of achievement, I suspect.

Well done.

...R