#include "HX711.h"
#include <Servo.h>
HX711 weight_sensor;
Servo food_hatch;
int LOW_THRESHOLD = 5;
int HIGH_THRESHOLD = 400;
bool SCHEDULED = true;
void setup() {
Serial.begin(9600); // enable debugging
Serial.println("Initializing the scale");
weight_sensor.begin(A1, A0); // initialize the weight sensor
food_hatch.attach(9);
}
void loop() {
int curr_weight = weight_sensor.get_units(1) / 0.42;
Serial.println(curr_weight, 1);
// opens the food hatch when food weight reaches low threshold or it's time for a scheduled feeding
if (curr_weight <= LOW_THRESHOLD || SCHEDULED) {
food_hatch.write(180);
Serial.print("Hatch opened");
}
//closes the food hatch when food weight reaches high threshold
if (curr_weight >= HIGH_THRESHOLD) {
SCHEDULED = false;
food_hatch.write(0);
Serial.print("Hatch closed");
}
}