Hi.
I have a problem compiling my code, can’t find out what the problem is.
I have reinstalled the program and all the lib´s and updated but still the same problem.
The coding is running smoothly without the Blynk, but when I insert the Blynk coding, my servo stop working and the ultrasonic sensor measurement freeze on the LCD.
I also cannot change the blynk-ser to port 3, instead going to port 1
Here is the error code, can anybody help ?
#define BLYNK_TEMPLATE_ID "TMPLler2LxdY"
#define BLYNK_DEVICE_NAME "Waste Monitoring System in Apartments"
#include <BlynkSimpleStream.h> // Blynk Library
#include <LiquidCrystal_I2C.h> //Library for LCD
#include <Wire.h> //Library for I2C
#include <Servo.h>
Servo SLid;
LiquidCrystal_I2C lcd(0x27, 20, 4); // LCD Address (0x27 for 20 columns and 4 rows)
BlynkTimer timer;
char auth[] = "SgUXLgK3GVDt8j8UnbgFsa9WwBL1oSHG";
int EchoLv1 = 31 ; // Echo Metal Metal = Pin 31
int TrigLv1 = 30 ; // Trig Metal Metal = Pin 32
int GreenLv1 = 50; // LED Green Non-Metal = Pin 8
int RedLv1 = 51; // LED Red Non-Metal = Pin 10
float pingLv1; // Time for ping to travel to target and return
float targetDisLv1; // Distance from sensor to target
float targetDistLv1; // Data sent to Blynk
int PercentageLv1;
int EchoLv2 = 49 ; // Echo Metal Metal = Pin 33
int TrigLv2 = 48 ; // Trig Metal Metal = Pin 34
float pingLv2 ; // Time for ping to travel to target and return
float targetDisLv2; // Distance from sensor to target
float targetDistLv2;
int PercentageLv2;
float speedOfSound = 776.5; // Speed of Sound in Miles per Hour = 776.5
String TeamGroup = " Group 3 Project "; // String for LCD
void setup()
{
Serial.begin(9600); // Turn on Serial Port
Blynk.begin(Serial, auth);
pinMode(EchoLv1, INPUT); // EchoLv1 is Input
pinMode(TrigLv1, OUTPUT); // TrigLv1 is Output
pinMode(EchoLv2, INPUT); // EchoLv2 is Input
pinMode(TrigLv2, OUTPUT); // TrigLv2 is Output
SLid.attach(22);
lcd.init();
lcd.backlight();
//timer.setInterval(300L, GarbageCap); // USMe pause for 0.3 seconds
}
void GarbageCap()
{
digitalWrite(TrigLv1, LOW); // Set TrigMe Low
delayMicroseconds(5); // Pause to set signal settle
digitalWrite(TrigLv1, HIGH); // Set TrigMe High
delayMicroseconds(10); // Pause in high state
digitalWrite(TrigLv1, LOW); // Set TrigMe Low
pingLv1 = pulseIn(EchoLv1, HIGH); // Set EchoMe High
targetDistLv1 = (pingLv1 / 2) / 29.1;
PercentageLv1 = map(targetDistLv1, 100, 10, 0, 100);
//Blynk.write the value of targetDUS3 on V48
lcd.setCursor(0, 0); // Starting with 0 columns and 0 rows
lcd.print(TeamGroup); // Print the LCD with the String given
lcd.setCursor(2, 1); // Starting with 0 columns and 2 rows
lcd.print("Garbage Capacity");
lcd.setCursor(2, 2);
lcd.print("in % : ");
lcd.print(PercentageLv1);
lcd.print("% ");
lcd.setCursor(2, 3);
lcd.print("in CM : ");
lcd.print(targetDistLv1, 2);
Blynk.virtualWrite(V25, targetDistLv1);
Serial.print("\nin % =" );
Serial.print(PercentageLv1);
Serial.print("\nin CM = ");
Serial.print(targetDistLv1, 2);
Serial.print("\n");
if (targetDistLv1 < 20) // Less than 10cm
{
analogWrite(RedLv1, 250); // Red LED Metal will on
analogWrite(GreenLv1, 0); // Green LED Metal will off
lcd.setCursor(2, 3);
lcd.print("Capacity : Full");
}
else
{
analogWrite(RedLv1, 0); // Red LED Metal will off
analogWrite(GreenLv1, 250);
lcd.setCursor(2, 3);
lcd.print("Capacity : Empty");
}
}
void LidMove()
{
digitalWrite(TrigLv2, LOW); // Set TrigMe Low
delayMicroseconds(100); // Pause to set signal settle
digitalWrite(TrigLv2, HIGH); // Set TrigMe High
delayMicroseconds(20); // Pause in high state
digitalWrite(TrigLv2, LOW); // Set TrigMe Low
pingLv2 = pulseIn(EchoLv2, HIGH); // Set EchoMe High
pingLv2 = pingLv2 / 1000000; // Converts ping time to seconds
pingLv2 = pingLv2 / 3600; // Converts ping time to hours
targetDisLv2 = speedOfSound * pingLv2; // Calculate distance in miles
targetDisLv2 = targetDisLv2 / 2; // Accounts for round trip of ping to target
targetDisLv2 = targetDisLv2 * 63360; // Convert targetDistance to inches (63360 inches in a miles)
targetDistLv2 = targetDisLv2 * 2.54; // Conver inches to centimeters (2.54 centimeters in a inches)
SLid.write(0);
if (targetDistLv2 < 20) // Less than 10cm
{
SLid.write(90);
delay(1000);// Servo move to 100 degrees
}
else
{
SLid.write(0); // Servo move to 0 degrees
}
}
void loop()
{
Blynk.run(); // Run Blynk Apps
//timer.run();
//GarbageCap();
GarbageCap();
LidMove();// Run Timer
}