ASK Run the motor dc and stoping with microswitch sensor

hai master i have a problem
I want to run a dc motor moves to the right and then after the sensor1 is on motor will stop a few seconds. after the motor moves to the left and when the sensor2 is on motor will stop.

This is the program I have

const int sensortutuppin= 3;//sensor2
const int sensorbukapin= 2;//sensor1
int motor1=5;
int motor2=6;

void setup()
{
pinMode(sensortutup, INPUT);
pinMode(sensorbuka, INPUT);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
}
void loop()
{
sensorbuka=digitalRead(sensorbukapin);
sensortutup=digitalRead(sensortutuppin);
digitalWrite(motor2, LOW);

if (sensorbuka==HIGH)
{
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
delay(3000);
digitalWrite(motor1, LOW);
digitalWrite(motor2, HIGH);

if (sensortutup==HIGH)
{
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
delay(3000);
}
}
}

This is the program I have
and what happens is the motor moves to the right and after sensor1 flame motorcycle dead, can not move to the left

Please help me, thank you

const int sensortutuppin= 3;//sensor2
const int sensorbukapin= 2;//sensor1
int motor1=5;
int motor2=6;

void setup()
{
  pinMode(sensortutup, INPUT);

Does that even compile? Where is sensortutup defined? Valued?

sensorbuka=digitalRead(sensorbukapin);
sensortutup=digitalRead(sensortutuppin);

I gave up on using the debug-by-guesswork approach 35 years ago. I highly recommend debug based on facts. What DID you read from the sensors? Why don't you know?

const int sensortutuppin= 3;
const int sensorbukapin= 2;
int motor1=5;
int motor2=6;
int sensorbuka;
int sensortutup;
void setup()
{
pinMode(sensortutuppin, INPUT);
pinMode(sensorbukapin, INPUT);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);

const int sensortutuppin= 3;
const int sensorbukapin= 2;
int motor1=5;
int motor2=6;
int sensorbuka;
int sensortutup;
void setup()
{
pinMode(sensortutup, INPUT);
pinMode(sensorbuka, INPUT);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
}
void loop()
{
sensorbuka=digitalRead(sensorbukapin);
sensortutup=digitalRead(sensortutuppin);
digitalWrite(motor1, HIGH);
digitalWrite(motor2, LOW);

if (sensorbuka==HIGH)
{
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
delay(3000);
digitalWrite(motor1, LOW);
digitalWrite(motor2, HIGH);

if (sensortutup==HIGH)
{
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
delay(3000);
}
}
}

So, what do you expect us to do when you post code, without explaining what it does? Or, what it does not do?

If you are expecting us to say "Oooh, pretty code...", try indenting the code properly. Otherwise, it's ugly code.

You ARE expected to answer EVERY question that is asked of you.

sorry sir, my code can not work the way I expected. I expect is that the motor can move to the right and then stop and then move and then stop, but in fact with the code only complains motors move to the right and then stop. Do not move to the left. Thank you

Do not move to the left.

Why not? Go back and re-read reply #1.

I have to try again. I swear the motor can not move to the left :frowning:

There are conditions under which you think the motor should move to the left (whatever that means for a rotating device). Are those conditions ACTUALLY ever present? Why are you guessing? Add some Serial.print() statements and KNOW.

sorry sir, I tried not just guessing.
some Serial.print()statements? please give me example.

please give me example.

sensorbuka=digitalRead(sensorbukapin);
Serial.print("sensorbuka = ");
Serial.println(sensorbuka);
sensortutup=digitalRead(sensortutuppin);
Serial.print("sensortutup = ");
Serial.println(sensortutup);

Don't forget the Serial.begin() call in setup().