Please help, my blynk wont update my value

Please help, i dont know what is wrong with my code, the lcd on blynk app wotn update the value

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
char auth[] = "20f26fd8dbfb4d41b138e777a939f336";
WidgetLCD lcd1(V4);
WidgetLCD lcd2(V5);
BlynkTimer timer;


#include <Servo.h>
 Servo TopServo;
 Servo BottomServo;

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 10, 11, 12, 7);

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;

#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3

#define S0 2                            //Color Sensor Attaching Number
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6

#define work11 7
#define work22 8

int candy = 0;
int candy_in = 0;                            
int frequency = 0;
int color = 0;

int blue;
int green;
int red;
int bluee;
int greenn;
int redd;
int blueee;
int greennn;
int reddd;


int readColor() {
 
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);                       // Setting red filtered photodiodes to be read
  
  frequency = pulseIn(sensorOut, LOW);         // Reading the output frequency
  
  int R = frequency;                           // Printing the value on the serial monitor
 
  Serial.print("R= ");                         //printing name
  Serial.print(frequency);                     //printing RED color frequency
  Serial.print("  ");
  delay(50);
 
  
  digitalWrite(S2, HIGH);                     // Setting Green filtered photodiodes to be read
  digitalWrite(S3, HIGH);
 
  frequency = pulseIn(sensorOut, LOW);         // Reading the output frequency
  
  int G = frequency;                           // Printing the value on the serial monitor
  
  Serial.print("G= ");                         //printing name
  Serial.print(frequency);                     //printing GREEN color frequency
  Serial.print("  ");
  delay(50);
  
  digitalWrite(S2, LOW);                       // Setting Blue filtered photodiodes to be read
  digitalWrite(S3, HIGH);
 
  frequency = pulseIn(sensorOut, LOW);         // Reading the output frequency
  
  int B = frequency;                           // Printing the value on the serial monitor
 
  Serial.print("B= ");                         //printing name
  Serial.print(frequency);                     //printing BLUE color frequency
  Serial.println("  ");
  delay(50);

  if(R < G && R < B ){
    color = 1;
  }
  if(G < R && G < B ){
    color = 2;
  }
  if(B < G && B < R ){
    color = 3;
 }
  return color;
 }

 int read_candy(){  
candy_in = analogRead(1);
Serial.println(analogRead(1));

if (candy_in < 200) return work11;
if (candy_in > 500) return work22;}

// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor 
 Serial.println(analogRead(0));
   
 if (adc_key_in < 250)  return btnUP; 
 if (adc_key_in < 450)  return btnDOWN; 
 if (adc_key_in < 650)  return btnLEFT; 
  
}
void project (){
 
  Blynk.virtualWrite(V0, millis() / 1000);
  Blynk.virtualWrite(V1, millis() / 60000);
  lcd1.print(0, 0, " COLOR SORTING ");
  blueee = bluee;
  lcd2.print(0, 1, "                 ");
  lcd2.print(1, 1, "Blue Candy = ");
  lcd2.print(14, 1, blueee);
  reddd = redd;
  lcd1.print(0, 1, "                 ");
  lcd1.print(0, 1, "Red Candy = ");
  lcd1.print(13, 1, reddd);
  greennn = greenn;
  lcd2.print(0, 0, "                 ");
  lcd2.print(0, 0, "Green Candy = ");
  lcd2.print(14, 0, greennn);
  
  
  lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons

 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnDOWN:
     {
        redd = red;  
        lcd.print("Red Candy = ");                          //printing name
        lcd.print(redd);                                     //printing RED color frequency
        lcd.print("  "); 
      break;
     }
   case btnLEFT:
     {
        greenn = green;
        lcd.print("Green Candy= ");                                 //printing name
        lcd.print(greenn);                                           //printing GREEN color frequency
        lcd.print("  ");                                          //GREEN
    
     break;
     }
   case btnUP:
     {
       bluee = blue; 
       lcd.print("Blue Candy= ");                                //printing name
       lcd.print(bluee);                                          //printing BLUE color frequency
       lcd.print("  ");                                        //BLUE 
     break;
     } 
     
     }
     
 candy = read_candy();


 
 switch (candy)
  {
    case work11:
  {
    
      lcd.setCursor(0,0);            // move to the begining of the first line  
      lcd.print(" CANDY DETECTED ");
      Serial.println("CANDY DETECTED");
      for(int i = 120; i > 55; i--) {
      TopServo.write(i);}       
  
      delay(1000);
  
        color = readColor();
    
        switch (color) {
    
        case 1:{
        BottomServo.write(60);
        delay(1000);
        for(int i = 55; i > 35; i--) {
        TopServo.write(i);} 
       
        red = red +1;  
        Serial.print("Red Candy = ");                          //printing name
        Serial.print(red);                                     //printing RED color frequency
        Serial.println("  "); 
        
        
       break;}
    
    case 2:{
    BottomServo.write(120);
    delay(1000);
    for(int i = 55; i > 35; i--) {
    TopServo.write(i);
    }  
       green = green +1;
       Serial.print("Green Candy= ");                                 //printing name
       Serial.print(green);                                           //printing GREEN color frequency
       Serial.println("  ");                                          //GREEN
       
       
      break;}
    
    case 3:{
    BottomServo.write(180);
    delay(1000);
    for(int i = 55; i > 35; i--) {
    TopServo.write(i);
    } 
       blue = blue +1; 
       Serial.print("Blue Candy= ");                                //printing name
       Serial.print(blue);                                          //printing BLUE color frequency
       Serial.println("  "); 
       
       
       break;
      }}
     
    
    delay(300);
  
 for(int i = 35; i < 120; i++) {
    TopServo.write(i);
    delay(2);
  }
 delay(500);
 

  }  

case work22:{

lcd.setCursor(0,0);            // move to the begining of the second line  
 lcd.print("    NO CANDY    ");
 Serial.println("    NO CANDY    ");  
 }
 }
