Hi guys mechatronics student with a question Im tasked with building an autonomous biodiesel production machine I already have the PID control but dont know how to make it time dependent. What I want is after the temperatura has reached 40 C to start counting 40 minutes, and the execute the next part of the code. Any help would be appreciated
Have you done much with the Arduino?
I have made small projects and I know my way around it no expert, but in this case I have no Idea on how to approach the time condition without using delays
Purchase a RTC module. You can then get accurate timing.
Record the start time and loop around until the finish time. You can also monitor other things such as temperature in the loop.
Weedpharma
If you don't want to use delay(time), you can use an interrupt from an external timer circuit. Look up 555 timer.
The milis() function will do what you need.
Check the blink without delay tutorial.
millis() is probably accurate enough for 40 minutes.
You can always "adjust" it to 40 minutes.
A 555 timer is sooo last century.
Leo..
blink without delay is somewhat confusing.
you need to have some flag set that shows when you want to start the count.
if (flag = LOW){
if (old_temp == 399 && new_temp = 400){
then = millis();
flag = HIGH;
}.
}
this will set the flag once the temp goes from 399 to 400, but will not work if the temp goes from anything else to 400.
since you set the flag, nothing will change the value of then. use this in the next section.
since you did not say what any other part of your program does, this will probalby not work,. shown here as a learning exercise.
if (millis() - then > 40 minutes){
do that next thing
flag=HIGH;
}
if (flag2-HIGH){
then = millis();
flag = LOW; // need to resett this and all other flags in some way
}
this snippet will NOT work as it is, but you must figure out how to set the flags and find some way to set then to millis() in a way that it will not clear or reset after that point in your process that you want to start counting.
Hi,
What arduino are you using and how are you aiming to displaying the your variables?
Tom....
The demo several things at a time is an extended example of BWoD.
...R
I faced the same problem with my proyect, I am glad to see the answers you received, because my conclusions were very similar.
There is a problem with the "tick" approach with arduino and its application to control system. Usually controlling an Industrial process or machine require a more complex approach, like the "State Machine"
In a "State machine" You need to identify the different states, the things that you are trying to control in this state, and of course the transitions between the different states, for example:
State 1: Filling the tank -> Control Tank level
State 2: Doing chemical reaction -> PID controlling parameter such as temperature, pressure, etc
State 3: Unfilling the tank -> etc
For several tasks to be performed, forget about the delay function, you must use the millis() approach as you have been already explained.
It you need to track time and dates, for very long tasks (once a month, every sunday, etc), you need a RTC (Real Time Clock) that will be make possible to track dates and times. Adafruit has a fantastic tutorial about RTC in Using the Real Time Clock | Adafruit Data Logger Shield | Adafruit Learning System. I doubt you need this, because you are asking about controls in forty minutes, millis() function is capable of tracking the time in this time frame.
Arduino has very limited resources to implement a complex a State machine, therefore my approach has been the following:
- Identify the tasks/states that have to work every tick
- Identify the tasks that have to work every other period of time (Ex. Every 40 minutes)
- identify the tasks that need to work when some conditions are fulfilled
In the loop function I divide my code accordingly:
-
Tasks that need to be performed in real time (each tick):
Example: Comunications, parameter control (of different states), etc -
Tasks that need to be performed in a time frame calculated with millis():
Example: every 40 minutes, opening or closing a valve -
Tasks that need to be according some conditions: alarm, errors, etc
Of course if you have several states in your machine, this approach would be a mess... you need other hardwar or professional solutions.