IR Encoder with DC Motor

Hello

I need to move a dc motor with a IR encoder, the idea is while the dc motor moves and when encoder detects a state count 1, for each counting do something different but non stop in each if conditions.

This is my idea.

const int encoderIn = 8; // input pin for the interrupter 
int detectState=0; // Variable for reading the encoder status
pinMode (IN4, OUTPUT);    
pinMode (IN5, OUTPUT);    
int IN4 = 4;
int IN5 = 5;
int count = 0;

void setup()
{
  pinMode(encoderIn, INPUT); 
  pinMode (IN4, OUTPUT);   
  pinMode (IN5, OUTPUT);    
   
}
void loop() {
  digitalWrite (IN4, HIGH);
  digitalWrite (IN5, LOW); 
   detectState=digitalRead(encoderIn);
      if (detectState == HIGH) { 
       count++;
        if (count = = 2){
           //move another motor
        }
        if (count = = 4){
          //move another motor
        }    
   }
   
}

In this idea the program will stop in each if conditions but I need some similar to switch - case but differente conditions of the encoder.

Ty !

The two equal signs in == can't have a space between them.

The code won't stop in those if statements. It will run them, finish them, exit and restart the loop. Try it and see what happens.

Delta_G: The two equal signs in == can't have a space between them.

The code won't stop in those if statements. It will run them, finish them, exit and restart the loop. Try it and see what happens.

Yes, srry..I typed wrong the two equal.

I know that the code it will run each if statements but I need to compare the value of encoder and depends of the pulse "HIGH" do something different.

That's what you have. It will read the encoder and add to your counter and then do something different based on the value of that counter. Then it will read the encoder again, add to the counter and do something different based on the new counter value. Then it will read the encoder again, add to the counter and do something different based on the new counter value. Then it will read the encoder again, add to the counter and do something different based on the new counter value. Then it will read the encoder again, add to the counter and do something different based on the new counter value. Then it will read the encoder again, add to the counter and do something different based on the new counter value. Maybe I'm misunderstanding your question. Have you tried any code yet?

  pinMode (IN4, OUTPUT);   
  pinMode (IN5, OUTPUT);

Do you name your INPUT pins OUT1 and OUT2?