Good Evening friends. I am building an rfid feeder alternative after seeing someone online build something similar using a scale sensor to determine which cat could eat from the bowl. We have one cat that is 10 lbs and one that is 14 lbs. I'm sure you can guess who is overeating and needs to be restricted to diet food. I purchased an arduino uno and fsr sensor to control the futaba servo I already have. I have found code online and edited it to operate on the override switch for filling the dish but neither input functions when I combine the switch code with the fsr code. I was reading about using a switch case string and wonder if that would work better. I would also like to slow down the loop because it moves so fast i can't read the data from the fsr sensor. I'm trying to keep it as simple as possible, using the servo to open the lid when the smaller cat activates the fsr and close it when the other cat exceeds the settings for the fsr. I also want to include a low power library that will shut down after an elapsed time and reactivate when the microswitch powers the wake up circuit. Any assistance would be greatly appreciated. I did build one of these last year and used a cd rom drawer, relays, resistors and capacitors to make a unit that operated on a magnetic reed but the cat kept sticking to the fridge with that big magnet on her collar!
#include <Servo.h>
#include <ezButton.h>
#define fsrPin A0
constexpr uint8_t openPin = 7; // open door
constexpr uint8_t closePin = 7; // force close
constexpr uint8_t servoPin = 9;
const int BUTTON_PIN = 7;
ezButton button(BUTTON_PIN);
int fsrReading;
// make your own servo class
class SlowServo {
protected:
uint16_t target = 110; // target angle
uint16_t current = 110; // current angle
uint8_t interval = 30; // delay time
uint32_t previousMillis = 0;
public:
Servo servo;
void begin(byte pin)
{
servo.attach(pin);
}
void setSpeed(uint8_t newSpeed)
{
interval = newSpeed;
}
void set(uint16_t newTarget)
{
target = newTarget;
}
void update()
{
if (millis() - previousMillis > interval)
{
previousMillis = millis();
if (target < current)
{
current--;
servo.write(current);
}
else if (target > current)
{
current++;
servo.write(current);
}
}
}
};
SlowServo myservo; // create a servo object
void setup() {
Serial.begin(9600);
myservo.begin(servoPin); // start the servo object
pinMode(openPin, INPUT_PULLUP);
pinMode(closePin, INPUT_PULLUP);
button.setDebounceTime(100);
Serial.println("digital cat feeder");}
void doorOpen()
{
Serial.println(F("open"));
myservo.set(90);
}
void doorClose()
{
Serial.println(F("close"));
myservo.set(0);
}
void loop() {
button.loop();
fsrReading = analogRead(fsrPin);
Serial.println ("Analog Reading = ");
Serial.println (fsrReading);
if (digitalRead(openPin) == LOW){
doorOpen();
}
if (fsrReading < 700 && fsrReading > 900) {
Serial.println("snowy - open cover");
{
doorOpen ();
}
if (digitalRead(closePin) == LOW)
{
doorOpen();
}
} else if (fsrReading < 1100) {
Serial.println("zelda - close cover");
}
{
doorClose();
}
myservo.update(); // call the update method in loop
}


