ESP-Based PIR Alarm

ESP based PIR alarm that can monitor an area and send an e-mail and/or SMS when movement is detected.
ESP based PIR alarm that can monitor an area and send an e-mail and/or SMS when movement is detected.
Features
- Built-in webserver (which builds on previous Elektor projects)
- Reed contact to switch quickly between modes
- RGB LED to indicate modes
- Additionally send SMS via Nexmo
- Backup of settings to EEPROM
- Time updates via NTP Timeserver
- Ten line activity log
- Silent mode without LED indications
Project Elements
Web Interface (PNG, 177.69 KB)
Change settings via web interface
Latest Sources V1.4.1
(ZIP)
Code, libraries, schematics and documentation
Discussion (1 comment)

ElektorLabs 5 years ago
Any chance of you willing to share more than just a list of features? Is it working? Schematics? Software?
Reply

inc. 5 years ago
Hi
Can you switch on the E-Mail debugging and check the output? In the SendEmail.cpp file of the SendEmail library there is a commented out line for debugging. When you enable this line the communication between Email server and the PIR sensor is sent to the serial port. Check that the E-Mail server credentials are correct e.g. using a webmailer. The port number also needs to be correct, you can get this from AT&T support.
The specific 475 error seems to indicate that AT&T thinks that the PIR sensor is sending spam. Did the sensor send any E-Mails at all, or did you get the error only after a while?
You might also login to the webmailer and check that no E-Mail is in the Outbox that could be regarded as suspicious by AT&T.
Regards,
Muiris.
Can you switch on the E-Mail debugging and check the output? In the SendEmail.cpp file of the SendEmail library there is a commented out line for debugging. When you enable this line the communication between Email server and the PIR sensor is sent to the serial port. Check that the E-Mail server credentials are correct e.g. using a webmailer. The port number also needs to be correct, you can get this from AT&T support.
The specific 475 error seems to indicate that AT&T thinks that the PIR sensor is sending spam. Did the sensor send any E-Mails at all, or did you get the error only after a while?
You might also login to the webmailer and check that no E-Mail is in the Outbox that could be regarded as suspicious by AT&T.
Regards,
Muiris.
Reply

inc. 5 years ago
Hi Yves,
The message indicates that send_html is not defined in library / class SendEmail. That was due to a mistake in the sources. Apologies for that, I included the wrong SendEmail library in the sources with the V1.3 update. Updated sources have now been uploaded, let me know if it now compiles and works as described.
From your comments I also saw that my sketch used #ifdef instead of #if when checking the USE_SEND_HTML declaration. Thanks for that, now corrected.
Sending of SMS via E-Mail is no longer possible with some providers (in my case Vodafone). I am investigating another option at the moment (Nexmo). Update to follow ....
Muiris.
The message indicates that send_html is not defined in library / class SendEmail. That was due to a mistake in the sources. Apologies for that, I included the wrong SendEmail library in the sources with the V1.3 update. Updated sources have now been uploaded, let me know if it now compiles and works as described.
From your comments I also saw that my sketch used #ifdef instead of #if when checking the USE_SEND_HTML declaration. Thanks for that, now corrected.
Sending of SMS via E-Mail is no longer possible with some providers (in my case Vodafone). I am investigating another option at the moment (Nexmo). Update to follow ....
Muiris.
Reply

ybourdon 5 years ago
Hello. This is a very nice project !
I have a problem with, I thing, the modified SendEmail library.
When compiling I get the following issue wich stops the compilation: 'class SendEmail' has no member named 'send_html'
Problem is in SMT line 42
sentEMails += smtpConnection.send_html(a_smtp_user, recipient, a_smtp_subject, a_smtp_message) ? 1 : 0;
I get the emazil with html texts but it is not decoded even if I declare : #define USE_SEND_HTML 0
Can you help me ?
Thank you for your reply.
Yves
I have a problem with, I thing, the modified SendEmail library.
When compiling I get the following issue wich stops the compilation: 'class SendEmail' has no member named 'send_html'
Problem is in SMT line 42
sentEMails += smtpConnection.send_html(a_smtp_user, recipient, a_smtp_subject, a_smtp_message) ? 1 : 0;
I get the emazil with html texts but it is not decoded even if I declare : #define USE_SEND_HTML 0
Can you help me ?
Thank you for your reply.
Yves
Reply

