Go Down

### Topic: Find the run time of a machine (Read 414 times)previous topic - next topic

#### Jeevaa

##### Nov 22, 2019, 07:58 am
I have a machine, where i calculate no of rotations of a shaft using proximity induction sensor to find the production. I also want to calculate total runtime of a machine. So help me to calculate the runtime of a machine...

#### PaulRB

#1
##### Nov 22, 2019, 08:03 amLast Edit: Nov 22, 2019, 08:09 am by PaulRB
Simple. Just use millis() function. The only moderately difficult part will be detecting when the machine has stopped. You will need to set a timeout period after each detection to determine when the machine has stopped.

Will you need to keep the total long-term running time of the machine, even if the Arduino it switched off?

Post the code you have now and we can suggest changes to it.

#### Jeevaa

#2
##### Nov 22, 2019, 08:36 am
This is the basic structure of my code

const int proximity = 2;
int rotation=0;
int prod_conv;
float production;
int sensorState;

void setup()
{
pinMode(proximity, INPUT);

}

void loop()
{
if (sensorState != 0)
{
rotation = rotation+1; //to find no of rotations
}
if( rotation%8==0)
{
prod_conv = rotation/8; //for every 8 rotation prod_conv increases
}
production = prod_conv*433.2; //here 433.2 is a constant

}

#3

#### gilshultz

#4
##### Nov 22, 2019, 10:40 pm
Consider using a RTC (Real Time Clock) that has backed up RAM as well.  For me I would use Unix time as it is very easy to work with. Save the start in backed up ram and EEPROM if you like. Then every so often you can save in battery memory then maybe once an hour or so save it in EEPROM as well.
Good Luck & Have Fun!
Gil

#### Jeevaa

#5
##### Nov 23, 2019, 03:41 am

[/quote]
Consider using a RTC (Real Time Clock) that has backed up RAM as well.  For me I would use Unix time as it is very easy to work with. Save the start in backed up ram and EEPROM if you like. Then every so often you can save in battery memory then maybe once an hour or so save it in EEPROM as well.
Good Luck & Have Fun!
Gil
I am new to Arduino,so can you give some examples

#### Paul__B

#6
##### Nov 23, 2019, 05:05 am
Then every so often you can save in battery memory then maybe once an hour or so save it in EEPROM as well.
If you have a RTC with BBRAM, why would you need to consign it to EEPROM?

Go Up