Board Running, Servo Not. Analog vs Digital Servo?

Hi there,

I am trying to do a DIY robot fish for work, from this website: (the website has the code for the fish too). I have an arduino nano, two IR sensors, magnet switch, 4 AA batteries with holders and three servo motors. The whole circuit has power, sensors are running fine, too, but whenever the board is turned on or reset the 3 servos turn a few quick notches and stop.

The DIY fish had an Uno and digital servos. Problem is, I accidentally ordered analog servos (fitec fs90 micro servo 4.8V,

I tried switching the signal pins in the code and on the board to analog pins, no luck. I tried to attach the signal wires to digital pins with PWM (pins 5, 6, and 9) and use analogWrite() in place of the Write() command in the code and I get “‘class Servo’ has no member named ‘analogWrite’”.

Can someone please tell me what I’m doing wrong? I would greatly appreciate it.
Thank you so much!

This is the code with the changes I made, the original is on the link for the DIY fish at the top

// di Segatello Mirco
#include <Servo.h>
Servo Servo1, Servo2, Servo3; // create servo object to control a servo
int i, time, obstacle;
int pos1, pos2, pos3; 
int pos1R, pos2R, pos3R; 
int phase=45;
int velocity=2000; 
int maxDeflexion=20; 
int maxDefobs=20; 
int actualTime;
float shift;
const int center1=98; 
const int center2=90;
const int center3=105;
const int sens_SX=7; 
const int sens_DX=8;
const int lostTime=3000;
void setup()
pinMode(sens_SX, INPUT);
pinMode(sens_DX, INPUT);
pinMode(13, OUTPUT);
void loop()
for (i=0; i<360; i++) {
pos1 = i+2*phase;
pos2 = i+phase;
pos3 = i;
if (pos1>359) pos1-=360;
if (pos2>359) pos2-=360;
if (pos3>359) pos3-=360;
if (pos1>179) pos1=360-pos1; 
if (pos2>179) pos2=360-pos2;
if (pos3>179) pos3=360-pos3; 
if (digitalRead(sens_DX)==0) { 
if (obstacle<maxDefobs) shift=shift+0.05; 
if (digitalRead(sens_SX)==0) { 
if (obstacle > (-maxDefobs)) shift=shift-0.05;
if (digitalRead(sens_SX)==1 && digitalRead(sens_SX)==1 && obstacle!=0)
if (millis()>actualTime+lostTime) {
if (shift>0) shift=shift-0.05;
if (shift<0) shift=shift+0.05;


as the error said, analogWrite is not the command of the lib. Also, the servos don't exactly use PWM so the pins don't matter, and the analogWrite you were trying wouldn't work anyway.

Digital servos do high/low pulses, analog servos afaik use varying voltages.
Arduino doesn't put out varying voltages. Even during analogWrite, it's still high/low, just a matter of ratio.
No amount of coding can make the Arduino vary voltage. To get that, you need some trickery

Or just buy the right servos.

AFAIK digital servos work with the Servo library just like analog servos. The "digital" stuff is inside the servo.

You can use any of the Arduino I/O pins to control a servo with the Servo library. Use the Servo sweep example that comes with the Arduino IDE for a test program.

analogWrite() is used with a suitable h-bridge driver for controlling the speed of DC motors - it is not used with servos.


There is no difference in how you use an analog v. a digital servo, just use the Servo library.

Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
How are you powering your servos?
If you are using the same 4AA's that power everything else you will having power supply problems due to the power requirements of the servo's.

Thanks.. Tom.... :slight_smile: