Make a sketch permanent

After 4 hard weeks of trial and error I have managed to make a setup where a small model railway turntable (home made by 3d printing) can be stopped for an amount of time when a magnet is near a Hall sensor.
However, this means attaching a laptop to load the sketch, which, of course, dies when the laptop and 5V power is removed . Is there any way I can permanently save the software so I can start the turntable by a toggle switch when it will be needed rather than having the laptop attached every time.
Here's the code, don't laugh, it works exactly as I want it to.

#define STEPPER_PIN_1 8
#define STEPPER_PIN_2 9
#define STEPPER_PIN_3 10
#define STEPPER_PIN_4 11

int step_number = 0;
int LED = 13 ; // LED
int digitalPin = 2; // Hall magnetic sensor input 1 (high) or 0 (low)
int analogPin = A0; // analog Pin also available, but not necessary
int digitalInputValue ; // digital readings
int analogInputValue; // analog readings

void setup()
{
pinMode (LED, OUTPUT);
pinMode (digitalPin, INPUT);
pinMode(analogPin, INPUT); //not necessary, but it is interesting to see the analog values
Serial.begin(9600);

pinMode(STEPPER_PIN_1, OUTPUT);
pinMode(STEPPER_PIN_2, OUTPUT);
pinMode(STEPPER_PIN_3, OUTPUT);
pinMode(STEPPER_PIN_4, OUTPUT);

}
void loop () {

OneStep(false);
delay(20);

digitalInputValue = digitalRead(digitalPin) ;
if (digitalInputValue == HIGH) // When magnet is present, digitalInputValue gets 1 (HIGH) and turns LED on
{
digitalWrite (LED, HIGH);

}
else
{

digitalWrite (LED, LOW);

}

{
if (digitalInputValue ==HIGH)
delay(10000);
}

//Here you can see the analog values of the sensor
analogInputValue = analogRead(analogPin);
Serial.println(analogInputValue); // print analog value
delay(4);

}
void OneStep(bool dir) {
if (dir) {
switch (step_number) {
case 0:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
}
} else {
switch (step_number) {
case 0:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);

}

}
step_number++;
if (step_number > 3) {
step_number = 0;
}

}

Thanks in advance for your help, BUT remember I'm an ancient biochemist not a computer geek.

The software need only be loaded once - it's burned into erasable memory on the Arduino, but it will remain until you overwrite it. All you have to do to use it again is provide power.

Tried that and it didn't work.

Have just tried again and it's working now. I'll give it another go later.

Yes, we get this question from time to time.

If you have uploaded a "sketch" code and it performs as it should (and not just repeats what a previous sketch did) then it is permanent.

If it fails to start with the PC disconnected, you have a problem with the reset circuitry.

Just tried it again and it is working as it should do. thanks for the help everyone. I'll scream if things go wrong.

That can work. Or just come back for more help. :expressionless:

a7