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.
