SteveSmith00 / hanging-deer-feeder

0 stars 0 forks source link

hanging deer feeder #1

Open SteveSmith00 opened 1 month ago

SteveSmith00 commented 1 month ago

Arduino Code for an Automated hanging deer feeder

#include <Servo.h>  // Include the Servo library to control the feeder mechanism

Servo feederServo;  // Create a servo object to control the feeder

const int servoPin = 9;   // Servo motor connected to digital pin 9
const int feedInterval = 6 * 60 * 60 * 1000;  // Interval to dispense feed (6 hours in milliseconds)
unsigned long lastFeedTime = 0;  // Tracks the last time feed was dispensed

void setup() {
  feederServo.attach(servoPin);  // Attach the servo on pin 9 to the servo object
  feederServo.write(0);          // Set initial position of the servo (closed)
  lastFeedTime = millis();       // Start the timer
}

void loop() {
  unsigned long currentTime = millis();  // Get the current time

  // Check if it's time to dispense feed
  if (currentTime - lastFeedTime >= feedInterval) {
    dispenseFeed();               // Call the function to release feed
    lastFeedTime = currentTime;    // Reset the timer
  }
}

void dispenseFeed() {
  // Rotate servo to open position to release feed
  feederServo.write(90);   // Rotate servo to 90 degrees (open)
  delay(5000);             // Keep it open for 5 seconds
  feederServo.write(0);    // Rotate back to 0 degrees (closed)
}

Explanation:

  1. Servo Motor: This code controls a servo motor attached to the feeder’s dispensing mechanism. The motor rotates to release the feed at regular intervals.
  2. Feeding Interval: The feedInterval is set to 6 hours (in milliseconds). You can adjust this value to dispense feed more or less frequently depending on your needs.
  3. Timing Mechanism: The millis() function is used to track the elapsed time since the last feed was dispensed, ensuring feed is released at the correct interval.
  4. Servo Control: The servo rotates 90 degrees to open the feeder, waits for 5 seconds (allowing feed to drop), then returns to 0 degrees to close.

Hardware Required:

This basic setup automates the dispensing process, so you don’t have to manually feed the deer every day. You can modify the timing, servo positions, and feeding mechanism to suit your specific requirements.

Scoper07 commented 3 weeks ago

Amazing work! Your contributions are invaluable to this project. Thanks for all your hard work! best hunting/hiking boots