Hello everyone,
I am new to this forum and i have an problem with my project so plz help me to get out of it..I shall be very thankful to you.
actually i want to perform several task as follows:-
-
i had connected an turbine sensor to digital pin 2 .
-
now i want to count the no of pulses generated for every 20ms
-
then i want to serially print those values after receiving 'a' on serial port.
below is my code i am using but having problem:-
#include "TimerOne.h"
int flowPin = 2;
int x = 0;
volatile int count = 0;
char b ;
void setup()
{
pinMode(flowPin, INPUT); //Sets the pin as an input
pinMode(13,OUTPUT);
Timer1.initialize(20000);
attachInterrupt(0, Flow, RISING);
Timer1.attachInterrupt(check);
Serial.begin(9600);
}
void loop()
{
if (Serial.available() >0 )
{
b = Serial.read ();
}
}
void check()
{
x= count;
if (b == 'a')
{
Serial.println(x);
}
count = 0;
}
void Flow()
{
count++; //Every time this function is called, increment "count" by 1
}
with this code my result of serial.println(x) are not acuurate. So plz help in resolving this problem