IR sensor don't work, who know's why

does anyone know's why my IR sensors don't work?

#include <Servo.h>
Servo myservo1;
#include <Servo.h>
Servo myservo2;
int pos = 0;

int rodePin1 = 18;
int rodePin2 = 19;
int groenePin1 = 20;
int groenePin2 = 21;
int groenePin3 = 17;
int groenePin4 = 16;
int SENSORPIN1 = 41;
int SENSORPIN2 = 53;
#include <Stepper.h>
const int stepsPerRevolution = 510;
int sensorState1 = 0, lastState1 = 0;
int sensorState2 = 0, lastState2 = 0;

Stepper myStepper(stepsPerRevolution, 10, 11, 12, 13);

void setup() {
myservo1.attach(9);
myservo2.attach(9);
pinMode(rodePin1, OUTPUT);
pinMode(rodePin2, OUTPUT);
pinMode(groenePin1, OUTPUT);
pinMode(groenePin2, OUTPUT);
pinMode(groenePin3, OUTPUT);
pinMode(groenePin4, OUTPUT);
myStepper.setSpeed(10);
pinMode(SENSORPIN1, INPUT_PULLUP);
pinMode(SENSORPIN2, INPUT_PULLUP);
digitalWrite(SENSORPIN1, HIGH);
digitalWrite(SENSORPIN2, HIGH);
Serial.begin(9600);
}
void loop() {
sensorState1 = digitalRead(SENSORPIN1);
sensorState2 = digitalRead(SENSORPIN2);

digitalWrite(rodePin1, LOW);
digitalWrite(rodePin2, LOW);

if(sensorState1 == LOW) {

digitalWrite(rodePin1, HIGH);
digitalWrite(rodePin2, HIGH);
digitalWrite(groenePin1, LOW);
digitalWrite(groenePin2, LOW);
digitalWrite(groenePin3, LOW);
digitalWrite(groenePin4, LOW);

Serial.println("clockwise");
Serial.println(sensorState1);
Serial.println(sensorState2);
myStepper.step(stepsPerRevolution);

delay(3000);

for(pos=0; pos < 90; pos += 1)
{
myservo1.write(pos);
myservo2.write(pos);
delay(80);
}

}

if (sensorState2 == LOW) {

digitalWrite(rodePin1, HIGH);
digitalWrite(rodePin2, HIGH);
digitalWrite(groenePin1, LOW);
digitalWrite(groenePin2, LOW);
digitalWrite(groenePin3, LOW);
digitalWrite(groenePin4, LOW);

delay(3000);

for(pos=90; pos>=1; pos-=1)
{

myservo1.write(pos);
myservo2.write(pos);
delay(80);
}
Serial.println("counterclockwise");
Serial.println(sensorState1);
Serial.println(sensorState2);
myStepper.step(-stepsPerRevolution);
}
if (pos < 90){
digitalWrite(rodePin1, HIGH);
digitalWrite(rodePin2, HIGH);
digitalWrite(groenePin1, LOW);
digitalWrite(groenePin2, LOW);
digitalWrite(groenePin3, LOW);
digitalWrite(groenePin4, LOW);
}

else {
digitalWrite(groenePin1, HIGH);
digitalWrite(groenePin2, LOW);
digitalWrite(groenePin3, HIGH);
digitalWrite(groenePin4, LOW);
delay(500);
digitalWrite(groenePin1, LOW);
digitalWrite(groenePin2, HIGH);
digitalWrite(groenePin3, LOW);
digitalWrite(groenePin4, HIGH);
delay(500);
}

}

Why did you post this in a forum section that specifically asks you not to post in it?

Where are the code tags around he code?
Where is your schematic?
Description of the IR sensors?

Just one include is needed.

Help us help you.

Problem, bread board power rail split:


Solution, bread board power rail split:

The Arduino is not a power supply for motors.

we don't have a code error. it's just the IR sensors that don't work. I don't know where that problem comes from, we have tested the sensors on a simpler code and then it did work. We are not exactly sure which IR sensors they are, but probably IR break beam.

So, while you're finding that out, could you add the code tags you forgot?
Just click on the pencil icon, and edit them in.

Thanks.

i don't know what you mean. can you maybe write the code for me?

what are code tags?

You don't seem to have a very good grasp of your own project.

The forum doesn't work that way. We're not here to do your work for you.

Read this. You should have done that before posting your question:

click the <code> icon and paste the code in the highlighted area.

you can delete the code in the original post and try again with the icon and the code that is indented

Does the simpler code work on the wiring setup as-is? Could you post that working code? If the simpler working code can exercise both of the sensors as connected, it could help can eliminate the wiring as a problem.

