Need help on my project

hi pete thanks…
this code without BLYNK function get from internet it.s work fine.
now i try to add BLYNK function so i can see air flow speed from my smartphone.
until now still not work hahaha…huhuhu…

any friend can help? huhuhu…

where’s the issue?
tell me more

‘wifi’ was not declared in this scope

wifi connect all ok…blynk app show ONLINE but coding not work as my plan…it should work like this
when fan turning IR sensor sens RPM that fan and 7 led will be on follow rmp speed…
this code without blynk function it work…but after add blynk function , wifi connection to blynk server ok but no RPM huhuhu

and it compiles without error ?

yes…no error…

i think my be problem with this code
attachInterrupt not function or wrong location…

    attachInterrupt(sensorInterrupt, &sensorIsr, RISING);  //Isr = interrupt service routine
     lastPulseTime = 0;

I have to change your code to simulate your ISR sensor and test blynk leds
your board isn’t a nodeMCU ?

my board arduino uno and ESP8266 wifi module

rpm = 61000000UL/(interval * 2);

......

attachInterrupt(sensorInterrupt, &sensorIsr, RISING);  //Isr = interrupt service routine
     lastPulseTime = 0;

were do you got the rpm value from your sensor ?
never !
:joy::wink:

from my coding without blynk function. i use i2c lcd display or serial monitor to display RPM value
here original coding and it work

 // wiring : IR sensor =D2
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2);  // 0x27 or 39 or 0x3F

//RPM--------------------------------------------------------------
//Configuration for the Tachometer variables
const int sensorPin = 2;
const int sensorInterrupt = 0;
volatile unsigned long lastPulseTime;
volatile unsigned long interval = 0;
//volatile int timeoutCounter;

int rpm;
int rpmlast = 3000;
int led1 = 6;
int led2 = 7;
int led3 = 8;
int led4 = 9;
int led5 = 10;
int led6 = 11;
int led7 = 12;



void setup()
{  
   Serial.begin(9600);
    pinMode(sensorPin, INPUT);
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
    pinMode(led3, OUTPUT);
    pinMode(led4, OUTPUT);
    pinMode(led5, OUTPUT);
    pinMode(led6, OUTPUT);
    pinMode(led7, OUTPUT);
    
  attachInterrupt(sensorInterrupt, &sensorIsr, RISING);  //Isr = interrupt service routine
  lastPulseTime = 0;
  // sets the LCD's rows and colums:
  lcd.init();
  lcd.backlight();            
  lcd.begin(16, 2); 
  //lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("arduino RPM:");
  delay(1000);
  lcd.clear();

  digitalWrite(led1,HIGH);
    digitalWrite(led3,LOW);
    digitalWrite(led2,LOW);
    digitalWrite(led4,LOW);
    digitalWrite(led5,LOW);
    digitalWrite(led6,LOW);
    digitalWrite(led7,LOW);
} 
  
