-
// Insert IP address of your SMTP server below!
-
IPAddress smtp_server(0, 0, 0, 0);
-
15
SmtpService smtp_service(smtp_server, SMTP_PORT, USERNAME, PASSWORD);
-
-
void setup() {
-
Ethernet.begin(mac, my_ip);
-
Serial.begin(BAUD_RATE);
20
delay(1000);
-
Email email(
-
"arduino@example.com",
-
"info@example.net",
-
"Yet another subject",
25
"Yet another body"
-
);
-
smtp_service.send_email(email);
-
}
-
30
void loop() {}
-
No surprises here. We define constants for the SMTP port, the MAC address,
the username, the password, and so on; then we create an
SmtpService
instance.
In the
setup
function, we initialize the Ethernet shield and the serial port, then
wait for a second to let things settle down. In line 22, we create a new
Email
object and pass it to the
send_email
method.
Figure 28, A typical SMTP session on the Arduino, on page 194 shows this in
action (including authentication).
Now we know how to send emails with an Arduino, but to build our burglar
alarm, we still have to learn how to detect motion.
Detecting Motion Using a Passive Infrared Sensor
Detecting motion is a useful technique, and you probably already know devices
that turn on the light in your garden or at your door whenever someone is
near enough. Most use passive infrared sensors (PIR)
5
for motion detection.
Nearly every object emits infrared light and a PIR sensor measures exactly
this kind of light. Detecting motion is comparatively easy if you’re already
able to receive the infrared radiation emitted by objects in the sensor’s field
of view. If the sensor receives the infrared light emitted by a wall and suddenly
a human being or an animal moves in front of the wall, the infrared light
signal will change.
5.
http://en.wikipedia.org/wiki/Passive_infrared_sensor
report erratum • discuss
Detecting Motion Using a Passive Infrared Sensor • 193
www.it-ebooks.info