Hi guys im working on a project and is there a way to delay the loop when it goes high? Such as when pin 11 goes high the loop will take 5 mins. in order to start again.
#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_2 = CapacitiveSensor(7, 6); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(3000); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
if (total1 > 50)
{
digitalWrite(11, HIGH);
delay(5000);
} else {
digitalWrite(11, LOW);
}
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing
Serial.println(total1); // print sensor output 1
Serial.print("\t");
delay(100); // arbitrary delay to limit data to serial port
}
The delay() function delays your code for a time given in a milliseconds. 5 minutes have (560) 300 seconds, or (3001000) 300,000 milliseconds. You can change your code to this:
I need to start the delay after the pin gets high. making the delay into 300000 will set the pin high for 5 minutes I need to idle the Arduino for 5 minutes before next reading starts thanks
Resonance1214:
I need to start the delay after the pin gets high. making the delay into 300000 will set the pin high for 5 minutes I need to idle the Arduino for 5 minutes before next reading starts thanks
That is exactly what the code does. I think that you need to explain your problem in a different way so we can understand,
Currently:
if total1 > 50
set pin high
wait 5 seconds // or 300000; this 'idles' the arduino
else
set pin low
Note:
you have to use pinMode in setup() to make the pin an output.