I am using esp-01 and uno. I have updated my ESP with ESP8266_NONOS_SDK-master. Everything is great so far. With blynk I can send data with DHT22. and I can view it with iPhon. The problem starts with this point. There is no problem displaying data. but when I want to control the relay or LED with the virtual button, I can not achieve this. no problem just burning virtual buttons and leds. but the two are not together.
Or is it happening?
here is my code…
#include <SimpleTimer.h>
#include <avr/wdt.h>
#include <stdlib.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#include <DHT_U.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#define DHTPIN 12
#define DHTTYPE DHT22
#define RAINPIN A3
SimpleTimer timer;
char auth[] = "eXXX4";
char ssid[] = "denger";
char pass[] = "asdasdas";
SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
// Select your pin with physical button
const int btnPin = 8;
int pin13 = 13;
int phpin = A5;
float t=0;
float n=0;
//float ph=0;
float h=0;
DHT dht(DHTPIN, DHTTYPE);
WidgetLED led1(V29);
WidgetLED led3(V31);
//BlynkTimer timer;
// V3 LED Widget represents the physical button state
boolean btnState = false;
void buttonLedWidget()
{
// Read button
boolean isPressed = (digitalRead(btnPin) == LOW);
// If state has changed...
if (isPressed != btnState) {
if (isPressed) {
led3.on();
} else {
led3.off();
}
btnState = isPressed;
}
}
void data(){
float h = dht.readHumidity();
float t = dht.readTemperature();
float n = analogRead(A3) / 9.31;
float ph = analogRead(phpin);
Blynk.virtualWrite(V20, t);
Blynk.virtualWrite(V21, h);
Blynk.virtualWrite(V22, n);
Blynk.virtualWrite(V23, ph);
Serial.print("Ph=");
Serial.println(ph);
Serial.print("ISI=");
Serial.println(t);
Serial.print("NEM=");
Serial.println(h);
Serial.print("toprak nem=");
Serial.println(n);
}
void setup()
{
// Debug console
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
// Setup physical button pin (active low)
pinMode(btnPin, INPUT_PULLUP);
timer.setInterval(500L, buttonLedWidget);
timer.setInterval(500L, data);
}
BLYNK_WRITE(V4)
{int pinValue = param.asInt(); // Get the state of the VButton
if (pinValue == 0)
{(digitalWrite(pin13,LOW),led1.off());} else {digitalWrite(pin13,HIGH),led1.on();}
}
void loop()
{
Blynk.run();
timer.run();
}