Use to WIZwiki-W7500, Sensing to PIR motion sensor module(HC-SR501)
Dependencies: mbed
Fork of PIR_Motion_Sensor_WIZwiki-W7500 by
Prerequisite
This example is for PIR test using digital I/O.
To implement this function, you need a Platform board, network Interface board.
- WIZwiki-W7500 from WIZnet (Platform board and Ethernet I/F board)
Hardware Configuration
WIZwiki-W7500 Pin map
PIR Sensor(HC-501SR) Pin map
Wiring Table
HC-501SR | W7500 |
VCC | 5V |
GND | GND |
SIGNAL | D8 or PC_7 |
Software
Init GPIO
DigitalOut myled(LED1); // Alert LED DigitalIn PIR(PC_7); // PIR Signal //D8
Get data from PIR
int PIR_sensor; // declare variable for PIR input data while(1) { PIR_sensor = PIR; // Check input signal from PIR pin pc.printf("PIR Value : %d\r\n",PIR_sensor); myled =! PIR_sensor; // PIR(HIGH) == LED On // PIR(LOW) == LED Off wait(0.1f); }
Caution
When wiring, be careful (GND, VCC)
main.cpp@1:b8bd8695558d, 2017-04-07 (annotated)
- Committer:
- kei44
- Date:
- Fri Apr 07 04:15:48 2017 +0000
- Revision:
- 1:b8bd8695558d
- Parent:
- 0:9ea50fe6902c
Change PIR PIN for ECO board. (D8 -> PC_7); In fact, two PIN definition is the same.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nanjsk | 0:9ea50fe6902c | 1 | // PIR Motion Sensor Modlue : HC-SR501 |
nanjsk | 0:9ea50fe6902c | 2 | #include "mbed.h" |
nanjsk | 0:9ea50fe6902c | 3 | |
nanjsk | 0:9ea50fe6902c | 4 | DigitalOut myled(LED1); |
kei44 | 1:b8bd8695558d | 5 | DigitalIn PIR(PC_7); //D8 |
nanjsk | 0:9ea50fe6902c | 6 | |
nanjsk | 0:9ea50fe6902c | 7 | Serial pc(USBTX, USBRX); |
nanjsk | 0:9ea50fe6902c | 8 | |
nanjsk | 0:9ea50fe6902c | 9 | int main() { |
nanjsk | 0:9ea50fe6902c | 10 | pc.baud(115200); |
nanjsk | 0:9ea50fe6902c | 11 | wait(0.5f); |
nanjsk | 0:9ea50fe6902c | 12 | pc.printf("Hello WizWIki-W7500!\n\r"); |
nanjsk | 0:9ea50fe6902c | 13 | pc.printf("===========================================\n\r"); |
nanjsk | 0:9ea50fe6902c | 14 | int PIR_sensor; |
nanjsk | 0:9ea50fe6902c | 15 | while(1) { |
nanjsk | 0:9ea50fe6902c | 16 | PIR_sensor = PIR; |
nanjsk | 0:9ea50fe6902c | 17 | pc.printf("PIR Value : %d\r\n",PIR_sensor); |
nanjsk | 0:9ea50fe6902c | 18 | myled =! PIR_sensor; |
nanjsk | 0:9ea50fe6902c | 19 | wait(0.1f); |
nanjsk | 0:9ea50fe6902c | 20 | } |
nanjsk | 0:9ea50fe6902c | 21 | } |