Hi! I need a little help with my project…
I have 3 sensors as gauges and a button which turns on a digital output with a relay. The point is that when I upload the code only the 3 sensor work properly but the button don’t. When I upload the code without the sensors the button works. I hope you can help me! thank you all.
Hello, My issue is that I’m using a button widget controlling the gp4 output. But now I tried the button as a virtual with some code still without success…
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 16 //D3
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define pino_sinal_analogico A0 //SENSOR SOLO
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
char auth[] = "";
/* WiFi credentials */
char ssid[] = "";
char pass[] = "";
/* TIMER */
#include <SimpleTimer.h>
SimpleTimer timer;
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 5 // D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
#define rele_1 4 //D4
void sensor_temp_agua()
{
float temp;
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Blynk.virtualWrite(10, temp); //virtual pin V10
Serial.print("TEMP AGUA: ");
Serial.print(temp);
Serial.print(" ºC");
Serial.print(" - ");
if(temp > 32)
{
Blynk.notify("TEMPERATURA DO AQUARIO ACIMA DE 27ºC");
}
}
void sensor_agua()
{
int valor_analogico;
int linhaagua;
valor_analogico = analogRead(pino_sinal_analogico);
linhaagua = (100 - ((valor_analogico / 9.2) - 100));
Blynk.virtualWrite(11, linhaagua); //virtual pin V11
Serial.print("NIVEL AGUA: ");
Serial.print(linhaagua);
Serial.print(" %");
Serial.print(" - ");
if(linhaagua < 80)
{
Blynk.notify("REPOSIÇÃO DE ÁGUA");
}
}
void sensor_dht_t()
{
float t = dht.readTemperature();
Blynk.virtualWrite(12, t); //virtual pin V12
Serial.print("TEMP AMBIENTE: ");
Serial.print(t);
Serial.print(" ºC");
Serial.print(" - ");
}
void sensor_dht_h()
{
float h = dht.readHumidity();
Blynk.virtualWrite(13, h); //virtual pin V13
Serial.print("UMID AMBIENTE: ");
Serial.print(h);
Serial.print(" %");
Serial.println(" - ");
Serial.println("IOT.BRS");
}
BLYNK_WRITE(V0) // Run this function when V1 button pressed.
{
int pinValue = param.asInt(); // Get status of V1.
if (pinValue == 1) { // If status of V1 is 1 then do stuff in if().
digitalWrite(4, LOW); // Turn on LED.
}
}
void setup() {
Serial.begin(115200);
pinMode(rele_1, OUTPUT);
digitalWrite(rele_1, HIGH);
pinMode(pino_sinal_analogico, INPUT);
Blynk.begin(auth, ssid, pass);
DS18B20.begin();
dht.begin();
delay(1000);
timer.setInterval(1000L, sensor_agua);
timer.setInterval(1100L, sensor_temp_agua);
timer.setInterval(1200L, sensor_dht_t);
timer.setInterval(1300L, sensor_dht_h);
}
void loop() {
Blynk.run();
timer.run(); // Initiates SimpleTimer
}