hello Blynker, i make prject blynk to read RPM with Tachometer optocopler U, in serial monitor value sensor is shown and accuarcy, i add blynk code for display RPM value oon blynk app, but the Value is not Shown in Virtual Pin on Value Display, please help me, here’s my code i’m attcah
> #define BLYNK_USE_DIRECT_CONNECT
>
> // You could use a spare Hardware Serial on boards that have it (like Mega)
> #include <SoftwareSerial.h>
> SoftwareSerial DebugSerial(2, 3); // RX, TX
>
> #define BLYNK_PRINT DebugSerial
> #include <BlynkSimpleSerialBLE.h>
>
> BlynkTimer timer;
>
>
> // You should get Auth Token in the Blynk App.
> // Go to the Project Settings (nut icon).
> char auth[] = "YourAuthToken";
>
> int val;
> long last=0;
> int stat=LOW;
> int stat2;
> int contar=0;
>
> int sens=75; // this value indicates the limit reading between dark and light,
> // it has to be tested as it may change acording on the
> // distance the leds are placed.
> int nPalas=2; // the number of blades of the propeller
>
> int milisegundos=500; // the time it takes each reading
>
>
> void sendSensor()
> {
> val=analogRead(0);
> if(val<sens)
> stat=LOW;
> else
> stat=HIGH;
> digitalWrite(13,stat); //as iR light is invisible for us, the led on pin 13
> //indicate the state of the circuit.
>
> if(stat2!=stat){ //counts when the state change, thats from (dark to light) or
> //from (light to dark), remmember that IR light is invisible for us.
> contar++;
> stat2=stat;
> }
> if(millis()-last>=milisegundos){
> double rpm=((double)contar/nPalas)/2.0*60000.0/(milisegundos);
> Serial.print(" RPM");Serial.print(rpm);
> Blynk.virtualWrite(V5, rpm);
> contar=0;
> last=millis();
> }
> }
>
> void setup()
> {
> Serial.begin(9600);
> pinMode(13,OUTPUT);
> DebugSerial.begin(9600);
>
> DebugSerial.println("Waiting for connections...");
>
> // Blynk will work through Serial
> // 9600 is for HC-06. For HC-05 default speed is 38400
> // Do not read or write this serial manually in your sketch
> Serial.begin(9600);
> Blynk.begin(Serial, auth);
> timer.setInterval(1000L, sendSensor);
>
> }
>
> void loop()
> {
> Blynk.run();
> timer.run();
>
> }
but RPM sensor works, i get these example code for read tachometer RPM from here https://playground.arduino.cc/Learning/Tachometer the code can work perfect and verry accuracy if display in serial monitor
I’m sorry guys, correct me if I’m wrong, but this code will probably not gonna work with Blynk. Reason? The loop() which in this code is supposed to repeatedly run very fast (as it will miss a lot of state changes otherwise).
This the fragment, I’m talking about:
val=analogRead(0);
if(val<sens)
stat=LOW;
else
stat=HIGH;
digitalWrite(13,stat); //as iR light is invisible for us, the led on pin 13
//indicate the state of the circuit.
if(stat2!=stat){ //counts when the state change, thats from (dark to light) or
//from (light to dark), remmember that IR light is invisible for us.
contar++;
stat2=stat;
}
Then the situation is even worse, as the above (aftr adaptation for Blynk) is called with timer only ONCE per second. So how it can count pulses which suppose to happen even hundreds times per second??
That code will not work IMHO… But, maybe I’m wrong…
here’s my complete code, if i’m not use blynk code, the value can shown on serial monitor, i modified it for blynk app, but value can’t shown on blynk app.
#define BLYNK_USE_DIRECT_CONNECT
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "d02c6d571f6146d4a9a14f69d8a7c434";
int val;
long last=0;
int stat=LOW;
int stat2;
int contar=0;
int sens=75; // this value indicates the limit reading between dark and light,
// it has to be tested as it may change acording on the
// distance the leds are placed.
int nPalas=2; // the number of blades of the propeller
int milisegundos=500; // the time it takes each reading
void sendSensor()
{
val=analogRead(A0);
if(val<sens)
stat=LOW;
else
stat=HIGH;
digitalWrite(13,stat); //as iR light is invisible for us, the led on pin 13
//indicate the state of the circuit.
if(stat2!=stat){ //counts when the state change, thats from (dark to light) or
//from (light to dark), remmember that IR light is invisible for us.
contar++;
stat2=stat;
}
if(millis()-last>=milisegundos){
double rpm=((double)contar/nPalas)/2.0*60000.0/(milisegundos);
//Serial.print(" RPM");Serial.print(rpm);
Blynk.virtualWrite(V5, rpm);
contar=0;
last=millis();
}
}
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
DebugSerial.begin(9600);
DebugSerial.println("Waiting for connections...");
// Blynk will work through Serial
// 9600 is for HC-06. For HC-05 default speed is 38400
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
thank’s for help me, would you give me example, i need blynk to measure RPM with tachomter optocoupler, i get the original code from this site https://playground.arduino.cc/Learning/Tachometer and imodified to dicplay on blynk. please help
You are using the wrong tools for the job… Blynk is an IoT application, not a simple display. It requires its own communication channel that will get disrupted by a real time data stream as you require. Compromises will need to be made by putting your sensor reading into a timed loop, even 10 times a second may interfere, but much less than thousands of times a second.
I pointed you earlier - find a code with interrupts- those should work. I do have some, but currently I’m too busy to dig into it. Perhaps this evening (CET)
I’m very confused about the hardware you’re using.
What board are you using ?
I assume you’re using an Android phone/tablet?
Do you have a BLE widget in your sketch?
Does your device show as being online in Blynk?
What connections do you have to your board?