Good day everyone!
I'm a new arduino user and I need some assistance with a problem I have failed to figure out on my own. I am doing a project of speed control. The speed sensor gives a pulsed output with a peak to peak of 5 V. The frequency of the pulsed output gives the speed of rotation of the motor shaft. I am failing to get my arduino to count the number of pulses properly using the pulseIn function. The values I am getting from the arduino are quite different from what I am expecting when I use a signal generator to provide the pulses.
Attached is my code and an example of what I am getting. I would highly appreciate help on what to do or on where to look for information so that I can benefit through independent learning as well.
Kind regards
uGatsheni
[unsigned long highTime; //variable for storing high time
unsigned long lowTime; //variable for storing low time
unsigned long period; // variable for storing period
unsigned long freq; //variable frequency
unsigned long Speed; // speed
void setup()
{
Serial.begin (57600);
pinMode(47,INPUT); //Setting pin as input
}
void loop()
{
highTime=pulseIn(47,HIGH); //read high time
lowTime=pulseIn(47,LOW); //read low time
period = highTime+lowTime; // Period is a total of high and low time
freq=1000000/highTime*2; //getting frequency with totalTime is in Micro seconds
Speed=freq*60.0; //getting speed from the frequency
Serial.print("Frequency");
Serial.print(" ");
Serial.print(freq);
Serial.print("\t");
Serial.print("Speed");
Serial.print(" ");
Serial.println(Speed);
delay(1000);
}]