void loop()
{
  if(rpm >= 0) {  //Remove the error readings of minus values   
    
    //Let's keep this RPM value under control, between 0 and 9999
    rpm = constrain (rpm, 0, 9999); // make sure value on this range
  
    
   if ((micros() - lastPulseTime) < 5e6 ) {  // micro()= is time since arduino start running program
      rpm = rpm;
    }
   Serial.println(rpm);  
  if(rpm >=499 && rpm<=500){
    digitalWrite(led1,HIGH);
    digitalWrite(led3,LOW);
    digitalWrite(led2,LOW);
    digitalWrite(led4,LOW);
    digitalWrite(led5,LOW);
    digitalWrite(led6,LOW);
    digitalWrite(led7,LOW);
    
  }
 if(rpm >=500 && rpm<=1000){
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
    digitalWrite(led3,LOW);
    digitalWrite(led4,LOW);
    digitalWrite(led5,LOW);
    digitalWrite(led6,LOW);
    digitalWrite(led7,LOW);
    
 }
    if(rpm >=1000 && rpm<=1500){
    digitalWrite(led3,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
    digitalWrite(led4,LOW);
    digitalWrite(led5,LOW);
    digitalWrite(led6,LOW);
    digitalWrite(led7,LOW);
 }
 if(rpm >=2500 && rpm<=3000){
    digitalWrite(led3,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
    digitalWrite(led4,HIGH);
    digitalWrite(led5,LOW);
    digitalWrite(led6,LOW);
    digitalWrite(led7,LOW);
 }
 if(rpm >=3500 && rpm<=4000 ){
    digitalWrite(led3,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
    digitalWrite(led4,HIGH);
    digitalWrite(led5,HIGH);
    digitalWrite(led6,LOW);
    digitalWrite(led7,LOW);
 }
 if(rpm >=4000 && rpm<=4700 ){
    digitalWrite(led3,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
    digitalWrite(led4,HIGH);
    digitalWrite(led5,HIGH);
    digitalWrite(led6,HIGH);
    digitalWrite(led7,LOW);
 }
 if(rpm >=4700 ){
    digitalWrite(led3,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
    digitalWrite(led4,HIGH);
    digitalWrite(led5,HIGH);
    digitalWrite(led6,HIGH);
    digitalWrite(led7,HIGH);
 }
 else {
   
      rpm =rpm;
    }
  }  

   
 // printRPM();
  Serial.println(rpm);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("___TACHOMETER___");
lcd.setCursor(0,1);
lcd.print(     rpm);
lcd.print(" RPM");
lcd.print("   ");
  delay(500);
}

void sensorIsr() {
  unsigned long now = micros();
  interval = now - lastPulseTime;
  if (interval > 5000){
     rpm = 61000000UL/(interval * 2);
     lastPulseTime = now;
  }
}

could you try something like that and tell me what you see:

.
.
.
.

int sensorPin = 2;
int state=0;
int laststate=0;
.
.
.
void setup()
timer.setInterval(300L, sensorIsr); 
{
.
.
.
void sensorIsr() {
state =  digitalRead(sensorPin );
Serial.println(state);
 }

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

so no need to use interrupt function?

attachInterrupt(sensorInterrupt, &sensorIsr, RISING);  //Isr = interrupt service routine
  lastPulseTime = 0;

I don’t see how you can achieve this without the use of an interrupt.

I gave you a simple solution before, which is:

  • Establish a counter (global integer) that will be incremented each time an interrupt occurs.
  • Attach the interrupt and each time an interrupt occurs, increment your counter.
  • Use a timer that runs every second. When the timer is triggered call a routine that takes your pulse count for the past second and does something with it (converts it into miles per hour, feet per second or just sticks with pulses per second) then uploads this to Blynk and writes it to your LCD and resets your interrupt counter to zero.

If you find that you’re experiencing issues then detach the interrupt before doing any processing of the results for the past second, then re-attach it after the process is completed.
If you don’t need to see the results on a second-by-second basis then increase the timer to every 5 or 10 seconds.

A nice superchart in Blynk will show you your history, and you can plot other data like temperature and humidity as well on the same chart if you wish.

Pete.

interrupt seems better for your project, and it works without your blynk code.
but I can’t test your blynk code.
so I think you have just to test the input to know if all is ok for Blynk without interrupt .

ok …let me try…
thanks friend…later i update what is progress…i so happy we have community with good helper friend…

1 Like

have in mind that interrupt stop the loop …

ooo…maybe i need try find other way without using interrupt…TQ friend…

That’s the whole idea!
When the signal on the interrupt pin goes HIGH (rising) the interrupt routine is called, then the code resumes where it left off.
In this case, all you’ll be doing in the interrupt routine isincrementing a counter, so it won’t have a disruptive effect on Blynk.
When the code called by the timer is executed (after a second, or more, has elapsed) it will do something with the results - calculate windspeed, upload to Blynk, write to LCD display etc. You don’t want this code to be interrupted by an interrupt, so you detach the interrupt at the start of the block of code called by the timer, do your processing, then re-attach the interrupt at the end of the block of code.

I’m my mind it doesn’t make any sense to be doing these timed calculations more than once every 5 or 10 seconds, but I guess it depends on what the results are meant to show.

Pete.