Hi, I’m a beginner at Blynk, and I’m doing a project for a university course.
I need to have the NodeMCU esp8266 read the analog values (A0) for one minute and calculate the average of the read values and send the mean value to the Blynk application on the smatphone. I made an initial code, however I have encountered problems in the script performing the functions I need.
Also, I wonder if there is a way to attach a micro SD card shield to save the average values.
I thank the help of all.
code
<<<<<<<<<<<<<<<<<
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = “token”;
char ssid[] = “apto - 304”;
char pass[] = “244466666”;
BlynkTimer sensor; // Criação do Timer do sensor
String stringOne;
String Stringday;
unsigned long atual;
unsigned long anterior = 0;
const long intervalo = 60000;
unsigned long val = 0.00;
unsigned long s;
float media;
int dia = 0.00;
int minutos = 0;
void lerSensor() // Função para ler os parâmetros do DHT22
{
atual = millis();
if (anterior != atual)
{
int valor = analogRead (A0);
val = val + valor;
s = s + 1.00;
if (atual - anterior >= intervalo )
{
anterior = atual;
media = (val * 3.2226) / s;
minutos++;
if (minutos == 1439.00)
{
dia = dia + 1;
Stringday = dia;
minutos = 0.00;
}
s = 0.00;
val = 0.00;
}
}
Blynk.virtualWrite(V2, media); // Escreve no pino virtual V5 do Blynk o valor de umidade lido pelo DHT22
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
sensor.setInterval(60000L, lerSensor); // Define o intervalo de tempo da leitura para 60000 milisegundos
}
void loop()
{
Blynk.run();
sensor.run(); // Inicializa o Timer
}