Im using an ultrasonic parallax sensor and a tmp36 sensor. What code do i have to use in order to get measurements every 30 seconds?
void loop()
{
read_sensors();
delay(30000);
}
Or:
long unsigned int last_time = 0;
void loop()
{
if ((mills() - last_time )> 30000) {
last_time = mills();
read_sensor();
}
}
I want my sensors to get activated every 30 seconds for 2 seconds and get at least 5 samples per second. What do i have to do?
Write some code, post it here and we'll have a look at it.
Don't forget to use code tags.
I dont know what is going on with baud rate and the samples.
I dont know what is going on with baud rate and the samples.
Neither do we. You will have to explain more about the sensors and how they are read.
Use a variable to keep track of the start of the current 30-second interval.
Use another variable to keep track of when you last took a sample.
Use another variable to keep track of whether the sensors are currently on
If millis() - start of the current 30-second interval >= 30 seconds, then:
either increment start of the current 30-second interval by 30 seconds, or just set it = to millis(),
turn on the sensor, note the fact that the sensor s on
take a sample
note the time you took the sample
otherwise, If millis() - start of the current 30-second interval >= 2 seconds, then:
if the sensor is on,
turn it off, and make a not of the fact that the sensor is now off
otherwise, you must be in the 2-second sample taking interval
if millis() - the time you took the last sample > 400, then
take another sample
record the time you took the sample
Now if your sensors need some sort of startup time, they need to be on for a little time before you take that first sample, then you'll need to modify this logic a bit.