Ok,so,first of all,the delay is for a ultrasonic sensor and it would be more complicated to add a timer
Second,i was reffering to the
{
digitalWrite(Releu,LOW);
delay(2000);
}
else
{
digitalWrite(Releu,HIGH);
}
and if you saw posts like this and if you can help me with that.
and as for the sensor and etc,i can figure them out but first,i need help with that if.
Think of it like a car:what’s the point on repairing the body if the engine isn’t working
I might be too dumb to make this work,because i’m a begginer but i just need to insipire from someone so i should know what to when i encounter similar situations
i tried for almost 4 hours to make this code work
#define BLYNK_TEMPLATE_ID "TMPL4J58z1nC7"
#define BLYNK_TEMPLATE_NAME "Nextlab"
#define BLYNK_AUTH_TOKEN "EIU_I1FTjr8odEmX7V38s5ul0Kz9_QDw"
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Eu_xxx";
char pass[] = "adelin26";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(11, 12); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#include <Servo.h>
#include <Ultrasonic.h>
#include <DHT.h>
#include <LiquidCrystal.h>
#define ultrasonic_pin 2
#define DHTPIN A1
#define DHTTYPE DHT11
#define Flacara A3
#define Releu 13
int servoPin = 3,distanta,temp,hum;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DHT dht(DHTPIN, DHTTYPE);
//Servo servo;
Ultrasonic ultrasonic(ultrasonic_pin);
BlynkTimer timer;
bool controlReleu = HIGH;
void setup() {
dht.begin();
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
//Blynk.begin(auth, wifi, ssid, pass);
pinMode(Releu,OUTPUT);
pinMode(Flacara,INPUT);
lcd.begin(16,2);
lcd.clear();
timer.setInterval(500L,releu);
//servo.attach(servoPin);
digitalWrite(Releu,controlReleu);
}
void loop() {
Blynk.run();
timer.run();
temp = dht.readTemperature();
hum = dht.readHumidity();
lcd.setCursor(0,0);
lcd.print("Temperatura:");
lcd.print(temp);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Umiditate:");
lcd.print(hum);
lcd.print("%");
distanta=ultrasonic.read();
delay(100);
}
void releu()
{
int flacara=digitalRead(Flacara);
Serial.print(flacara);
int ok=0;
if (flacara == LOW) {
controlReleu=LOW;
digitalWrite(Releu, LOW);
ok=1;
}
else if(ok==0||controlReleu==LOW)
timer.setTimeout(2000L, []() {
digitalWrite(Releu, HIGH);
controlReleu=HIGH;
});
}
I know that this code isn’t the most efficient and up to the blynk standards but i just want to find out how should i do my if.In this example,by my logic it should work,but it won’t.After i resolve with the if i could start putting my other things in timers and arrange my loop void