Hi! This is my first post and of course, I have a problem to solve ![]()
First at all let me say thanks to all the great people of the forum, It would have been impossible to carry out this project without the help of this forum.
I have a project that counts the RPM of my turntable by using a Hall effect sensor, I can see the RPM in a 7 segments 4 digits display and also I can get the time per lap, that is showed in the tetrminal. Everything is working fine by now but I would like to add the time per lap and save it every 30m in the eeprom. So I can check at anytime how many hours has been working.
The time per lap is saved in a variable that counts the time it takes from one sensor detection to the next and I can see the time per lap in seconds.
What I need is add this time every lap and every 30 minuts save this total to the eeprom in hours.
Seems a simple problem but I really can´t get it working. ![]()
Thanks in advanced for your time and help.
Welcome to the forum
Which Arduino are you using ?
Where are you stuck ?
Have you looked at and tried the examples for the EEPROM library ? The put() and get() functions of the library would be the most useful ones for you
Thanks UKHeliBob, I have not tested this part yet but the eeprom save and get data seems not difficult, I´m pretty sure that I can manage this. The major problem is how to add the time per lap and get a total in hours.
I´m using an Arduino UNO.
Post your current sketch, using code tags when you do
Ok, I have not the real code here an now , but it is based on this project: Arduino Tachometer - Using a Hall Effect Sensor (A3144) to Measure Rotations from a Fan — Maker Portal.
I´ve modified the code and I can do some other things wit it, but essentially this is the code I´ve started to work.
As you can see, in this code the variable that show the time per lap is called "time_passed" . Now what I need to do is add this variable every lap and when I get 30 minuts, write this total to the eeprom in hours.
// digital pin 2 is the hall pin
int hall_pin = 2;
// set number of hall trips for RPM reading (higher improves accuracy)
float hall_thresh = 100.0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(115200);
// make the hall pin an input:
pinMode(hall_pin, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// preallocate values for tach
float hall_count = 1.0;
float start = micros();
bool on_state = false;
// counting number of times the hall sensor is tripped
// but without double counting during the same trip
while(true){
if (digitalRead(hall_pin)==0){
if (on_state==false){
on_state = true;
hall_count+=1.0;
}
} else{
on_state = false;
}
if (hall_count>=hall_thresh){
break;
}
}
// print information about Time and RPM
float end_time = micros();
float time_passed = ((end_time-start)/1000000.0);
Serial.print("Time Passed: ");
Serial.print(time_passed);
Serial.println("s");
float rpm_val = (hall_count/time_passed)*60.0;
Serial.print(rpm_val);
Serial.println(" RPM");
delay(1); // delay in between reads for stability
}
Don’t forget there is a limited number of read write cycles for eeprom , so something like an SD card maybe better.
You can buy simple hours run meters which would be an easy option - or emulate one in the Arduino ?
Hammy, I´m not concerned about the eeprom life, keep in mind that we´re talking about a record player, I don´t usit daily and if I usit, I spend one or two hours , so we´re talking about to write a few times per week.
My question is how to add this variable every lap and when I get 30 minuts, write this total to the eeprom in hours.
Seems a simple problem but I´ve tried some different examples and codes that I´ve seen online but no luck yet.
If you are stuck on timing 30 seconds whilst allowing the code in loop() to run freely then see Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE
I think the question is not well exposed.
I have no problem counting the time, I alllready have the time in secods (showed in the terminal in seconds) . What I need is add the time of every lap ("time_passed" variable ) and when it arrives to 30 minuts add this to the total ammount (saved previosly in the eeprom.
You surely know how to add the value of the time_passed variable to a total_time variable so the remaining problems are non blocking timing (see the links in my previous post) and writing the data to EEPROM (see the EEPROM examples)
You're right men, a simple counter will do de job very well. Excuse me for the stupid question.
Regarding the eeprom, seems not very difficult, I'm sure that I can do it.
Cheers