Servo behaving in a strange manner

Dear friends,

I’m building a box-like device that will open when the person visits all GPS predefined locations.

The device has :
-Arduino Nano
-LCD 16x4
-GPS NEO6 module
-buzzer
-1 LED diode (R,G,B diode, 3 in 1)

  • 1 Servo motor SG90

I’m using 6 libraries:

#include<Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Servo.h>
#include <EEPROM.h>

I want to control the servo once some flags are turned ON (to unlock the box), so I wrote a simple function - the servo should just rotate cc150 degrees .

#include <Servo.h>
Servo motor;

void turn(){
  motor.write(0);
  delay(2000);
  motor.write(150);
  delay(2000);  
}

The problem is - as soon as I attach the motor
// motor.attach( 8 )

it starts spinning uncontrollably, 40 degrees left, then 30 right etc.

The only way to stop the Servo is to “motor.detach()”

Both the Nano and the Servo are working properly, when I try a basic sketch (swipe or knob), it works flawlessly.

I’m powering them using a mb102 breadboard power supply.

To me it looks like the Nano is sending some strange and faulty PWM signals to the Servo as soon as the servo is attached.

Any idea on what is causing the problem ?

My guess is that the power supply is nowhere near powerful enough for all those components.

Either that or it's something in the code that you haven't shown us.

Steve

It is best to have a separate power supply for the servo, 5 to 6V at more than 1 Ampere (4xAA battery pack works well). Be sure to connect all the grounds.

Do NOT attempt to use the 5V Arduino output to power the servo. Doing so will cause malfunctions or even destroy the Arduino.

Thanks for the replies <3

I also think that powering

  1. 16 x 4 LCD
  2. GPS NEO6
    3)A buzzer
  3. A Servo
  4. A 3 in 1 LEd

through a Arduino Nano is a painful experience for the small guy. That’s why in the code when the Servo works (for 500 only millisec) the LCD backlight turns off (to flatten the current peak).

I will try with a different power supply, and see the results.

btw

It’s obviousthe poor Nano is struggling to provide energy to the LCD - when the small led on the GPS NEO blinks, the LCD backlight brightens decreases for the short duration of the blink.

Manufacturers publish the limitations of the various input and output pins, but in general, the 5V output is intended as a convenience, and only for a couple of low power sensors.

LCD backlights and GPS units are power hungry, while servos, motors, etc. are absolutely voracious.

It is best to separately power the LCD backlight and servo.

Don't expect a battery powered project to run for more than a day or two if those and/or the GPS are continuously activated.