Buzzer at the start of loop

hello, im making an automatic cat feeder to dispense dry food every 6 hrs. Initially when writing the program it made the sound the started the servo for 3 sec. when i tried to refine it by making it go for say 10 seconds, when it was plugged into the usb so i could use the serial output to make sure it worked. then after taking out the usb an ran from the power source the beeping just looped over and over, and i cant figure out why. is there a simple reason?

// Include the library
#include <Servo.h>
#include <Noiasca_timer.h>

// Create the servo object
Servo myservo;

const int buzzer = 7; //buzzer to arduino pin 9
LittleTimer littleTimer {3600000};

unsigned long count = 0;   

// Setup section to run once
void setup() {

 Serial.begin(9600);
Serial.println("\nStart");
littleTimer.start();    
  
  myservo.attach(8); // attach the servo to our servo object
 
   pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
//buzz();
servomove();


}

// Loop to keep the motor turning!
void loop() { 
 if (littleTimer.hasTriggered())  // if the defined time is over, the timer will execude the followin lines
  { 
    Serial.println("timer has triggered");
     (count++); 
  }

   
   Serial.println(count); 
     
if (count >= 7) { 
          count = 0;
    }
if (count == 6) {
  Serial.println( "here comes the food");
    buzz();
     servomove();  
           
    }

 

}


void servomove() {
  myservo.write(40); // rotate the motor counterclockwise
  delay(5000); // keep rotating for 5 seconds (5000 milliseconds) time it takes to fill a bowl

  myservo.write(90); // stop the motor
}

void buzz() {
  tone(buzzer, 4800); // Send 1KHz sound signal...
  delay(800);        // ...for 1 sec
  noTone(buzzer);     // Stop sound...
  delay(100);        // ...for 1sec
 tone(buzzer, 4500);
 delay(800);        // ...for 1 sec
  noTone(buzzer); 
  delay(100);  
   tone(buzzer, 4000); // Send 1KHz sound signal...
  delay(800);        // ...for 1 sec
  noTone(buzzer); 

}
  

because the condition

if (count == 6) {

will still true for hour.
As a solution you can increment count just after beeping

Also your buzz() function has about 2.5 seconds of delays, which may be fine for this application. Realize, however, that during the buzz() function your code can do nothing else.

How does that condition make it beep over and over when powered up. The beeping im talking about is when first powered on. Its almost like the arduino is resetting itself over and over.

Im aware of the delay, but like u said its fine in this application. Because the timer wont start again until the buzz function finishes and hoping the cat will hear the sounds and know there is food.

Hi,
Put the startup BEEP in the setup function, it will only beep when setup is run.

Tom... :smiley: :+1: :coffee: :australia:

The beep is in the setup, its just commented out right now because it seems to reset the arduino and stops the loop from working

Hi,
Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.
What is your power supply?

Can you please post some images of your project so we can see your component layout?

Can you please post link to specs/data of the beeper?

If you disconnect the beeper, does it keep resetting?

What model Arduino are you using?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.