Hi, I have some problems with my coding. Until now I managed to do this code which is working mostly ok. Now I want to control relays with IF functions, but it doesn’t work, and I don’t know why. Sorry for ugly code, in future I will fix it also. I thought numeric input didn’t work, but then I tried to see pin V15 and value is correct, if I change it, otherwise is 0. Hope someone can help me with this. Thanks in advance!
Details :
• Arduino +ESP8266 via tx rx + wifi
Android
• Blynk server
• Blynk Library newest
#include <BlynkSimpleShieldEsp8266.h>
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <DHT.h>
#define ON 1
#define OFF 0
int rele1 = 3;
int rele2 = 4;
int rele3 = 5;
int rele4 = 6;
char auth[] = "";
char ssid[] = "";
char pass[] = "";
#define aref_voltage 3.3
#define THERMISTORPIN A0
#define THERMISTORNOMINAL 10000
#define TEMPERATURENOMINAL 25
#define NUMSAMPLES 5
#define BCOEFFICIENT 3950
#define SERIESRESISTOR 10000
uint16_t samples[NUMSAMPLES];
#define ESP8266_BAUD 115200
ESP8266 wifi(&Serial);
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
float h = dht.readHumidity();
float t = dht.readTemperature();
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
byte TempGretja;
BLYNK_WRITE(V0)
// This function will be calLED every time Widget
// in Blynk app writes values to the Virtual Pin V2
{
TempGretja = param.asInt(); // Assigning incoming value from pin V0 to variable
Blynk.virtualWrite(V11, TempGretja);
Serial.println(TempGretja);
}
int TempHlajenja;
BLYNK_WRITE(V1)
{
TempHlajenja = param.asInt(); // Assigning incoming value from pin V0 to variable
Blynk.virtualWrite(V12, TempHlajenja);
Serial.println(TempHlajenja);
}
float Toleranca;
BLYNK_WRITE(V2)
{
Toleranca = param.asFloat(); // Assigning incoming value from pin V0 to variable
Blynk.virtualWrite(V13, Toleranca);
Serial.println(Toleranca);
}
void setup()
{
pinMode (rele1, OUTPUT);
digitalWrite (rele1, HIGH);
pinMode (rele2, OUTPUT);
digitalWrite (rele2, HIGH);
pinMode (rele3, OUTPUT);
digitalWrite (rele3, HIGH);
pinMode (rele4, OUTPUT);
digitalWrite (rele4, HIGH);
// Debug console
Serial.begin(9600);
analogReference(EXTERNAL);
delay(10);
// Set ESP8266 baud rate
Serial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void (* resetFunc) (void) =0;
BLYNK_WRITE(V10) // Reset
{
if (param.asInt()==1) {
resetFunc();
delay(100);
}
}
void loop(){
if (t < TempGretja){
digitalWrite (rele1, LOW);}
else if (t > TempGretja) {
digitalWrite (rele1, HIGH);}
uint8_t i;
float average;
// take N samples in a row, with a slight delay
for (i=0; i< NUMSAMPLES; i++) {
samples[i] = analogRead(THERMISTORPIN);
delay(10);
}
// average all the samples out
average = 0;
for (i=0; i< NUMSAMPLES; i++) {
average += samples[i];
}
average /= NUMSAMPLES;
// convert the value to resistance
average = 1023 / average - 1;
average = SERIESRESISTOR / average;
float steinhart;
steinhart = average / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V4, steinhart);
Blynk.run();
timer.run();
delay(1000);
Blynk.virtualWrite(V15, TempGretja);
}