Hello,
I found Blynk recently to help build a project and found some issues. I’m using Blynk onr a Particle Photon running 1.4.4 firmware and communicating wifi, and using iOS on the Blynk Server.
I’m reading analog data from 3 weight sensors A0-A3, then having those values, for the moment, being read directly by Blynk. No issue there.
From there, those values are added together to give a Total Weight, which works well.
Using 3 virtual pins, V0,V1, V2, I’m allowing user entry of pounds, displaying Total Weight, and displaying an alert LED, respectively.
The Virtual Alert LED should only go off when the selected setting on the segmented switch is used in conjunction with the Total weight, so if totAna >0, 5, 10, or 25% of the entered weight from V0,
Physically, I have a single LED (light1) wired to D0 to go off at the same time as led1.
I’m not sure if my segment is running correctly, and both LEDs stay on, despite the criteria not being met.
Any help would be appreciated to get this working.
/*************************************************************
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
No coding required for direct digital/analog pin operations!
*************************************************************/
#define BLYNK_PRINT Serial // Set serial output for debug prints
//#define BLYNK_DEBUG // Uncomment this to see detailed prints
#include <blynk.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxx";
//char auth[] = "xxxxxxxxx";
int light1 = D0;// This is where your LED is plugged in. The other side goes to a resistor connected to GND.
//int light2 = D1;
//int light3 = D2;
WidgetLED led1(V3);
int pressure1 = A0; // This is where your photoresistor or phototransistor is plugged in. The other side goes to the "power" pin (below).
int pressure2 = A1;
int pressure3 = A3;
int analog1; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the pressure sensor.
int analog2;
int analog3;
int ledToggle(String command); // Forward declaration
int poundValue;
int poundPercent;
int TTWB;
int totAna;
BLYNK_WRITE(V0)
{
int poundValue;
poundValue = param.asInt(); // assigning incoming value from pin V1 to a variable
//poundPercent =poundValue * .25;
// process received value
// Serial.printlnf("V0 Numeric Input is: ", £Percent, INT);
}
BLYNK_WRITE(V1) {
switch (param.asInt())
{
case 1: { TTWB = 0;
break;
}
case 2: { TTWB = 5;
break;
}
case 3: { TTWB = 10;
break;
}
case 4: { TTWB = poundValue * .25;
break;
}
}
}
void readSensors()
{
Blynk.syncVirtual(V1);
analog1 = analogRead(pressure1);//
analog2 = analogRead(pressure2);
analog3 = analogRead(pressure3);
totAna = analog1 + analog2 + analog3;
Blynk.virtualWrite(V2, totAna);
if (totAna > TTWB){
led1.on();
digitalWrite(light1, HIGH);
Serial.printlnf("%d",totAna);
Particle.publish("Total Weight", String(totAna), PRIVATE);
}
else if (totAna < TTWB) {
led1.off();
digitalWrite(light1,LOW);
}
}
void setup()
{
Serial.begin(9600);
delay(5000); // Allow board to settle
pinMode(light1, OUTPUT);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
readSensors();
}