So I just started using Arduino and this is my first project. I want wo make a pet feeder that detect mass by using force sensor and using timer to tell which time to feed the pet. The feature that I use in my project is
- User can create up to 3 feed time using alarm
- If the force from force sensor is lesser than 1, then it will open the servo to feed the pet and a piezo will beep for 3 second.
- If the force from force sensor is >= 1, then the device won't open the servo and just beep the piezo.
I use isAlarm, isAlarm1, isAlarm2 variable to store if the user set the alarm or not.
My problem is, even when the condition is met (hourAlarm = hour, minuteAlarm = minute, and so on, and force sensor value < 1 ), the servo is still won't turn.
This is my device
This is how I code the servo related system
void setup() {
lcd.begin(16, 2);
pinMode(pushbtn1, INPUT);
pinMode(pushbtn2, INPUT);
pinMode(pushbtn3, INPUT);
pinMode(pushbtn4, INPUT);
pinMode(A0, INPUT);
servo_1.attach(1, 500, 2500);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop(){
forcesensor = analogRead(A0);
weight = map(forcesensor, 0, 544, 0, 10);
if(mode==0)clock();
else if(mode==1)setTime();
else if(mode==2)setAlarm();
else if(mode==3)setAlarm1();
else if(mode==4)setAlarm2();
}
And this is how I trigger the piezo and servo using force and alarm condition logic
void checkAlarm1(){
if(hour==hourAlarm1 & minute==minuteAlarm1 & second==secondAlarm1 & flag==flagAlarm1 & weight < 1){
tone(buzzer, 1000);
delay(3000);
noTone(buzzer);
servo_1.write(90);
delay(2000);
servo_1.write(0);
isAlarm=false;
}
else if (hour==hourAlarm1 & minute==minuteAlarm1 & second==secondAlarm1 & flag==flagAlarm1){
tone(buzzer, 1000);
delay(3000);
noTone(buzzer);
isAlarm=false;
}
}
If you please, you can check this project on tinkercad
Tinkercad project
Thankyou
