Bringing It All Together
With our
PassiveInfraredSensor
and
SmtpService
classes, it’s a piece of cake to build
a burglar alarm with email notifications. Connect the PIR sensor to the Eth-
ernet shield, as shown in the following figure.
Then enter the following code in your Arduino IDE:
Ethernet/BurglarAlarm/burglar_alarm.h
#ifndef __BURGLAR_ALARM_H__
Line 1
#define __BURGLAR_ALARM_H__
-
#include "pir_sensor.h"
-
#include "smtp_service.h"
-
5
class BurglarAlarm {
-
PassiveInfraredSensor _pir_sensor;
-
SmtpService _smtp_service;
-
void send_alarm() {
-
Email email(
10
"arduino@example.com",
-
"info@example.net",
-
"Intruder Alert!",
-
"Someone's moving in your living room!"
-
);
15
_smtp_service.send_email(email);
-
}
-
-
public:
-
BurglarAlarm(
20
const PassiveInfraredSensor& pir_sensor,
-
const SmtpService& smtp_service) :
-
_pir_sensor(pir_sensor),
-
_smtp_service(smtp_service)
-
{
25
}
-
-
-
report erratum • discuss
Bringing It All Together • 197
www.it-ebooks.info