inc. 5 years ago
The PIR alarm is working, the feature list is nearly complete.
Programmed using Arduino 1.8.7. Some Zip libraries need to be installed.
Operation: Every 100ms the ESP8266 checks the reed switch and the PIR sensor and decides if something needs to be done. Depending on the current status and operating mode (alarm/movement/mode change) the LED colour is changed. When an alarm needs to be triggered an E-Mail will be sent.
The reed switch is debounced by virtue of counting how long it is active. When it is not active for long enough the event is discarded. This works very reliably.
Future options:
MQTT Events
Programmed using Arduino 1.8.7. Some Zip libraries need to be installed.
Operation: Every 100ms the ESP8266 checks the reed switch and the PIR sensor and decides if something needs to be done. Depending on the current status and operating mode (alarm/movement/mode change) the LED colour is changed. When an alarm needs to be triggered an E-Mail will be sent.
The reed switch is debounced by virtue of counting how long it is active. When it is not active for long enough the event is discarded. This works very reliably.
Future options:
MQTT Events
Complete project including includes (348kb)
Simple test setup (133kb)
Simple test setup (133kb)
Reply
Show more
10 Comment(s)
Updates from the author
inc. 5 years ago
* Sending of SMS via NEXMO service
* Update SendMail.cpp to check for SMTP server availability
* Add test buttons to send E-Mail or SMS on demand
* Various small enhancements to the GUI
* Move text strings in code to ROM to save RAM space using F()
Since Vodaphone doesn't support the sending of SMS via E-Mail I decided to investigate a different alternative - Nexmo. This is a well supported internet based messaging system which shouldn't go away very soon. In my tests it has worked very well.
Please clear the EEPROM beforehand (using the [Forget] button) if you build Version 1.4 on top of one of the previous releases. The EEPROM storage layout has changed. Otherwise strange settings can appear.
Version 1.4.1
* Correct off-by-one error in SMS.ino substring selection - SMS sentCount remained at 0
inc. 5 years ago
* Robust MQTT connection, with reconnection to broker if required
Version 1.3.1
* Corrected included SendEmail library
inc. 5 years ago
* Corrected issue whereby the Local Access Point (SoftAP) did not start as described in the documentation (i.e. SSID = PIR-Monitor-SensorOne and password protected) if an old SoftAP connection was already defined and active.
* In monitoring mode the light is now white instead of blue which looks better I think.
* Updated documentation with details of code compilation.
Also attached are some pictures of my nightlight conversion just as an illustration of the amount of space required for the unit. Some of the parts were 3D printed to make it neater. Many variations are possible!
Inside parts 1 (1497kb)
Inside parts 2 (1567kb)
Front parts (1145kb)
Front view (625kb)
Code, libraries, schematics and documentation (1359kb)
inc. 5 years ago
* HTML formatted E-Mails
* E-Mail sent on Start-Up
* MQTT Events on Alarm, Monitoring, Start-Up
* Added variables PIR_MaxAlarmCount, AlarmModeExitTime and PIR_AlarmRetainTime to EEPROM
* Reed switch "Touch" mode for about 2 seconds will show currently active mode(s)
See updated documentation for more details. Comments are welcome.
Parts:
- Wemos D1 Mini 4MB ESP8266
- PIR sensor standard mini model e.g. HC-SR501
- Reed switch came from the junk box
- 4-way I2C level translator to convert between 5V and 3.3V e.g. XCSOURCE 5PCS IIC I2C Logic Level Converter Bi-Directional Module 5V to 3.3V TE291 from Amazon. This function could also be implemented with discrete components.
- One WS2812B RGB LED
A power supply is not defined, just 5V @ about 300mA or so. It depends on how and where it is deployed. I'm working on fitting it into an old nightlight at the moment, using a minature Meanwell 5V 3W power supply.
Showing placement of PIR module, reed switch, LED (2344kb)
Example of E-Mail send from the alarm (157kb)
test-jig.jpg (2145kb)
Code, libraries, schematics and documentation (1122kb)