return;}


  
  
void setup()
{ 
  SwSerial.begin(9600);
  Serial.begin(9600);
  timer.setInterval(1000L, project);
  
  Blynk.begin(Serial, auth);

  
  
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  lcd.print("Color Sensor"); // print a simple message

  pinMode(LED_BUILTIN, OUTPUT);

  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);

  digitalWrite(S0, HIGH);               //Setting frequency-scaling to 20%
  digitalWrite(S1, LOW);

  TopServo.attach (A2);                  //Servo Attaching number
  BottomServo.attach(A3);

  TopServo.write (120);
  delay(500);
  
  BottomServo.write (120);
  delay(500);
 
  lcd1.clear();
  lcd2.clear();
  
  lcd1.print(0, 0, " COLOR SORTING "); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd1.print(0, 1, "    MACHINE     ");
  
  lcd2.print(0, 0, " COLOR SORTING "); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd2.print(0, 1, "    MACHINE     ");
  
  }

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

}

Well, without knowing much more about your project, seeing what DOES show up on the LCD widget, and taking more time than most will want to run or read through your code… we don’t know either :stuck_out_tongue_winking_eye:

Perhaps you can provide us more details?.. We are not on-call code doctors here, we try to help others learn about Blynk.

BTW, It looks like you have gone through the trouble of setting up a 2nd software serial port for diagnostics… SwSerial… but then print all your serial statements across the same Serial port that Blynk uses to communicate with… How does your project even stay connected?

1 Like

I actually dont know it so well also about coding, i made this code all by copy and paste, first before i want to connect my project to blynk, i use this code

#include <Servo.h>
 Servo TopServo;
 Servo BottomServo;

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 10, 11, 12, 7);

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;

#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3




#define S0 2                            //Color Sensor Attaching Number
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6

#define work11 7
#define work22 8

int candy = 0;
int candy_in = 0;                            
int frequency = 0;
int color = 0;





int blue;
int green;
int red;
int bluee;
int greenn;
int redd;

void setup() {                          // put your setup code here, to run once:

  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  lcd.print("Color Sensor"); // print a simple message

  pinMode(LED_BUILTIN, OUTPUT);

  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);

  digitalWrite(S0, HIGH);               //Setting frequency-scaling to 20%
  digitalWrite(S1, LOW);

  TopServo.attach (A2);                  //Servo Attaching number
  BottomServo.attach(A3);

  TopServo.write (120);
  delay(500);
  
  BottomServo.write (120);
  delay(500);
  
  Serial.begin(9600); }
 

