BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Sensor light notification push


#1

hi guys, I have a problem with the code. I would like a notification to arrive when the brightness sensor value goes down. at the oxen it’s about 1000, when it’s light it goes down under 800. I would like it when I got down I got a notification in my cell phone. Can you help me? thank you

the code is:

#define BLYNK_PRINT Serial   

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>



char auth[] = "xxx";  
int analogInPin = A0;
int sensorValue = 0;

void notifyOnButtonPress()
{
  // Invert state, since button is "Active LOW"
  int isButtonPressed = !analogRead(0);
  int photocellReading;
  
  if (photocellReading < 800) {
    Serial.println("Button is pressed.");

    // Note:
    //   We allow 1 notification per 5 seconds for now.
    Blynk.notify("Yaaay... button is pressed!");

    // You can also use {DEVICE_NAME} placeholder for device name,
    // that will be replaced by your device name on the server side.
    //Blynk.notify("Yaaay... {DEVICE_NAME}  button is pressed!");
  }
}

void setup()
{
  Serial.begin(9600); 
  Blynk.begin(auth);
  pinMode( analogInPin, INPUT);

    // Setup notification button on pin 2
  pinMode(0, INPUT_PULLUP);
  // Attach pin 2 interrupt to our handler
  attachInterrupt(digitalPinToInterrupt(0), notifyOnButtonPress, CHANGE);
}




void loop()
{
  sensorValue = analogRead(analogInPin);            
 
  Serial.print("sensor = " );
  Serial.println(sensorValue);      
 
  delay(1000);
  Blynk.run();
}

#2

As per the instructions you erased in order to post…

Your void loop() is also a little busy… and delayed… both bad combinations :stuck_out_tongue_winking_eye:


#3


#4

I tried so but still nothing? a help?

#define BLYNK_PRINT Serial   

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

char auth[] = "xxx";  

const  int analogInPin = A0;
int sensorValue = 0;
int lastValue = 0;


void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
  pinMode(analogInPin, INPUT);
}

void loop()
{ 
  Blynk.run();

  sensorValue = analogRead(analogInPin);
Serial.println(sensorValue);

if (sensorValue == 800 && lastValue == 0) {
  Serial.println("is on, send notification");
  Blynk.notify("light on");
  lastValue = 0;
  delay(1000);
//send notification
    
  } 
  else if (sensorValue == 1000 && lastValue == 0) {
    
  Serial.println("light off");
  delay(1000);
  }
  else {
    //st
    Serial.println("no send notification");
    lastValue = 0;
    delay(1000);
  }
  
  delay(100);
}

#6

do you have any improvements to do?
it works

#define BLYNK_PRINT Serial   

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

char auth[] = "xxx";  

const  int analogInPin = 0;
int sensorValue = 0;
int lastValue = 1000;


void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
  pinMode(analogInPin, INPUT);
}

void loop()
{ 
  Blynk.run();

  sensorValue = analogRead(analogInPin);
Serial.println(sensorValue);

if (sensorValue < 500 && lastValue == 1000) {
  Serial.println("is on, send notification");
  Blynk.notify("light on");
  lastValue = 1000;
  delay(3000);
//send notification
    
  } 
  else if (sensorValue > 1000 && lastValue == 0) {
  Serial.println("light off");
  delay(3000);
  }

  }

#7

One big improvement would be to get rid of this and do it properly with timers.

Pete.


#8

I improved your posts by properly formatting the code as you were instructed to do :wink:

Otherwise, no, not really… your loop is still full there and is still use of delays… reread ALL those links I sent you.