Newbe help

Hi guys, first congrats on a great platform.
I am only a couple of days old here, and have a small project running, monitoring the pool temperature and changing lights depending on the temp.
Now, in the original implementation, before the IOT version, I had the lights to get on for a sec, then off and on and so on. This was done with a simple delay and a loop turning the outputs of the arduino on and off. Now when I use Blynk, the delay causes disconnects and cannot be used. Tried to play a bit with timers but no cigar. The code works (turns on and changes colors) as well provides data with no issues besides the flashing.
I hope that you can tell me how to fix that, I guess its a simple thing for someone with experience.

Here is my code:

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxx”;

int ThermistorPin = 1;
int Vo;
int button;
int light;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
float batt;
int mailflag;
char ssid[] = “xx”;
char pass[] = “1234”;

BlynkTimer timer;

#define EspSerial Serial
#define ESP8266_BAUD 115200
#define BLYNK_MAX_READBYTES 256

ESP8266 wifi(&EspSerial);

void setup() {
button = 0;

batt = 0;
mailflag = 0;
EspSerial.begin(ESP8266_BAUD);

Blynk.begin(auth, wifi, ssid, pass,“blynk-cloud.com”, 80);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(2, LOW); //Green Right 4
digitalWrite(3, LOW); //RED Right 4
digitalWrite(4, LOW); //Blue down 2
digitalWrite(5, LOW); //Green down 2
digitalWrite(6,LOW); // RED down 2
digitalWrite(7, LOW); //BLUE top 2
digitalWrite(8, LOW); // Green top 2
digitalWrite(9, LOW); // RED top 2
digitalWrite(10, LOW); // BLUE LEFT 4
digitalWrite(11, LOW); //Green LEFT 4
digitalWrite(12, LOW); //RED LEFT 4
digitalWrite(13, LOW); //Blue Right 4

timer.setInterval(1000L, sendSensor);
timer.setInterval(1000L, PinAction );
Blynk.email("xx, “Boat on line”, “Running.”);
}

BLYNK_WRITE(V2) // button attached to Virtual Pin 1 in SWITCH mode
{
int state = param.asInt();
if (state ==1)
{
button = 1;
}
else if (state ==0)
{
button = 0;
}

}

void PinAction(){

if ((light < 50) or (button == 1)) { // Zone 1

 if (Tc >= 25) { // turn red
   digitalWrite(2, LOW); //Green Right 4
   digitalWrite(3, LOW);  //RED Right 4
   digitalWrite(4, HIGH); //Blue down 2
   
   digitalWrite(5, LOW); //Green down 2
   digitalWrite(6,LOW); // RED down 2
   digitalWrite(7, HIGH); //BLUE top 2
   
   digitalWrite(8, LOW); // Green top 2
   digitalWrite(9, LOW); // RED top 2
   digitalWrite(10, HIGH); // BLUE LEFT 4
   
   digitalWrite(11, LOW); //Green LEFT 4
   digitalWrite(12, LOW); //RED LEFT 4
   digitalWrite(13, HIGH); }//Blue Right 4   

       
else if ((Tc < 25 ) && (Tc)>20) { 
   digitalWrite(2, LOW); //Green Right 4
   digitalWrite(3, HIGH);  //RED Right 4
   digitalWrite(4, LOW); //Blue down 2
   digitalWrite(5, LOW); //Green down 2
   digitalWrite(6,HIGH); // RED down 2
   digitalWrite(7, LOW); //BLUE top 2
   digitalWrite(8, LOW); // Green top 2
   digitalWrite(9, HIGH); // RED top 2
   digitalWrite(10, LOW); // BLUE LEFT 4
   digitalWrite(11, LOW); //Green LEFT 4
   digitalWrite(12, HIGH); //RED LEFT 4
   digitalWrite(13, LOW);} //Blue Right 4 


else if (Tc <=20) { 
   digitalWrite(2, HIGH); //Green Right 4
   digitalWrite(3, LOW);  //RED Right 4
   digitalWrite(4, LOW); //Blue down 2
   digitalWrite(5, HIGH); //Green down 2
   digitalWrite(6,LOW); // RED down 2
   digitalWrite(7, LOW); //BLUE top 2
   digitalWrite(8, HIGH); // Green top 2
   digitalWrite(9, LOW); // RED top 2
   digitalWrite(10, LOW); // BLUE LEFT 4
   digitalWrite(11, HIGH); //Green LEFT 4
   digitalWrite(12, LOW); //RED LEFT 4
   digitalWrite(13, LOW); }//Blue Right 4   

}

if ((light > 50) and (button == 0)) {
digitalWrite(2, LOW); //Green Right 4
digitalWrite(3, LOW); //RED Right 4
digitalWrite(4, LOW); //Blue down 2
digitalWrite(5, LOW); //Green down 2
digitalWrite(6,LOW); // RED down 2
digitalWrite(7, LOW); //BLUE top 2
digitalWrite(8, LOW); // Green top 2
digitalWrite(9, LOW); // RED top 2
digitalWrite(10, LOW); // BLUE LEFT 4
digitalWrite(11, LOW); //Green LEFT 4
digitalWrite(12, LOW); //RED LEFT 4
digitalWrite(13, LOW); }//Blue Right 4}
}

void sendSensor()
{
batt = (analogRead(2) * 10.0) / 1024.0;
Vo = analogRead(ThermistorPin);

R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2logR2 + c3logR2logR2logR2));
Tc = T - 273.15;

light = analogRead(A0);
Blynk.virtualWrite(V0,Tc);
Blynk.virtualWrite(V1,light);
Blynk.virtualWrite(V3,batt);
if (Tc <= 5){
Blynk.setProperty(V0, “color”, “#04C0F8”);
}
else if ((Tc > 5) && (Tc < 25)) {
Blynk.setProperty(V0, “color”, “#23C48E”);
}
else if (Tc >= 25) {
Blynk.setProperty(V0, “color”, “#D3435C”);

}
if (batt <= 6){
Blynk.setProperty(V3, “color”, “#D3435C”);
if (mailflag == 0) {
mailflag = 1;
Blynk.email(“xx@cc.c”, “Subject: Boat BATT LOW”, “Charge the boat”);
}
}
else if (batt > 6) {
Blynk.setProperty(V3, “color”, “#23C48E”);
}
Blynk.syncAll();
//LED_OFF(1000);

}

void loop()
{
BLYNK_WRITE(V2);
Blynk.run();
timer.run();

}

before we could help, format your code please

1 Like

Hi,

Some suggestions:

  1. Remove the syncAll() from your routine, that is only needed in the initial setup() to cause Blynk to write values from the Cloud to your Arduino.
  2. Remove Blynk_Write(V2) from the loop as it will cause Blynk to cut you off as you can only make a few requests a second

Thanks guys.