Facing problem with EEPROM results

Hi, I have done a project using Arduino UNO , a 12v dc motor control circuit for it's direction and on/off control . I need to store the output results into the internal EEPROM. It's working fine on reset, but fails to retrieve on power back conditions. As I'm a new comer to this forum, I don't know how to attach my program to reach you. Please help me to solve this issue.

Hi @shyamsunddar. You can learn about it here:

Hello
take a view here.
https://www.arduino.cc/en/Reference/EEPROM

Can I upload my program in this space?
#include <EEPROM.h>

int gled = 9;
int rled = 11;
int pushButton1 = 6;
int pushButton2 = 7;
int sensor1 = 4;
int sensor2 = 5;

int a=0;
int b=0;

void setup() {
pinMode(gled, OUTPUT);
pinMode(rled, OUTPUT);
pinMode(pushButton1, INPUT_PULLUP);
pinMode(pushButton2, INPUT_PULLUP);
pinMode(sensor1, INPUT_PULLUP);
pinMode(sensor2, INPUT_PULLUP);
Serial.begin(9600);
delay(500);
a = EEPROM.read(0);
b = EEPROM.read(1);
delay(100);
Serial.print(a);
Serial.print(b);
a=a;
a=b;
delay(100);

/*
if ((a=1) && (b==1))
{
digitalWrite(gled, HIGH);
digitalWrite(rled, LOW);
Serial.print("Result1");
digitalWrite(gled, HIGH);
digitalWrite(rled, LOW);
}

if ((a=2) && (b==2))
{
digitalWrite(gled, LOW);
digitalWrite(rled, LOW);
Serial.print("Result2");
digitalWrite(gled, LOW);
digitalWrite(rled, LOW);
}

if ((a=3) && (b==3))
{
digitalWrite(gled, LOW);
digitalWrite(rled, HIGH);
Serial.print("Result3");
digitalWrite(gled, LOW);
digitalWrite(rled, HIGH);
}

if ((a=4) && (b==4))
{
digitalWrite(gled, HIGH);
digitalWrite(rled, LOW);
Serial.print("Result4");
digitalWrite(gled, HIGH);
digitalWrite(rled, LOW);
}
*/

}

void loop()
{

int button1 = digitalRead(pushButton1);
int button2 = digitalRead(pushButton2);
int sense1 = digitalRead(sensor1);
int sense2 = digitalRead(sensor2);

if (button1==LOW)
{
a=1;
b=1;
EEPROM.write(0,a);
EEPROM.write(1,b);
delay(50);
Serial.print(a);
Serial.print(b);
delay(50);
}

if (button2==LOW)
{
a=2;
b=2;
EEPROM.write(0,a);
EEPROM.write(1,b);
delay(50);
Serial.print(a);
Serial.print(b);
delay(50);
}

if (sense1==LOW)
{
a=3;
b=3;
EEPROM.write(0,a);
EEPROM.write(1,b);
delay(50);
Serial.print(a);
Serial.print(b);
delay(50);
}

if (sense2==LOW)
{
a=4;
b=4;
EEPROM.write(0,a);
EEPROM.write(1,b);
delay(50);
Serial.print(a);
Serial.print(b);
delay(50);
}

if((a==1)&& (b==1))
{
digitalWrite(gled, HIGH);
digitalWrite(rled, LOW);
a=0;
b=0;
delay(50);
}

if((a==2) && (b==2))
{
digitalWrite(gled, LOW);
digitalWrite(rled, LOW);
a=0;
b=0;
delay(50);
}

if((a==3)&& (b==3))
{
digitalWrite(gled, LOW);
digitalWrite(rled, LOW);
delay(1000);
digitalWrite(gled, LOW);
digitalWrite(rled, HIGH);
a=0;
b=0;
delay(50);
}

if((a==4) && (b==4))
{
digitalWrite(gled, LOW);
digitalWrite(rled, LOW);
delay(1000);
digitalWrite(gled, HIGH);
digitalWrite(rled, LOW);
a=0;
b=0;
delay(50);
}}

This program is working occasionally, after retrieving the power supply sometime the data is stored and sometimes I get some other data at the output. What's the error in this program. Will somebody correct the error please?

Your variables, a and b are int data types (2 bytes each). EEPROM.write() writes only one byte at time to EEPROM. Use EEPROM.put() to write an int to EEPROM and EEPROM.get() to retrieve the data. See the EEPROM library reference.

The EEPROM library reference was linked in reply #3.

The how to get the best of the forum with instructions on how to properly post code was linked in reply#2. It does not look like you read our responses to your questions.

Use the autoformat tool of the IDE (ctrl-t or Tools, Auto Format) before posting code in code tags.