UNO vers Nano programming

Hi new to arduino
I have a basic sketch i found for turning a servo to "0" and 180 via 2 inputs which works on my uno but not on my nano any ideas. sketch below

#include<Servo.h>
int pos = 90;
int pin2 = 2;
int pin3 = 3;
int LedHi = 5;
int LedLow = 6;
Servo servo1;

void setup() {
pinMode(LedHi, OUTPUT);
pinMode(LedLow, OUTPUT);
pinMode(pin2, INPUT_PULLUP);
pinMode(pin3, INPUT_PULLUP);
Serial.begin(9600);
servo1.attach(5);
}

void loop() {
while (digitalRead(pin2) == LOW && pos < 180) {
digitalWrite(LedLow, LOW);
pos++;
servo1.write(pos);
Serial.print("Degrees rotation= ");
Serial.println(pos);
if (pos == 180) {
Serial.print("Reached top end ");
digitalWrite(LedHi, HIGH);
}
delay(10);
}

while (digitalRead(pin2) == LOW && pos > 0) {
digitalWrite(LedHi, LOW);
pos--;
servo1.write(pos);
Serial.print("Degrees rotation= ");
Serial.println(pos);
if (pos == 0) {
Serial.print("Reached low end ");
digitalWrite(LedLow, HIGH);
}
delay(10);

Uno and Nano are very much the same, I don't think it's your code.

I suspect you have a wiring issue or you're trying to power the servo from the Arduino.

@shrekanddonkey66, your topic has been moved to a section of forum that is more suitable.

Can you please edit your post, select all code and click the </> button above the text box; next save the post again. This will make it easier to read and copy.

I'm try to power the servo from the arduino do you suggest from the 5 volt PSU directly ?

I'm surprised it works on an UNO, you are using the same pin for the servo and LedHi.

david i too noticed that and changed the servo to pin 9 stil not working.
the wife wants a watering system for the green house so all i want to do is open a valve via a servo turning 180degrees when an input goes high and back to 0 when input is low

Servos take more current than an Arduino can provide, especially if they're actually doing some work. You may get away with it for a demo where an unloaded servo just turns to and fro.

Depending on the servo and the power supply's capacity, it might be plausible to power them both from the same PSU.

Note also that many servos don't have 180 degrees of movement, but will happily draw loads of current trying to get there if you ask. Find out by experiment how far yours go.

I am reasonably sure that none of the common miniature servos would be able to control a watering system valve - it's just going to be too stiff.

Neither UNO nor Nano can "power" anything of significance, of course you need a power supply for your servo.

A latching solenoid valve made for irrigation systems is an easy way to control a water line. You don't even need an arduino if all you want is a push-button manual control, although at that point a 1/4 turn manual ball valve is simpler.

David I'm using a water butt so the pressure is too.low for a soleniod valve ,hence the idea of using a 1/4 turn or half turn full bore valve with some time of motor and control.
Original idea was from thingiverse " watering system "

Regards
Dave Stringer

@shrekanddonkey66 You use digitalRead(pin2) two times but never pin3.

A regular solenoid valve does not require ANY pressure, It will open/close just setting in the air with no fluid at all. Perhaps you are thinking of "piloted solenoid valves" which do require a pressure differential of a small amount.
Paul