void
check() {
-
Serial.println("Checking");
30
if
(_pir_sensor.motion_detected()) {
-
Serial.println("Intruder
-
send_alarm();
-
}
-
}
35
};
-
#endif
-
This defines a class named
written so far. It encapsulates a
object. Its most complex method is
The rest of the
BurglarAlarm
20, we define the constructor that initializes all private members. If the PIR
sensor detects movement, the
Let s use the
BurglarAlarm
Ethernet/BurglarAlarm/BurglarAlarm.ino
#include <SPI.h>
#include <Ethernet.h>
#include "burglar_alarm.h"
const unsigned int
const unsigned int
const unsigned int
const
String
const
String
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress my_ip(192, 168, 2, 120);
// Insert IP address of your SMTP server below!
IPAddress smtp_server(0, 0, 0, 0);
PassiveInfraredSensor pir_sensor(PIR_INPUT_PIN);
SmtpService
BurglarAlarm
void
setup() {
Ethernet.begin(mac, my_ip);
Serial.begin(BAUD_RATE);
delay(20 * 1000);
}
void
loop() {
burglar_alarm.check();
delay(3000);
}
Chapter 11. Creating a Burglar Alarm with Email Notification
detected!");
BurglarAlarm
SmtpService
send_alarm
class is pretty straightforward. Beginning on line
check
method sends an email.
class:
PIR_INPUT_PIN = 2;
SMTP_PORT = 25;
BAUD_RATE = 9600;
USERNAME
= "bm90bXl1c2VybmFtZQ==";
PASSWORD
= "bm90bXlwYXNzd29yZA==";
smtp_service(smtp_server, SMTP_PORT, USERNAME, PASSWORD);
burglar_alarm(pir_sensor, smtp_service);
www.it-ebooks.info
that aggregates all the code we ve
instance and a
PassiveInfraredSensor
, which sends a predefined email.
// Encoded in Base64.
// Encoded in Base64.
198
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?