Trouble Coding 2 28BYJ-48 5V DC (motor) with a LJ12A3-4-Z/AX (sensor).

I managed to wire and code one 28BYJ-48 5V DC (motor), but what I'm trying to do is connect two 28BYJ-48 5V DC (motor) and an LJ12A3-4-Z/AX (sensor). But I'm facing major coding issues; this is the code I'm using:

int Pin1 = 10;
int Pin2 = 11;
int Pin3 = 12;
int Pin4 = 13;
int _step = 0;
boolean dir = true;//false=clockwise, true=counter clockise
void setup()
{
pinMode(Pin1, OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
}

void loop ()
{
switch (_step){
case 0:
digitalWrite(Pin1, LOW);
digitalWrite(Pin4, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, HIGH);
break;
case 1:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, HIGH);
break;
case 2:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, LOW);
break;
case 3:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, LOW);
break;
case 4:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
case 5:
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
case 6:
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
default:
digitalWrite(Pin1, LOW);
digitalWrite(Pin4, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
}
if(dir){
_step++;
}else{
_step--;
}
if(_step>7){
_step=0;
}
if(_step<0){
_step=7;
}
delay(1);
}

//setup default LED on pin 13
const int ledPin = 13;
//setup touch sensor on pin 3
const int touchPin = 3;

//store the time when last event happened
unsigned long lastEvent = 0;
//store the state of LED
boolean ledOn = false;

//setup pins
{
pinMode(ledPin, OUTPUT);
pinMode(touchPin, INPUT);
}

void loop(){
//read touch sensor state
int touchState = digitalRead(touchPin);

//only interested in the HIGH signal
if (touchState == HIGH) {
//if 50ms have passed since last HIGH pulse, it means that the
//touch sensor has been touched, released and touched again
if (millis() - lastEvent > 50) {
//toggle LED and set the output
ledOn = !ledOn;
digitalWrite(ledPin, ledOn ? HIGH : LOW);
}

//remember when last event happened
lastEvent = millis();
}
}

motor_sensor.ino (4.27 KB)

What is your coding issue? You didn't say what it is.

Also please go back and edit your post, put the code inside code tags.

rename each loop() to something else, creating two new sub-functions and call each sub-function in a new loop()

just combine the code in each setup() into a new version of setup().