i have tried many times. But i still cannot display my count in the blynk app.
my project is like a counter. The count is always changing.
i store the count as a variable named “c_red”.
How can i display the value in blynk app using “value display widget”?
sometimes, the “value display widget” is showed “0” but the value is not changing with the real situation.
hope someone can help.
thank you.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#define BLYNK_PRINT DebugSerial
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "f7a82f44b45e4d78aa12ef7865262c48";
void sendSeconds() {
Blynk.virtualWrite(V0, millis() / 1000);
}
void sendMillis() {
Blynk.virtualWrite(V1, millis());
}
LiquidCrystal_I2C lcd(0x27,16,2);
#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6
Servo topServo;
Servo bottomServo;
int frequency = 0;
int color=0;
int c_red=0;
int c_blue=0;
int c_green=0;
int c_brown=0;
int c_yellow=0;
int c_orange=0;
void setup() {
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(Serial, auth);
timer.setInterval(1000L, sendSeconds);
// Setup a function to be called every second
timer.setInterval(1000L, sendMillis);
lcd.init();
lcd.begin(16,2);
lcd.backlight();//Power on the back light
lcd.setCursor(1,0);
pinMode(13, INPUT);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
// Setting frequency-scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
topServo.attach(7);
bottomServo.attach(8);
}
void loop() {
Blynk.run();
timer.run();
topServo.write(123);
delay(500);
for(int i = 115; i > 68; i--) {
topServo.write(i);
delay(2);
}
delay(500);
color = readColor();
delay(10);
switch (color) {
case 1:
bottomServo.write(35);
c_red++;
Blynk.virtualWrite(V3,c_red);
break;
case 2:
bottomServo.write(63);
c_orange++;
break;
case 3:
bottomServo.write(87);
c_green++;
break;
case 4:
bottomServo.write(130);
c_yellow++;
break;
case 5:
c_brown++;
break;
case 6:
bottomServo.write(175);
c_blue++;
break;
case 0:
break;
}
delay(300);
for(int i = 68; i > 24; i--) {
topServo.write(i);
delay(2);
}
delay(200);
for(int i = 29; i < 115; i++) {
topServo.write(i);
delay(2);
}
color=0;
}
// Custom Function - readColor()
int readColor() {
// Setting red filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int R = frequency;
// Printing the value on the serial monitor
Serial.print("R= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
lcd.print("R=");//printing name
lcd.print(c_red);//printing RED color frequency
lcd.print(" ");
Blynk.virtualWrite(V3, c_red);
lcd.print("OG=");//printing name
lcd.print(c_orange);//printing RED color frequency
lcd.print(" ");
delay(50);
// Setting Green filtered photodiodes to be read
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int G = frequency;
// Printing the value on the serial monitor
Serial.print("G= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
lcd.print("G=");//printing name
lcd.print(c_green);//printing RED color frequency
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Y=");//printing name
lcd.print(c_yellow);//printing RED color frequency
lcd.print(" ");
delay(50);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int B = frequency;
// Printing the value on the serial monitor
Serial.print("B= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.println(" ");
lcd.print("BW=");//printing name
lcd.print(c_brown);//printing RED color frequency
lcd.print(" ");
lcd.print("BL=");//printing name
lcd.print(c_blue);//printing RED color frequency
lcd.print(" ");
lcd.setCursor(1,0);
delay(50);
if(R<100 & R>80 & G<160 & G>130){
color = 1; // Red
}
if(R<80 & R>55 & B<115 & B>85){
color = 2; // Orange
}
if(B<109 & B>80 & G<109 & G>80){
color = 3; // Green
}
if(R<79 & R>50 & G<90 & G>65){
color = 4; // Yellow
}
if(R<125 & R>101 & B<120 & B>101){
color = 5; // Brown
}
if (G<120 & G>100 & B<80 &B>55){
color = 6; // Blue
}
return color;
}
BLYNK_READ(V5)
{
int sensorData = c_red;
Blynk.virtualWrite(V5, sensorData);
}