Arduino Pro Mini keeps resetting with servo

I’ve been desperately trying to get a small 5v servo to run off my Pro Mini

I want the arduino to receive a servo position over I2c or serial, then turn the servo to that position. The sketch works, the motor turns, but after a few turns, the arduino freezes. I’m powering the board (3V pro mini) and the servo with a 1.5A 5V plug. I’ve had the same problems with an arduino nano.

Please someone, tell me how to make this work! Thanks!

#include <Wire.h>
#include <Servo.h> 

Servo cameraservo;

int cameraPin = 12;

int camerapos = 60;

//I2C
#define SLAVE_ADDRESS 0x10

  int inByte = 0;         // incoming serial byte

int commandNumber = 0;  //Incoming command
 
 
 void setup() 
{ 
// initialize i2c as slave
Wire.begin(SLAVE_ADDRESS);

Serial.begin(9600);

pinMode(cameraPin, OUTPUT);     
  cameraservo.attach(cameraPin); 

cameraservo.write(camerapos);  //put servo into starting position            


}



void loop(){
  
// Get user commands from I2c or serial     
   Wire.onReceive(receiveData);
   
    char ch = Serial.read();

if (isDigit(ch)){
  commandNumber = (ch - '0');
}

if ((commandNumber > 1) && (commandNumber < 90))
    {Serial.print(commandNumber);
    Serial.print("  Camera Position:  ");
    Serial.println(camerapos);
    

    servoControl();   }

commandNumber = 0;

    
}



//Servo Code

void servoControl(){
  
  while ( camerapos > commandNumber){
 
        cameraservo.write(camerapos);            
    delay(20);   
    camerapos = camerapos - 1;
    Serial.println(camerapos);

  }
  
  while ( camerapos < commandNumber){
 
        cameraservo.write(camerapos);            
    delay(20);   
    camerapos = camerapos + 1;
 
      Serial.println(camerapos);

  }   
  }  

//I2c code
void receiveData(int byteCount){

    if(Wire.available()) {
        commandNumber = Wire.read();       
     }
}

Issues that come to mind are power and voltage - I’m not sure whether you can command a 5V servo with a 3.3V arduino. Alternatively, the servo’s drawing too much power and causing the Arduino problems. Can you try using the sweep example sketch to eliminate these as possible causes?

I agree with wildbill. On top of that, put in several bypass capacitors on both the servo, and the arduino power supply leads.

3V may or may not be a suitable control (control/sig in) level, but
What's your situation without the servo?

Hello!

Let me use this topic for my question. I have pro mini 328 5V. With it I control 2 servo motors (SG 90). When I connect it over FTDI everything runs OK. But when I remove FTDI and power arduino over external power (positive is connected on RAW, negative on GND - Vin is about 10V) the servos just sort of twitch.
The servos positive are connected on VCC, negative on GND, one signal on digital 8 the other on digital 9. I don't now where to look for problem any more.
If you could give me some hint it would be great.

Best regards,
spetovar

Is VCC the same as Vin ?
Put a volt meter on the positive, and see what it shows while the servos are trying to move.

Hi,

Thank you for your replay. VCC is not the same as Vin because VCC is regulated 5V. Vin is voltage from batteries connected on RAW. When the servos move the VCC is about 4.5 V. But the code is written so that only one servo moves at the time. So that should be enough. I can connect servos on external power but I would like to understand why is this happening.

Best regards,
spetovar

Maybe the ProMini's 5V just doesn't have what it takes for this.
Q: got servo surge?
A: No vá, señor!

IOWThe USB_5V can deliver the juice but Pro-Mini's board-derived 5V cannot?
Can you rig up a separate 5V circuit to test that out?

Hi!

So this is what I tried so far:

  1. Connected everything the same on Arduino Uno and Arduino Nano. Both times everything works with external power.
  2. Connected pro mini to the bench power supply with steady 7V. The result is the same. Servo doesn't move just twitches.
  3. I disconnected everything, connected only one servo and run Sweep program from the example. It still doesn't work.
    Now I'm thinking there is a problem with the Arduino Pro Mini... Don't know what else could it be.
    Any more ideas ?

Best regards,
spetovar

The voltage regulator on the mini has a maximum output current of 100 mA. The Atmega usually drains 30-50 mA so you have 50-70 mA to power your shield.

quote from:
http://arduino.cc/en/Main/ArduinoBoardProMini

Hi!

Thank you Jack for that. I read that and more and more I realize, that I would have to power servos separately.
But it does still bothers me though why it runs OK on USB but not the external power...
Maybe can drain more mA with USB than on the RAW pin. I didn't find that info yet.

Best regards,
spetovar

As, I guess, you now understand..

http://forum.arduino.cc/index.php?topic=173018.msg1410410#msg1410410

Use a multimeter to see what the actual voltage is on your board. If you are running 5v thru a voltage regulator, the output voltage may be a volt or more less than 5v.

Hi!

Yes Pancake I do. Sorry for double posting.
I used a multimeter and I measured directly on the servo connector. The voltage there is 4.9 V when it moves and 5 V when idle. So supplied voltage should not be a problem.
But I read that the ground pins could be a problem. I have a external power source ground on pin 23 and servo ground on pin 4. May this be a problem ?
Tomorrow I'll test that and tell you how it went.

Best regards,
spetovar

Servo power and the arduino need to have the grounds connected together like below.

zoomkat:
Servo power and the arduino need to have the grounds connected together like below.

I think they "are" if "pin 4" and "pin 23" are electrically the same.

spetovar:
I have a external power source ground on pin 23 and servo ground on pin 4. May this be a problem ?

Maybe... if it's a thin trace between the two.
Connect them ("pin 4" and "pin 23") with a piece of #20 solid and use that as a Gnd bus to make that a "non-issue".

BTW, I think that "pin 4" corresponds to JP7 pin 9 and "pin 23" is JP6 pin 2 (re. PDF above)