Nodemcu 12e and wifi
Blynk server
Blynk Library version 0.6.1
Android
/**************************************************************
* IoT Motion Detector with Blynk
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
* Developed by Marcelo Rovai - 30 November 2016
**************************************************************/
#include <ESP8266WiFi.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
char auth[] = "ZnW9b5FuZd09ISXhBksLewt_YWERO8Ys";
/* WiFi credentials */
char ssid[] = "BTHub6-2HN7";
char pass[] = "vApML49vx4A7";
/* HC-SR501 Motion Detector */
#define ledPin D7
#define pirPin D1 // Input for HC-S501
int pirValue; // Place to store read PIR Value
void setup()
{
Serial.begin(115200);
delay(10);
Blynk.begin(auth, ssid, pass);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
digitalWrite(ledPin, LOW);
}
void loop()
{
getPirValue();
Blynk.run();
}
/***************************************************
* Get PIR data
**************************************************/
void getPirValue(void)
{
pirValue = digitalRead(pirPin);
if (pirValue)
{
Serial.println("==> Motion detected");
Blynk.notify("T==> Motion detected");
}
digitalWrite(ledPin, pirValue);
}
Apologies for the truncated post, I made a right mess of it. Even showed off my wifi password which I have now had to change.
My project is to monitor the movements of an elderly person in their home, and to send an alert when normal patterns of movement cease. To this end I initially want to present historical PIR sensor data on a chart so that I can spot patterns of movement.
I flashed the code to my Nodemcu, created a blynk app which used just a notification widget and it works fine. I get a notification every time the PIR is triggered. I think this proves that at least the components of my project are at least working.
Then I added a superchart widget and set it up with:-
Binary data
Input digital pin D1 False =0 flip=0 true=1
Y axis height 20% to 80%
No data on the chart
Then I deleted the notification widget
Still No data on the chart
I am new to Blynk and I am sure that I am missing some fundamental knowledge.
Can someone please steer me in the right direction to study
I still worry about the poor hardware having to send a message every second. It would be better if a message was sent to the cloud only when the PIR sensor is triggered. Is this where interrupts come in? I will read up.
PS
Should there really be an L after the 1000 in the timer article? I left it out and things still seem to work.
That’s really not a problem. However, if you’re using Superchart in anything other than Live view then you should be aware that all values sent over a 1 minute period are averaged and that average value written to the database and displayed in Superchart.
This means that one trigger lasting 15 seconds with a 1 second reporting frequency will result in a stored value of 0.25
That’s an option, but your explanation of what you’re actually trying to achieve, and how you’ve chosen to implement the code is still a mystery to me.
If you want to know when the value of a GPIO pin changes then you can keep polling the pin and checking it’s status, or you can attach an interrupt to the pin.
Interrupts can be defined as CHANGE, RISING or FALLING. A change interrupt will call the defined function (known as the Interrupt Service Routine or ISR) when the pin changes from HIGH to LOW and LOW to HIGH. That’s probably not what you want in this case.
One issue to consider is that PIR relays probably won’t give a clean signal. There will be some bounce between HIGH and LOW for a few milliseconds when the contacts open or close.
This isn’t an issue when polling the contacts at say 100ms intervals, but it is when using interrupts, so your ISR will need some debounce code incorporating into it.
Googling will explain all of these issues in detail.
The ‘L’ is optional in this case. It tells the compiler to treat this as an Unsigned Long number.