Weird script with a timer but no timer function
hey all,
i'm setting motion sensor , found following sketch start with. works intended short "on' cycle", want extend length of time pin high don't see timer here.
when run sketch on board there 15 seconds of on time before pin goes low. don't see variable timeon in sketch.
so have 2 questions
how sketch have 15 second on time?
how can write sketch include timeon variable?
thanks!
rich
i'm setting motion sensor , found following sketch start with. works intended short "on' cycle", want extend length of time pin high don't see timer here.
when run sketch on board there 15 seconds of on time before pin goes low. don't see variable timeon in sketch.
so have 2 questions
how sketch have 15 second on time?
how can write sketch include timeon variable?
thanks!
rich
code: [select]
int calibrationtime = 5;
boolean sensoractive = false;
boolean previoussensorstate = false;
int pirpin = 12; //the digital pin connected pir sensor's output
int ledpin = 9;
// setup phase
void setup(){
serial.begin(115200);
pinmode(pirpin, input);
pinmode(ledpin, output);
digitalwrite(pirpin, low);
//give sensor time calibrate
serial.println("sensor calibration in progress");
serial.println("------------------------------");
for(int = 0; < calibrationtime; i++){
serial.print(".");
digitalwrite(ledpin, high);
delay(250);
digitalwrite(ledpin, low);
delay(250);
digitalwrite(ledpin, high);
delay(250);
digitalwrite(ledpin, low);
delay(250);
}
serial.println("");
serial.println("sensor calibration completed");
serial.println("sensor reading active");
sensoractive = false;
previoussensorstate = false;
}
// loop sequence
void loop()
{
// takes pin value , saves sensoractive boolean value
if(digitalread(pirpin) == high)
{
sensoractive = true;
digitalwrite(ledpin, high);
}
if(digitalread(pirpin) == low)
{
sensoractive = false;
digitalwrite(ledpin, low);
}
// performs action if state of sensor changes
// since loop, here works:
// if sensor pin goes high (on) after being low (off), sensoractive value changes previoussensorstate value.
// turns on led. when pin goes low (off) same thing opposite values.
// prints status serial. print time of triggering providing number of seconds have passed since program started.
if(sensoractive != previoussensorstate)
{
if(sensoractive == true)
{
previoussensorstate = sensoractive;
serial.println("---");
serial.print("motion detected at: ");
serial.print(millis()/1000);
serial.println(" seconds");
delay(50);
}
if(sensoractive == false)
{
previoussensorstate = sensoractive;
serial.println("---");
serial.print("motion stopped at: ");
serial.print(millis()/1000);
serial.println(" seconds");
delay(50);
}
}
}
pir sensors come 2 potentiometers, 1 of potentiometer set dwell time of high state (how long stays high after triggering) - second potentiometer trimmer adjust sensitivity
on pir boards have dwell time labeled t letter next , sensitivity s letter next it. 2 types of pir looks like
this adjust manually, "how can write sketch include timeon variable?" challenge unless want have servo turning small potentiometer.
alternatively, set time low possible , handle longer duration in code won't able go below minimum timing available on specific hardware unless ignore pin information.
on pir boards have dwell time labeled t letter next , sensitivity s letter next it. 2 types of pir looks like
this adjust manually, "how can write sketch include timeon variable?" challenge unless want have servo turning small potentiometer.
alternatively, set time low possible , handle longer duration in code won't able go below minimum timing available on specific hardware unless ignore pin information.
Arduino Forum > Using Arduino > Programming Questions > Weird script with a timer but no timer function
arduino
Comments
Post a Comment