From looking at the rats-nest picture, it looks like the IR sensors are powered -- do you really need the INPUT_PULLUP and digitalWrite? to enable them?

It looks like there are some long jumpers doing these connections:

double-white, double-white, and yellow& green?

...but your short ones look neater and a lot less prone to accidents and mistakes.

Can you share a proper circuit diagram

The IR sensors are diodes, requiring correct polarity. Here is your code, formatted and pasted into a code block. By the way, you only need to include Servo.h once and you had two servos attaching to one pin... and more stuff (see comment in code).

#include <Servo.h>
Servo myservo1;
// #include <Servo.h> // only need one #include<Servo.h>
Servo myservo2;
int pos = 0;

int rodePin1 = 18;
int rodePin2 = 19;
int groenePin1 = 20;
int groenePin2 = 21;
int groenePin3 = 17;
int groenePin4 = 16;
int SENSORPIN1 = 41;
int SENSORPIN2 = 53;

#include <Stepper.h>
const int stepsPerRevolution = 510;
int sensorState1 = 0, lastState1 = 0;
int sensorState2 = 0, lastState2 = 0;

Stepper myStepper(stepsPerRevolution, 10, 11, 12, 13);

void setup() {
  myservo1.attach(9);
  myservo2.attach(7); // maybe this is PWM
  myservo2.attach(9); // you had two servos on one pin.
  pinMode(rodePin1, OUTPUT);
  pinMode(rodePin2, OUTPUT);
  pinMode(groenePin1, OUTPUT);
  pinMode(groenePin2, OUTPUT);
  pinMode(groenePin3, OUTPUT);
  pinMode(groenePin4, OUTPUT);
  myStepper.setSpeed(10);
  pinMode(SENSORPIN1, INPUT_PULLUP);
  pinMode(SENSORPIN2, INPUT_PULLUP);
  digitalWrite(SENSORPIN1, HIGH);
  digitalWrite(SENSORPIN2, HIGH);
  Serial.begin(9600);
}

void loop() {
  sensorState1 = digitalRead(SENSORPIN1);
  sensorState2 = digitalRead(SENSORPIN2);

  digitalWrite(rodePin1, LOW);
  digitalWrite(rodePin2, LOW);

  if (sensorState1 == LOW) {

    digitalWrite(rodePin1, HIGH);
    digitalWrite(rodePin2, HIGH);
    digitalWrite(groenePin1, LOW);
    digitalWrite(groenePin2, LOW);
    digitalWrite(groenePin3, LOW);
    digitalWrite(groenePin4, LOW);

    Serial.println("clockwise");
    Serial.println(sensorState1);
    Serial.println(sensorState2);
    myStepper.step(stepsPerRevolution);

    delay(3000);

    for (pos = 0; pos < 90; pos += 1)
    {
      myservo1.write(pos);
      myservo2.write(pos);
      delay(80);
    }
  }

  if (sensorState2 == LOW) {

    digitalWrite(rodePin1, HIGH);
    digitalWrite(rodePin2, HIGH);
    digitalWrite(groenePin1, LOW);
    digitalWrite(groenePin2, LOW);
    digitalWrite(groenePin3, LOW);
    digitalWrite(groenePin4, LOW);

    delay(3000);

    for (pos = 90; pos >= 1; pos -= 1)
    {
      myservo1.write(pos);
      myservo2.write(pos);
      delay(80);
    }
    Serial.println("counterclockwise");
    Serial.println(sensorState1);
    Serial.println(sensorState2);
    myStepper.step(-stepsPerRevolution);
  }
  if (pos < 90) {
    digitalWrite(rodePin1, HIGH);
    digitalWrite(rodePin2, HIGH);
    digitalWrite(groenePin1, LOW);
    digitalWrite(groenePin2, LOW);
    digitalWrite(groenePin3, LOW);
    digitalWrite(groenePin4, LOW);
  }

  else {
    digitalWrite(groenePin1, HIGH);
    digitalWrite(groenePin2, LOW);
    digitalWrite(groenePin3, HIGH);
    digitalWrite(groenePin4, LOW);
    delay(500);
    digitalWrite(groenePin1, LOW);
    digitalWrite(groenePin2, HIGH);
    digitalWrite(groenePin3, LOW);
    digitalWrite(groenePin4, HIGH);
    delay(500);
  }
}

And... here is a simulation of your project. I did not include a motor, because you never write to a motor (only to the green LEDs). The two switches are the "IR". Click one at a time. Your code has both servos rotating 90 degrees in a blocking loop, so "GREEN" motors will not turn until the servos are done, and you need to wait until done before making another "IR" (switch) input.

Apostrophes are powerful if they’re used properly.