My servo won't turn

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

  1. User can create up to 3 feed time using alarm
  2. 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.
  3. 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);

void loop(){
  forcesensor = analogRead(A0);
  weight = map(forcesensor, 0, 544, 0, 10);
  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);
  else if (hour==hourAlarm1 & minute==minuteAlarm1 & second==secondAlarm1 & flag==flagAlarm1){
    tone(buzzer, 1000);

If you please, you can check this project on tinkercad
Tinkercad project


  if (hour == hourAlarm1 & minute == minuteAlarm1 & second == secondAlarm1 & flag == flagAlarm1 & weight < 1)

A single & does a bitwise AND comparison, which I doubt is what you want. Use && to do a logical AND, which makes more sense

How do expect a coin cell to power a servo???

I’ve tried this but still, it doesn’t work

I’ve tried to use battery, still not work

You can safely power the servo directly from 5V of the arduino and add a 100 microF capacitor between the red/black wires of the servo.
Can you upload the complete code? It doesn’t compile and I don’t know what you’ve declared outside setup(), loop() and functions.

Does the Servo Sweep example work with your circuit and power supply ?

Yes, it works


This is the link project

You can check the simulation link in tinkercad if you please. Thank you in advance

Do you mean that it works in TInkerCad or that it works with an actual Arduino and servo ?

Do not put the servo on pin 1, that is used by Serial. The analog pins A0 through A5 can be used for the servo, but avoid A4 and A5 if you intend to use the I2C bus. If you do not intend to use Serial, remove the call to Serial.begin and pin 1 will be ok for use.

You never call checkAlarm1().


Thank you so much, it work

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