Add eeprom on my program.

How do I add eeprom on my arduino code?

int potPin = 0; // analog input pin 0 for the potentiometer
int motor1Pin = 7; // H-bridge leg 1
int motor2Pin = 6; // H-bridge leg 2
int val = 0; // variable to store the value coming from the potentiometer

void setup() 
  {
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
  }

void loop() 
  {
  
    val = analogRead(potPin); // read the value from the potentiometer
    val = val/4; // convert 0-1023 range to 0-255 range
  
    if (val <= 85) 
    {
      digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge low
      delay(100);
      digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high
    }
  
  
    else if (val >=86 && val<=170)
    {
      digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
      delay(100);
      digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high
    }
  
  
    else 
    {
      digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge high
      delay(100);
      digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge low
    }
  }

Have you read the manual?

what manual?

How do I save the program on my arduino so that once I plug out the usb cable from the pc and use a battery to power up it, the program will still be there. How?

That happens automatically to flash

jimmy12:
what manual?

The word "manual" in my post was a hyperlink to the reference page on eeprom.

JimboZA:
That happens automatically to flash

But I try plugging out the usb and use a battery and connect it to the dc port. It didnt work.

So put the power back from the usb, but don't re-upload the sketch, and see if it runs. If it does, then you at least know the sketch is still there after power off and on.

Maybe your dc power is faulty... How are you powering the motors by the way?