I have been following this guide (Keep your void loop() clean - Blynk Documentation) to keep my void loop clean. However, Im getting an error of “BlynkTimer does not name a type”. Im using Blynk library v 1.0.1. Is this error related to the new Blynk2.0? (since the article is for Blynk Legacy)
Right now Im writing in void loop and it working just fine.
Its already worked. I dont know what happen, what I did just re-arranged it. BTW, this is my sketch incase you have something in mind. One more thing, is it normal to have delay on Blynk? In my case, Both percentage and LED are delay. But the percentage readings are much more delay.
What’s the purpose of the SIM800, and why have you created a SoftwareSerial port on pins 0 & 1 , which are the hardware serial UART pins that are used here:
And here:
Why is pin 3 being used by both your LCD and debug serial port?…
Im testing SIM800 at the 1st place but then I realised I dont need that for my project (forgot to delete that out, my bad). Anyway, I have corrected mentioned issues. Thanks to you, Pete.
#define BLYNK_TEMPLATE_ID "xxxxxx"
#define BLYNK_DEVICE_NAME "Smart Irrigation"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxxxx"
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>
const int MoistPin = A0;
const int relayPin = 13;
const int WaterPin = A4;
const int WaterrelayPin = 10;
int analogValue;
float MoistValue;
float moist;
float level;
const int drysoil = 1023;
const int wetsoil = 0;
const int lowlevel = 0;
const int highlevel = 1019;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
BlynkTimer timer;
#define BLYNK_PRINT DebugSerial
SoftwareSerial DebugSerial(0, 1); // RX, TX
char auth[] = BLYNK_AUTH_TOKEN;
WidgetLED led1 (V2);
WidgetLED led2 (V3);
#define BLYNK_GREEN "#00b62c"
#define BLYNK_RED "#ff0000"
void setup()
{
DebugSerial.begin(9600);
Serial.begin(9600);
pinMode(relayPin, OUTPUT); // set pin as output
pinMode(WaterrelayPin, OUTPUT); // set pin as output
lcd.begin(20, 4); // set up the LCD's number of columns and rows:
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("Moist. Level:");
lcd.setCursor(0,1);
lcd.print("Watering Pump:");
lcd.setCursor(0,2);
lcd.print("Drainage Level:");
lcd.setCursor(0,3);
lcd.print("Overflow Pump:");
Blynk.begin(Serial, auth);
timer.setInterval(250L,ReadData);
}
void ReadData ()
{
moist = analogRead(MoistPin); //Read Moisture Sensor Value
int percentageMoisture = map(moist, wetsoil, drysoil, 100, 0);
lcd.setCursor(13,0);
lcd.print(percentageMoisture);
lcd.println("%");
if(percentageMoisture < 50)
{
// Relay On
digitalWrite(relayPin, HIGH);
lcd.setCursor(14,1);
lcd.println("ON");
led1.setColor(BLYNK_GREEN);
}
else
{
// Relay Off
digitalWrite(relayPin, LOW);
lcd.setCursor(14,1);
lcd.println("OFF");
led1.setColor(BLYNK_RED);
}
level = analogRead(WaterPin); //Read Moisture Sensor Value
int percentagewaterlevel = map(level, highlevel, lowlevel, 40, 0);
lcd.setCursor(15,2);
lcd.print(percentagewaterlevel);
lcd.println("mm");
if(percentagewaterlevel > 20)
{
//Relay On
digitalWrite(WaterrelayPin, HIGH);
lcd.setCursor(14,3);
lcd.println("ON");
led2.setColor(BLYNK_GREEN);
}
else
{
//Relay Off
digitalWrite(WaterrelayPin, LOW);
lcd.setCursor(14,3);
lcd.println("OFF");
led2.setColor(BLYNK_RED);
}
Blynk.virtualWrite(V0, percentageMoisture);
Blynk.virtualWrite(V1, percentagewaterlevel);
}
void loop()
{
Blynk.run();
timer.run();
} ```
As I said earlier, the Uno has one hardware UART. This is connected to the USB connector at the top of the board in your diagram (via an onboard TTL to Serial adapter) and also to pins 0 and 1.
Your connection to the internet is via this port, yet you have created a SofttwareSerial port that uses the same pins, and sends debug data which should be bound for the serial monitor to the Blynk connection pins.