void loop() { // put your main code here, to run repeatedly:
 
 lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons

 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnDOWN:
     {
        redd = red;  
        lcd.print("Red Candy = ");                          //printing name
        lcd.print(redd);                                     //printing RED color frequency
        lcd.print("  "); 
      break;
     }
   case btnLEFT:
     {
        greenn = green;
        lcd.print("Green Candy= ");                                 //printing name
        lcd.print(greenn);                                           //printing GREEN color frequency
        lcd.print("  ");                                          //GREEN
    
     break;
     }
   case btnUP:
     {
       bluee = blue; 
       lcd.print("Blue Candy= ");                                //printing name
       lcd.print(bluee);                                          //printing BLUE color frequency
       lcd.print("  ");                                        //BLUE 
     break;
     }}
 candy = read_candy();


 
 switch (candy)
  {
    case work11:
  {
    
      lcd.setCursor(0,0);            // move to the begining of the first line  
      lcd.print("CANDY DETECTED  ");
      delay(1000);
      Serial.println("CANDY DETECTED");
      delay (1000);
      
      for(int i = 120; i > 55; i--) {
      TopServo.write(i);}       
  
      delay(1000);
  
        color = readColor();
    
        switch (color) {
    
        case 1:{
        BottomServo.write(60);
        delay(1000);
        for(int i = 55; i > 35; i--) {
        TopServo.write(i);} 
       
        red = red +1;  
        Serial.print("Red Candy = ");                          //printing name
        Serial.print(red);                                     //printing RED color frequency
        Serial.println("  "); 
        lcd.print("Red Candy = ");                          //printing name
        lcd.print(red);                                     //printing RED color frequency
        lcd.print("  ");                                                      //RED
       break;}
    
    case 2:{
    BottomServo.write(120);
    delay(1000);
    for(int i = 55; i > 35; i--) {
    TopServo.write(i);
    }  
       green = green +1;
       Serial.print("Green Candy= ");                                 //printing name
       Serial.print(green);                                           //printing GREEN color frequency
       Serial.println("  ");                                          //GREEN
       lcd.print("Green Candy= ");                                 //printing name
       lcd.print(green);                                           //printing GREEN color frequency
       lcd.print("  ");
      break;}
    
    case 3:{
    BottomServo.write(180);
    delay(1000);
    for(int i = 55; i > 35; i--) {
    TopServo.write(i);
    } 
       blue = blue +1; 
       Serial.print("Blue Candy= ");                                //printing name
       Serial.print(blue);                                          //printing BLUE color frequency
       Serial.println("  "); 
       lcd.print("Blue Candy= ");                                //printing name
       lcd.print(blue);                                          //printing BLUE color frequency
       lcd.print("  "); //BLUE 
       break;
      }}
     
    
    delay(300);
  
 for(int i = 35; i < 120; i++) {
    TopServo.write(i);
    delay(2);
  }
 delay(500);
break;
  }  

case work22:{

lcd.setCursor(0,0);            // move to the begining of the second line  
 lcd.print("    NO CANDY    ");
 delay(1000);
 Serial.println("    NO CANDY    ");  
 delay (1000);
break;
}}}

int readColor() {
 
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);                       // Setting red filtered photodiodes to be read
  
  frequency = pulseIn(sensorOut, LOW);         // Reading the output frequency
  
  int R = frequency;                           // Printing the value on the serial monitor
 
  Serial.print("R= ");                         //printing name
  Serial.print(frequency);                     //printing RED color frequency
  Serial.print("  ");
  delay(50);
 
  
  digitalWrite(S2, HIGH);                     // Setting Green filtered photodiodes to be read
  digitalWrite(S3, HIGH);
 
  frequency = pulseIn(sensorOut, LOW);         // Reading the output frequency
  
  int G = frequency;                           // Printing the value on the serial monitor
  
  Serial.print("G= ");                         //printing name
  Serial.print(frequency);                     //printing GREEN color frequency
  Serial.print("  ");
  delay(50);
  
  digitalWrite(S2, LOW);                       // Setting Blue filtered photodiodes to be read
  digitalWrite(S3, HIGH);
 
  frequency = pulseIn(sensorOut, LOW);         // Reading the output frequency
  
  int B = frequency;                           // Printing the value on the serial monitor
 
  Serial.print("B= ");                         //printing name
  Serial.print(frequency);                     //printing BLUE color frequency
  Serial.println("  ");
  delay(50);

  if(R < G && R < B ){
    color = 1;
  }
  if(G < R && G < B ){
    color = 2;
  }
  if(B < G && B < R ){
    color = 3;
 }
  return color;
 }

 int read_candy(){  
candy_in = analogRead(1);
Serial.println(analogRead(1));

if (candy_in < 200) return work11;
if (candy_in > 500) return work22;}

// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor 
 Serial.println(analogRead(0));
   
 if (adc_key_in < 250)  return btnUP; 
 if (adc_key_in < 450)  return btnDOWN; 
 if (adc_key_in < 650)  return btnLEFT; 
  
}

and it works fine without internet, what i want to do is only printing the value of red, blue, green candy in widget lcd that available on blynk, please help

Also one more thing, i use UNO and serial USB for connection to internet, in case it is needed

I fixed your post… use 3 backticks, not two.

Yes, I know… and as I pointed out, you are tying to use the same Serial port for both that network/Blynk connection and the serial prints… you can NOT do that! Instead, use the SwSerial you setup for the serial prints (along with the TTL-USB adapter and another terminal program).

It is important that you have some small degree of programming ability (beyond copy/paste) when venturing beyond Blynk’s basic GPIO control, otherwise how could one even understand how to implement our suggestions?

I already change it to 0,1
at first it is working, but after i change my laptop wifi, it doesnt work, do anyone know why?