Hello Arduino Community,
I tried many times now but i just cant figure this thing out. Maybe its an impossible Task.
My code isnt even worth posting because it just doesnt work.
I had some smaller projects whom i handled with smaller frustration, but not this one....
This is the Task:
I have 8 Flow Sensors in future there could even be 16 Sensors.
I want to read all Sensors for 10000ms each and then take the average which i would store in some variables in the meanwhile to get the flow value.
Seems easy until i mention that i want to read all Sensors for 10s at the same time, as you all know the delay function stops my loop after each analogRead for 10s so i can only read one after another.
Now we come to the problem, which is that IF there is a flow stop for more than 10s (more like 15s but i need some safety time) the machine i need to check the flow on could've already gone into an error state.
That means by the time im measuring the 3rd sensor the flow on Sensor 1 already could have stopped and then i get an Error, thus i would be already to late to execute my safety routine.
Shorter reading times per Sensor are not really practical because i get really inconsistent values that way. Pump flow is not so consistent.
This project is a lost cause for me i just dont now what to do, i tried with interrupts and the millis function but i couldnt even make those work...
Is there any way i can even measure multiple analog's for a set amount of time or is the arduino not meant for such applications? If so, is there hardware that IS capable of managing such a task for a decent budget? Because the product im developing should be relative low cost like <250€ for the hardware side of the flow operation.
Also excuse my english because im from Germany.
Thanks to all of you up front!
If you post your code, then we may be able to help. See "How to use this forum" at the top of the forum.
From your description, it sounds like your project is a good candidate for using the millis() function. Read the "Demonstration code for several things at the same time" thread at the top of the forum.
Rather than doing them all sequentially, it sounds like you need to read sensor 1, store value, read sensor 2 store value, .... until you read sensor 8 and store that value.
Do this for 10 seconds (Look at the Blink Without Delay example in the IDE to figure out how to avoid delay())
After 10 seconds have passed, you can then perform your average of each sensor.
Please post a link to the sensor datasheet and let us know which Arduino you are using.
If the flow is watched for safety reasons, a running average can be computed at each iteration of loop(), and an alert can be signaled as soon as some threshold value is exceeded for a certain time at any channel.
Have an array to store the values of all channels, and a for loop over the number of analog channels to watch. In that loop you get a new value from the ADC for the current channel and build the next smoothed average value for that channel. If the value is out of bounds then start debouncing, until you signal an alert if the excessive value persists after the debounce interval.
Study the IDE examples for how to avoid delay() for the various tasks in your project.
First of all, l thanks for the help guys!
I will try to recode everything and use the millis function and some arrays in the near future, if it works i post the code here.
In order for us to actually help we will nneed to see a data sheet for the sensor and see your code.
One question is why you need to read all at the same time. Most processes are not sso dynamic as to need such a high speed data collection.
if you have all analog outputs, you will need to read each device twice. discard the first reading.
then move to the next.
delay() should not be anywhere near your sketch
some sensors are smart and you send a signal to take a reading. which they then do.
then you reach out to the sensor and ask for the value of the last reading.
if you used that same concept ( i KNOW some will hate this idea) and use one NANO or Mini for each sensor.
you could send a signal to all 'now' like bring pin 6 high or some such.
then, each would receive that signal at the same time, and start to do the reading of the sensor.
no, you can poll each for the reading.
it would take much longer to poll each and get the average value of the readings, but hey, we are in the dark as to what you want to do and what you are using.