using this module with arduino
and also using the same code(https://www.youtube.com/watch?v=hhBe1gnvCC4) but on my LCD it only display 0 rather than to displayRPM
Welcome to the forum
Without seeing your code any schematic it is impossible to provide any help
Please post both
only difference is that rather than speed sensor i use ne555 module
I see that you decided to ignore the advice on posting code on the forum
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27, 16, 2);
const byte PulsesPerRevolution = 1;
const unsigned long ZeroTimeout = 10000;
const byte numReadings = 1;
volatile unsigned long LastTimeWeMeasured;
volatile unsigned long PeriodBetweenPulses = ZeroTimeout + 100;
volatile unsigned long PeriodAverage = ZeroTimeout + 1000;
unsigned long FrequencyRaw;
unsigned long FrequencyReal;
unsigned long RPM;
unsigned int PulseCounter = 1;
unsigned long PeriodSum;
unsigned long LastTimeCycleMeasure = LastTimeWeMeasured;
unsigned long CurrentMicros = micros();
unsigned int AmountOfReadings = 1;
unsigned int ZeroDebouncingExtra;
unsigned long readings[numReadings];
unsigned long readIndex;
unsigned long total;
unsigned long average;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
attachInterrupt(digitalPinToInterrupt(2), Pulse_Event, RISING);
delay(1000);
}
void loop() {
LastTimeCycleMeasure = LastTimeWeMeasured;
CurrentMicros = micros();
if (CurrentMicros < LastTimeCycleMeasure) {
LastTimeCycleMeasure = CurrentMicros;
}
FrequencyRaw = 10000000000 / PeriodAverage;
if (PeriodBetweenPulses > ZeroTimeout - ZeroDebouncingExtra || CurrentMicros - LastTimeCycleMeasure > ZeroTimeout - ZeroDebouncingExtra) {
FrequencyRaw = 0; // Set frequency as 0.
ZeroDebouncingExtra = 2000;
} else {
ZeroDebouncingExtra = RPM;
}
FrequencyReal = FrequencyRaw / 10000;
RPM = FrequencyRaw / PulsesPerRevolution * 60;
RPM = RPM / 100000;
total = total - readings[readIndex];
readings[readIndex] = RPM;
total = total + readings[readIndex];
readIndex = readIndex + 1;
if (readIndex >= numReadings) {
readIndex = 0;
}
average = total / numReadings;
Serial.print("Period: ");
Serial.print(PeriodBetweenPulses);
Serial.print("\tReadings: ");
Serial.print(AmountOfReadings);
Serial.print("\tFrequency: ");
Serial.print(FrequencyReal);
Serial.print("\tRPM: ");
Serial.print(RPM);
Serial.print("\tTachometer: ");
Serial.println(average);
lcd.setCursor(0, 0);
lcd.print("RPM : ");
delay(500);
lcd.print(RPM);
lcd.print(" ");
}
void Pulse_Event() {
PeriodBetweenPulses = micros() - LastTimeWeMeasured;
LastTimeWeMeasured = micros();
if (PulseCounter >= AmountOfReadings) {
PeriodAverage = PeriodSum / AmountOfReadings;
PulseCounter = 1;
PeriodSum = PeriodBetweenPulses;
int RemapedAmountOfReadings = map(PeriodBetweenPulses, 4000, 5000, 1, 10);
RemapedAmountOfReadings = constrain(RemapedAmountOfReadings, 1, 10);
AmountOfReadings = RemapedAmountOfReadings;
} else {
PulseCounter++;
PeriodSum = PeriodSum + PeriodBetweenPulses;
}
}
Thank you
Please remember to use code tags in future
yes afcource
Try adding
pinMode(2, INPUT_PULLUP);
at the beginning of setup().
What do you see on Serial Monitor?
The code you copied was written by someone who is only a little more advanced than a beginner, it may need so many corrections that it might be better to delete it and write new code.
What will your final project be used for?
Which jumper frequency do you have on the 555 module?
Hi vaishnavi_gunjal,
It might be interesting to consult the sketches here:
Success, photoncatcher
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.