I wonder if someone can help? I'm new to this and have done the usual blinking LEDs, PWM tutorials and am now out of my depths trying to marry two sketches together.
I'm trying to build a frames per second monitor (as in video/film frames) to measure revolutions per second (it needs to run from 0 to around 60 fps). I've a Hall Effect sensor working as the trigger working from a magnet that revolves past the sensor.
I believe my wiring is correct, the LCD screen works with a "hello world" sketch and I can run a sketch which blinks the LED when a magnet is passed by the Hall Sensor.
The base sketch I have been adapting is from a rpm outputting to LCD, triggered from an optical sensor. The descriptions I've added, to try and explain to myself what I think is going on (so there is room for plenty of error there).
At the moment when I run the sketch the LED comes on, the LCD lights up with "FPS: " but thats it, when a magnet is wafted by the Hall Sensor LED doesn't blink and the LCD doesn't count any frames, the count remains at 0.
// Compute the Frames Per Second using a Hall Sensor
#include <LiquidCrystal.h>
#define HALL_PIN 8 // Pin for signal from Hall Sensor
#define LED_PIN 13 //Using Arduino's Internal LED; just as an indicator
boolean counted=false; //The results to count are false
int t1=0,t2=0; //Creates variables t1 and t2 and gives them a value of 0
int hits=0;
int rps=0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Sets pins for LCD
void setup(){ //Sets variables
pinMode(HALL_PIN, INPUT); //Sets Pin 9 as the Input from Hall Sensor
pinMode(LED_PIN, OUTPUT); //Sets Pin 13 as output to LED
lcd.begin(16, 2); //Sets the size of the LCD display
}
void loop(){ //The action of the sketch
t2 = millis();
if(t2 >= (t1 + 1000)){
rps = hits;
hits = 0;
t1=t2;
lcd.clear(); //Clears LCD
lcd.print("FPS: "); //Prints text FPS to LCD
lcd.print(rps*1000); //Prints revolutions per second to x 1sec to LCD
}
if(digitalRead(HALL_PIN) == HIGH){ //Counts instances of True from Hall_Pin, pin 8
if(!counted){
counted = true;
hits++;
}
} else {
counted = false;
}
digitalWrite(LED_PIN, digitalRead(HALL_PIN));
if (HALL_PIN == HIGH){ //If the Hall sensor is high turn the LED off
digitalWrite(LED_PIN, LOW);
}
else{
digitalWrite(LED_PIN, HIGH); //If the Hall sensor is low turn the LED on
}
}
I wonder if anyone had any pointers where I'm going wrong (you can see where I'm struggling there are no descriptions).
Has anyone ever seen really good tutorials going though feeding data to LCDs? I've been trawling through tutorials but can't find anything specifically that shows me where I might be going wrong, I've found plenty of tachometer references but not written for an idiot.
If I can get this working I'd like to next bolt on a frame counter, counting the number of times the magnet passes the Hall Sensor… But one thing at a time!
Many thanks in advance.
Gus