Classic Nano - sketch not working

I have a Nano mounted on an expansion board to control a single servo - for experiments. The sketch I am using worked fine the last time I used it.

I have an expansion board mounted with a servo connected to pin 3 and the corresponding input pin is either Hi or Lo according to a switch.

The sketch uploads and I see the TX/RX leds flash. When the pin is Lo I see the power light on the Nano, when I operate the switch, the 'L' led comes on and stays on until the pin is LO.

I checked the voltage on the SIG pin and on power up it indicates a signal which then drops to zero. This moves the servo to the centre position as desired. Operating the Hi/Lo switch shows no change on the SIG pin.

This is confusing as all this worked fine a few months back and I have tried with a couple of brand new Nanos.

What could be happening and how do I find out?



Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.

High current loads should not be powered from the Arduino 5v pin.

Not sure what you are saying here. What is the corresponding pin to pin 3?

A schematic will clear things up but it sounds like it is wired wrong.

Definitely isn't wired wrong - it worked for ages so I'm trying to figure out why it has stopped working. See later reply for details

The attached photo shows the actual board and the connections I have on it. This was all working until yesterday so I'm wondering what might have changed.

![Arduino_expansion board|500x500](upload://tmyeyrXSGmGbeuj5Cn2E45j4itF.jpeg)

#include <Servo.h>

const byte InputPins[] = {11, 12, 13, A0, A1, A2, A3, A4};
const byte NrServos = sizeof(InputPins);
const byte ServoPins[NrServos] = {3, 4, 5, 6, 7, 8, 9, 10};
const byte EndPositions[2] = {105, 75};
const byte BounceAngles[] = {7, 0, 3, 0, 1};
const byte MovementDelay = 30;
const byte BounceDelay = 180; 

Servo servo;
bool previousButtonStates[NrServos];

void setup() {
  for (byte i = 0; i < NrServos; i++) {
    pinMode(InputPins[i], INPUT);       // set pins to INPUT
    servo.write(EndPositions[0]);       // move servo to DOWN position
    delay(2 * BounceDelay);

void loop() {
  for (byte i = 0; i < NrServos; i++) {
    const bool State = digitalRead(InputPins[i]);
    if (State != previousButtonStates[i]) {
      previousButtonStates[i] = State;
      for(byte pos = EndPositions[!State]; 
          pos != EndPositions[State]; 
          (State ? pos-- : pos++))
        servo.write(pos);               // move servo to position in variable 'pos'
        delay(MovementDelay);           // wait for the servo to reach the position
                                        //make the servo 'bounce'
      for(byte n = 0; n < sizeof(BounceAngles); n++){
        servo.write(EndPositions[State] + (State ? -1: +1) * BounceAngles[n]);

It can become wired wrong if the wires are not making contact. Still love to see a schematic.

So would I but I don't have the knowledge to create one

So how can you ever hope that any one could help you?
I order to help we need to know what you have.

My metal work teacher said to us in the 60s
“If you can’t draw it, you can’t make it”

If you show me an example of what you mean by schematic, I'll see what I can do.

1 Like

Here is the schematic I created - hopefully it is what you need, first one I ever did.


You are unlikely to see any change in voltage on the servo signal wire with different servo positions, the servo control signal is a single HIGH pulse of around 1mS to 2mS at 20mS intervals.

Are you sure the servo is getting power? Most servo expansion boards are designed for external power (that is what the barrel connector is for) because it is impossible for an arduino board to supply sufficient power to operate anything more than the tiniest servo.

Hi David,
First off, this test rig has been working as is for about three years - for some reason it has stopped doing so. The servo moved correctly even powered by the USB input. I have several Nano's at my disposable and none of them are working with the sketch I loaded even though the code has not been changed.

On a totally separate set up, using the ATMega328 chip, I can set my multimeter to 20 volts DC and see a value varying from .35 to .45 as the servo swings through about 40 degrees. Maybe this Nano is behaving differently to the ATMega328.

Anyway, I'm trying to diagnose this set up and the only clue I am getting is that the 'L' led is going solid when the pin goes Hi. What could cause that?

Follow up. I just loaded the 'sweep' sketch and that send the 'L' led on solid as soon as it finishes uploading so I suspect it isn't my sketch but something in the board or the chip.
Also, the servo did move from side to side once on power up and settled in the 'DOWN' position as per my sketch.

That is caused by the way you wired that switch. You put 5V on pin 13 and that powers the L LED directly so it loses any form of control from the code. Use another pin for your switch and don’t forget to update your code.

The code you posted seems to have nothing to do with the schematic you produced.

According to this code you should connect your input switch to pin 11 to control the servo on pin 3.

Mike, thank you for this and you are correct because moving the 5v switch line to pin 11 got everything working as designed.
This is a bit of a mystery as the code you see drives 8 semaphore signals on a model railway layout and it works just great. The test rig is simply a replica of one signal to allow me to test the amount of movement and 'bounce' and, if I understand correctly, the code expects that servo pin 5 would be controlled by input pin 13 - which it is on the layout. So why this test rig doesn't work using pin 13 is a puzzle - are you saying we should not be using input pin 13?

Did you try just moving the servo to pin 5 and leaving the switch to pin 13?

The schematic you posted showed the switch on pin 13 and the servo on pin 3 so I knew it was wrong. See how the code is only half the story and having the schematic is the other half. Thanks for drawing that, you can’t fully understand one without the other.

What I am saying is that you can use pin 13 as an input, but on some Arduinos that will mess with the onboard LED as well. You probably didn’t notice that on your final railway setup, but it still happened.

I will try that using pin 13 and let you know, thanks again

Yes, that was it - pin 13 does work servo 5 and the 'L' light comes on when Hi.

Problem solved, thank you

1 Like