Arduino "falling asleep" after long period of inactivity

Hello,
I am unfamiliar with programming, but I paid someone to program a PIR circuit to trigger sounds and lights when a golf ball is "made" into the 19th hole of our miniature golf course. It worked great, but we just discovered that it doesn't work the first time after sitting for over an hour without being tripped (after sitting, the first ball "made" will wake up the board and the subsequent balls will trip the sensor, beginning the sequence as long at it's not an hour between those shots). We open in 2 days and I can't get in touch with the my developer, they're MIA. It does have a "heartbeat led" so I can monitor if it's on or not.
HELP!!

Do you have a copy of the code?

I'll try to find it.
I can't find anywhere that says that the board will "go dormant" and need to be "woken up" after a long period inbetween. Is this even a thing?

It's a thing if the programmer writes the code that way.

There are a variety of power saving sleep modes, but as pert says, the programmer would need to explicitly enable them.

Is this thing battery powered?

it's powered by a 9v outlet. also, the amp for the audio is 9v outlet powered separately.
Here's the code:

int led = 12; // the pin that the LED is atteched to
int statusled = 13; // on board LED for status flash
int sensor = 2; // the pin that the sensor is atteched to
int buzzer = 9; // the pin that the buzzer is attached to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)

void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(statusled,OUTPUT);
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}

void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(led, HIGH); // turn LED ON
tone(buzzer,2500,2500);
delay(100); // delay 100 milliseconds

if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(led, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
digitalWrite(statusled,HIGH);
delay(500);
digitalWrite(statusled,LOW);
delay(500);

if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How does a golf ball at ambient temperature trigger a PIR?

If you heat the ball up in your hand for a few minutes, then put the ball in the detection area, is it detected when you assume the Arduino has gone to sleep?

Is the heartbeat LED flashing even when the fault occurs?

Thanks.. Tom... :slight_smile:

int led = 12;                 // the pin that the LED is atteched to
int statusled = 13;           // on board LED for status flash
int sensor = 2;              // the pin that the sensor is atteched to
int buzzer = 9;             // the pin that the buzzer is attached to
int state = LOW;             // by default, no motion detected
int val = 0;                 // variable to store the sensor status (value)

void setup() {
  pinMode(led, OUTPUT);      // initalize LED as an output
  pinMode(statusled,OUTPUT);
  pinMode(sensor, INPUT);    // initialize sensor as an input
  Serial.begin(9600);        // initialize serial
}

void loop(){
  val = digitalRead(sensor);   // read sensor value
  if (val == HIGH) {           // check if the sensor is HIGH
    digitalWrite(led, HIGH);   // turn LED ON
    tone(buzzer,2500,2500);
    delay(100);                // delay 100 milliseconds 
    
    if (state == LOW) {
      Serial.println("Motion detected!"); 
      state = HIGH;       // update variable state to HIGH
    }
  } 
  else {
      digitalWrite(led, LOW); // turn LED OFF
      delay(200);             // delay 200 milliseconds 
      digitalWrite(statusled,HIGH);
      delay(500);
      digitalWrite(statusled,LOW);
      delay(500);
      
      if (state == HIGH){
        Serial.println("Motion stopped!");
        state = LOW;       // update variable state to LOW
    }
  }
}

@tomgeorge
Like I said, I'm very novice and almost incompetent. I'm not sure if I could draw a circuit for this project.

As far as I know, the movement of the ball is triggering the sensor and we're not having issues with it triggering. We're having issues with it not reading after a long time of the circuit sitting without being tripped. after about an hour, if it's tripped it won't read it, it just seems to wake up from sleeping, then if a ball trips it within the next hour, it works no problem. So, I don't think it matters if the ball is warmer or ambient.

(the LED still blinks on the circuit after an hour of not being tripped)

There's nothing in that code that makes it sleep after some time.

What happens to the heartbeat signal?

The PIR sensor to detect a golf ball is odd indeed, to say the least. It doesn't sound like the proper sensor for the job. Are you sure it's a PIR to begin with? Type number?

HC-SR501 Pir Motion IR Sensor
Heartbeat signal stays on

Did you say that you have two power supplies, one for the arduino and one for "audio"?

Mark

yes, correct

Then there is nothing wrong with the arduino IT IS NOT GOING TO SLEEP.

Your second wall wart (for the audio) is!

Mark

That sensor is indeed utterly unsuitable for the job. It looks for motion of objects warmer than ambient - people, cars (hot engine), the neighbout's cat. The golf ball unless caresses for some time before play will be at ambient temperature, and therefore nigh invisible to this sensor.

To detect a golf ball falling into a hole you need e.g. a break beam sensor (it falling/rolling through), or a knock sensor (it falling on), or a light sensor (it blocking the light as it falls on).

The 1.2 second maximum reaction time of that sketch (due to the heartbeat using delay() calls) is not helping, for sure.