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 #212 background imageLoading...
Page #212 background image
-
void loop() {
-
if (pir.motion_detected()) {
-
Serial.println("Motion detected");
25
} else {
-
Serial.println("No motion detected");
-
}
-
delay(200);
-
}
30
With the constant
PIR_INPUT_PIN
, you can define the digital pin youve connected
your PIR sensor to. In line 4, we begin the definition of a class named
Passive-
InfraredSensor
that encapsulates all things related to PIR sensors.
We define a member variable named
_input_pin
that stores the number of the
digital pin weve connected our sensor to. Then we define a constructor that
expects the pin number as an argument and assigns it to our member variable.
The only method we need to define is
motion_detected
. It returns
true
if it has
currently detected a motion and
false
otherwise. So, it has to check only
whether the current state of the sensors digital pin is
HIGH
or
LOW
.
Compile the sketch and upload it to your Arduino. You should see an output
similar to the following screenshot when you start to wave your hand in front
of the sensor.
Now weve built the two main components of our burglar alarm, and the only
thing left to do is to bring them both together. Well do that in the next section.
Chapter 11. Creating a Burglar Alarm with Email Notification 196
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