EasyManuals Logo

Arduino uno User Manual

Arduino uno
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #214 background imageLoading...
Page #214 background image
void check() {
-
Serial.println("Checking");
30
if (_pir_sensor.motion_detected()) {
-
Serial.println("Intruder detected!");
-
send_alarm();
-
}
-
}
35
};
-
#endif
-
This defines a class named
BurglarAlarm
that aggregates all the code weve
written so far. It encapsulates a
SmtpService
instance and a
PassiveInfraredSensor
object. Its most complex method is
send_alarm
, which sends a predefined email.
The rest of the
BurglarAlarm
class is pretty straightforward. Beginning on line
20, we define the constructor that initializes all private members. If the PIR
sensor detects movement, the
check
method sends an email.
Lets use the
BurglarAlarm
class:
Ethernet/BurglarAlarm/BurglarAlarm.ino
#include <SPI.h>
#include <Ethernet.h>
#include "burglar_alarm.h"
const unsigned int PIR_INPUT_PIN = 2;
const unsigned int SMTP_PORT = 25;
const unsigned int BAUD_RATE = 9600;
const String USERNAME = "bm90bXl1c2VybmFtZQ=="; // Encoded in Base64.
const String PASSWORD = "bm90bXlwYXNzd29yZA=="; // Encoded in Base64.
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 smtp_service(smtp_server, SMTP_PORT, USERNAME, PASSWORD);
BurglarAlarm burglar_alarm(pir_sensor, smtp_service);
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 198
report erratum discuss
www.it-ebooks.info

Table of Contents

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino uno and is the answer not in the manual?

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals