'How do i send data from my esp8266 light sensor to blynk?
I am trying to know whether the lights have tripped using a light sensor to detect light intensity. However, i do not know how to upload my data onto blynk, as i am new to blynk and new to arduino as well. Below is my code. I tried using a telegram bot to get the data but somehow it stopped working and i am finding alternatives to get the data remotely. If there are any other methods other than Blynk please suggest too.
#include <ESP8266WiFi.h> // WIFI LIBRARY
#include <WiFiClient.h> //CLIENT LIBRARY
#include <ESP8266WebServer.h> //WEBSERVICER LIBRARY
#include <ESP8266HTTPClient.h> //HTTP CLIENT LIBRARY
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "ArchiEngStudio";
char pass[] = "a12345678";
int CNT = 0, sent, i, j;
float count = 0;
int limit = 800; // SET LIMIT HERE
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
float reading = analogRead(A0);
Serial.println(reading);
delay(3000);
/* NO LIGHT CONDITION */
if (reading < limit)
{
if (CNT < 1) // CHECK LOOP ONLY RUNS ONCE
{
count = 0;
for (i=0; i<10; i++) //TAKING 10 READINGS TO CHECK IF LIGHTS ARE REALLY OFF
{
delay(1000);
int read2 = analogRead(A0);
Serial.println(read2);
if (read2 < limit)
{
Serial.println("(1) No Light ...");
}
else
{
Serial.println("(1) Light on...");
i= i+20;
}
}
if (i < 11) // IF ALL 10 READINGS SHOW THAT LIGHTS ARE OFF, SEND MESSAGE
{
if (sent == 0)
{
Serial.println("Tripped!");
sent = 1;
}
}
}
CNT++;
}
else
{
CNT = 0;
}
/* LIGHTS ON CONDITION */
if (sent == 1) //ONLY ALLOWED IF LIGHTS WERE OFF
{
if (reading >= limit)
{
for (j=0; j<10; j++) //TAKING 10 READINGS TO CHECK IF LIGHTS ARE REALLY ON
{
delay(1000);
int read3 = analogRead(A0);
Serial.println(read3);
if (read3 >= limit)
{
Serial.println("(2) Light on...");
}
else
{
Serial.println("(2) No light...");
j= i+10;
}
}
if (j < 11) //IF ALL 10 READINGS SHOW THAT LIGHTS ARE ON, SEND MESSAGE
{
Serial.println("Light on!");
sent = 0;
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|