0
$\begingroup$

Summary

I am making an automatic door for my chickens including a servo motor. In the process I actually shorted my 5V from my Arduino. The servo is powered by external batteries and only gets its signal by digital pin 9. After the shorting, the servo only wants to go full power 1 way, I can't get it to move the other direction any more. Does somebody know what happened and/or what to do?

Detail

I want to use the servo as motor as a pulley, which will lift a small plastic door with a cord. I hope this will be light enough. I added 2 images of the setup I have made with the wiring, using 2 led to indicate the up (yellow) and down (red) state. The 2 blue leds are to indicate if a button is pressed and is just wired to the 5 V. The buttons are attached to D4 and D5. The servo is connected to D10 is this case and to the 4 batteries. The solar panel is wired to 5V, running through 3 1000 ohm resistors to A0.

Everything ran fine until I accidentally shortened the 5V to GND. I hope you can say what is wrong!

Thanks in advance.

My code is:

#include <Servo.h>

Servo name_servo;

int servo_position = 0;
int button_open = 4;
int button_closed = 5;
int LEDRED = 12;
int LEDWHITE = 13;
int SUN = A0;

void setup () {
  name_servo.attach (9);
  pinMode(button_open, INPUT);
  pinMode(button_closed, INPUT);
  pinMode(LEDRED, OUTPUT);
  pinMode(LEDWHITE, OUTPUT);
}

void loop() 
{
  {
  int SUN = analogRead(A0);
  Serial.println(SUN);
  delay(1);   
  }
  if(digitalRead(button_open) == HIGH && servo_position >= 0)
  {
  digitalWrite(LEDRED,HIGH);
  digitalWrite(LEDWHITE, LOW);  
    for (servo_position = 180; servo_position >= 0; servo_position -=1) 
    {
      name_servo.write(servo_position);
      delay(10);
    }
    {
      delay(2000);
    }
  }
  if(digitalRead(button_closed) == HIGH && servo_position <= -1 || analogRead(SUN) >= 900 && servo_position <= -1)
  {
  digitalWrite(LEDRED,LOW);
  digitalWrite(LEDWHITE, HIGH);
    for (servo_position = 0; servo_position <=180; servo_position +=1) 
    {
      name_servo.write(servo_position);
      delay(10);
    }
    {
      delay(2000);
    }
  }  
}

This is how I wired everything.

$\endgroup$
2
  • 2
    $\begingroup$ Hi @Rob and welcome to Robotics. Without a lot more information, we will be unable to help you diagnose what happened or what to do. That being said, shorting electrical circuits is never good and can make things break in really strange ways. I would suggest replacing affected components. $\endgroup$
    – Ben
    Jun 13, 2019 at 23:09
  • $\begingroup$ In order to determine whether the short has damaged the Arduino, try a different Arduino or different pin. $\endgroup$ Jun 17, 2019 at 14:39

1 Answer 1

0
$\begingroup$

Upon a quick review, I noticed a few things that might be causing the problem:

In your setup() function, you are attaching the servo to pin 9 using name_servo.attach(9). However, in your code comments, you mentioned that the servo is connected to pin 10. Make sure the servo is connected to the correct pin.

In your loop() function, you have an extra set of curly braces {} enclosing the code block for reading the analog value of the SUN pin. Remove those extra braces to fix the indentation and ensure proper execution.

Another issue is related to the condition in your second if statement. You are checking if the button_closed is pressed and if the servo_position is less than or equal to -1. However, it seems like you want the servo to move when the button is pressed or when the analog value of SUN is greater than or equal to 900. To fix this, modify the condition to digitalRead(button_closed) == HIGH || (analogRead(SUN) >= 900 && servo_position <= -1).

Try making these changes and see if it resolves the problem with your servo motor.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.