As I search/learning at the forum for the USB and Arduino Mega connection and the output still not appearing on the blynk apps.I came across a discussion about [SOLVED] Device offline (UNO using USB-link) and i follow the step.
and another one i follow the https://examples.blynk.cc/?board=Arduino%20Mega%202560&shield=Serial%20or%20USB&example=GettingStarted%2FBlynkBlink. and try and error with the codding. All is connected but only the output is not appeared
The serial is for TTL USB adapter, correct me if im wrong, that i need to comment out the Serial because of a direct connection and follow the http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/usb-serial for the bat
BlynkTimer timer;
char auth[] = "cabb6d95d9804956b25f9e4553fc10b8";
// Metal
int GreenMe =5 ;
int YellowMe =6 ;
int RedMe =7;
int EchoMe =38 ;
int TrigMe =39 ;
float pingUS1 ;
float targetDUS1;
float targetDUS3;
String GarbageCaps1me="The Garbage Capacity for Metal is 0%";
String GarbageCaps2me="The Garbage Capacity for Metal is 50%";
String GarbageCaps3me="The Garbage Capacity is for Metal 100%";
// Non - Metal
int GreenNo =8;
int YellowNo =9;
int RedNo =10;
int EchoNo =44;
int TrigNo =45;
float pingUS2;
float targetDUS2;
float targetDUS4;
String GarbageCaps1no="The Garbage Capacity for Non-Metal is 0%";
String GarbageCaps2no="The Garbage Capacity is Non-Metal 50%";
String GarbageCaps3no="The Garbage Capacity is Non-Metal 100%";
float speedOfSound=776.5;
String GarbageLCD="Garbage Capacity";
void USMe()
{
digitalWrite(TrigMe, LOW);
delayMicroseconds(100);
digitalWrite(TrigMe, HIGH);
delayMicroseconds(20);
digitalWrite(TrigMe, LOW);
pingUS1 = pulseIn(EchoMe, HIGH);
pingUS1 = pingUS1/1000000;
pingUS1 = pingUS1/3600;
targetDUS1 = speedOfSound*pingUS1;
targetDUS1 = targetDUS1/2;
targetDUS1 = targetDUS1*63360;
targetDUS3 = targetDUS1*2.54;
Serial.print("The distance to the trash is: ");
Serial.print(targetDUS3);
Serial.println(" centimeters");
Blynk.virtualWrite(V48, targetDUS3);
if (targetDUS3 < 10)
{
Serial.println(GarbageCaps3me);
analogWrite(RedMe, 250);
analogWrite(YellowMe, 0);
analogWrite(GreenMe, 0);
}
else
{
analogWrite(RedMe, 0);
}
if (targetDUS3 >= 11 && targetDUS3 <= 20)
{
Serial.println(GarbageCaps2me);
analogWrite(YellowMe, 250);
analogWrite(RedMe, 0);
analogWrite(GreenMe, 0);
}
else
{
analogWrite(YellowMe, 0);
}
if (targetDUS3 >20)
{
Serial.print(GarbageCaps1me);
analogWrite(GreenMe, 250);
analogWrite(RedMe, 0);
analogWrite(YellowMe, 0);
}
else
{
analogWrite(GreenMe, 0);
}
}
void USNo()
{
digitalWrite(TrigNo, LOW);
delayMicroseconds(100);
digitalWrite(TrigNo, HIGH);
delayMicroseconds(20);
digitalWrite(TrigNo, LOW);
pingUS2 = pulseIn(EchoNo, HIGH);
pingUS2 = pingUS2/1000000;
pingUS2 = pingUS2/3600;
targetDUS2 = speedOfSound*pingUS2;
targetDUS2 = targetDUS2/2;
targetDUS2 = targetDUS2*63360;
targetDUS4 = targetDUS2*2.54;
Serial.print("The distance to the trash is: ");
Serial.print(targetDUS4);
Serial.println(" centimeters");
Blynk.virtualWrite(V49, targetDUS4);
if (targetDUS4 < 10)
{
Serial.println(GarbageCaps3no);
analogWrite(RedNo, 250);
analogWrite(YellowNo, 0);
analogWrite(GreenNo, 0);
}
else
{
analogWrite(RedNo, 0);
}
if (targetDUS4 >= 11 && targetDUS4 <= 20)
{
Serial.println(GarbageCaps2no);
analogWrite(YellowNo, 250);
analogWrite(RedNo, 0);
analogWrite(GreenNo, 0);
}
else
{
analogWrite(YellowNo, 0);
}
if (targetDUS4 >20)
{
Serial.print(GarbageCaps1no);
analogWrite(GreenNo, 250);
analogWrite(YellowNo, 0);
analogWrite(RedNo, 0);
}
else {
analogWrite(GreenNo, 0);
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(Serial, auth);
pinMode(EchoMe, INPUT);
pinMode(TrigMe, OUTPUT);
pinMode(EchoNo, INPUT);
pinMode(TrigNo, OUTPUT);
timer.setInterval(300L, USMe);
timer.setInterval(500L, USNo);
}
void loop()
{
Blynk.run();
timer.run();
}