Hello Blynkers I’m beginner for coding and my project is use the PIR sensor to detect the motion of human and send to NeoPixel 8 bit to activated the LED and while the object pass the sensor NeoPixel will be close (I use blue LED before NeoPixel to show if object come in range of PIR sensor , it will activate before NeoPixels) and I want to use blynk to create interface to set time to start/stop the NeoPixels and LED with the wifi.
The interface of blynk is :
LCD is pin V2 (It can use when motion is detected)
LedBlynk is pin V1(It can use when motion is detected)
Notification is worked
Timer is pin V0 (It can’t use I use the code in github http://docs.blynk.cc/#widgets-controllers-timer ) but I confuse about the code it’s working if I use only the Neopixel without PIR sensor but when connect the PIR to Neopixel it can’t work and I don’t understand in my confuse
My Project details :
• My Hardware is NodeMCU v2 with wifi
• I use Smartphone OS (iOS ) + version12.1.4
• Blynk server
• Blynk Library version is 0.6.0
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN D3
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 8
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
char auth[] = "******";
char ssid[] = "******";
char pass[] = "******";
BlynkTimer timer;
int ledPin = D4; // choose the pin for the LED
int ledPin1 = D2;
int inputPin = D0; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int delayval = 500;
boolean stateled=0;
boolean prevStateled=0;
WidgetLCD lcd(V2);
WidgetLED ledBlynk(V1);
void checkledstate()
{
stateled=digitalRead(D4);
if (stateled!=prevStateled)
{
if (stateled==0) Blynk.virtualWrite(D4,0);
if (stateled==1) Blynk.virtualWrite(D4,255);
}
prevStateled=stateled;
}
void setup() {
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
timer.setInterval(300L, checkledstate);
pinMode(inputPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
Serial.begin(115200);
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin();
pixels.show();
}
BLYNK_WRITE(V0)
{
***this I don't know where to put it and it will work****
}
void loop()
{
if (Blynk.connected())
{
Blynk.run();
getval();
}
timer.run();
}
void getval(void){
if (Blynk.connected()){
//getval();
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
ledBlynk.on();
Blynk.virtualWrite(5,1023);
lcd.clear();
lcd.print(0,0,"Motion detected");
for(int i=0;i<NUMPIXELS;i++){ // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval);
Blynk.virtualWrite(V13,255);
}// Delay for a period of time (in milliseconds). turn LED ON
if (digitalRead(inputPin) == HIGH) // we have just turned on
Serial.println("Motion detected!");
Blynk.notify("Motion detected"); // We only want to print on the output change, not state
}
else {
digitalWrite(ledPin, LOW);
ledBlynk.off();
Blynk.virtualWrite(5,0);
lcd.clear();
lcd.print(0,0,"Motion end");
for(int i=0;i<NUMPIXELS;i++){ // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval);
Blynk.virtualWrite(V13,0); // turn LED OFF
// we have just turned of
Serial.println("Motion ended!");// We only want to print on the output change, not state
}
}
}
}
BLYNK_CONNECTED() {
Blynk.syncAll();
}
Thank you of all Solved answer