i build my own GSR sensor with arduino and i am using this simple code to get the values to the serial monitor. But now i want to implement a text every 5th second (for example when it begins "picture1" after 5 seconds "picture2" and so on. how should the code look like for this or how can i do this
Code:
const int GSR=A0;
int sensorValue=0;
int gsr_average=0;
void setup(){
Serial.begin(9600);
}
void loop(){
long sum=0;
for(int i=0;i<10;i++) //Average the 10 measurements to remove the glitch
{
sensorValue=analogRead(GSR);
sum += sensorValue;
delay(5);
}
gsr_average = sum/10;
Serial.println(gsr_average);
}
i also attach a picture of the serial monitor how it should look like
It really depends on what values you want printed. 5 seconds is 5000 milliseconds so delay(5000) will cause your loop to only run every 5 seconds. Otherwise, you could timestamp an unsigned long in setup() with the current value of millis() then run your loop and each pass through check to see if the system time (millis()) has elapsed 5 seconds -> (millis() - current_time) > 5000. If so, output to the monitor and update current_time to the systems time.
Since you mention pic1, pic2, etc. it may also be helpful for you to get familiar with arrays. You can start at file/examples/control/arrays, found in the IDE.