Encoder for Pololu Wheel 42x19mm

Sweet; thanks.

why the encoder doesn’t produce the output according to the input that has been given? Because when we try to make an observation using the oscilloscope the encoder doesn’t reach 2V but the oscilloscope still produce the signal?(input 5V) How we want to overcome this problem, can you suggest something for such filter? Actually I don’t know the specific type of filter that we are really needed for this case. Thanks.

How are you powering the encoder? Can you post a screen capture of what you’re seeing on your oscilloscope and a picture of how you have everything connected?

- Ben

we give 5V dc for the encoder circuit, but we don’t have the picture yet, maybe tomorrow I’ll post the picture, thanks.

Can you be more specific? What are you using for your power supply?

- Ben

I’m using 7V battery and connect it to the supply circuit which is the supply circuit will regulate the voltage to 5V and from the output I give it to the encoder circuit? Is it specific enough?

Unfortunately, your telling me that you’re (and I’m paraphrasing slightly) “giving the encoder 5 V from a circuit” doesn’t give me a clear picture of what you’re doing. In theory your description sounds fine (if you supply the encoder with 5 V, it should generally work), but given that something is apparently not working, I need details in order to be able to identify the part of your system that might be responsible for problem.

First of all, 7 V is not a natural nominal battery voltage; can you specifically tell me what kind of battery you are using? My guess would be two LiPo cells in series, but I’d rather not have to be guessing. Did you measure your battery voltage with a multimeter or your oscilloscope? Secondly, what circuit are you using to obtain 5 V? Did you measure the output of this circuit to verify that it is really 5 V? And third, how is this connected to your encoder. A picture of your setup would help a lot with this last one, and I would also like to see a picture an oscilloscope capture of your encoder output as I’m not sure I even understand your problem.

- Ben

Hello Ben, is it necessary to using both of output in order to measure the distance?

You need both outputs if you want to know the direction of rotation. If you know the motor is always spinning in the same direction, you can get by with one output, though you’ll have lower resolution than if you used both.

- Ben

OK thanks Ben

Hello again Ben, I want to ask something regarding your formula. Why your formula doesn’t fit in my program. Here I attached my program with my wiring diagram.

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

// for encoder declaration
#define encoder0PinA  2
#define encoder0PinB  3
#define encoder0PinC  A4
#define encoder0PinD  A5
volatile unsigned int encoder0PosA = 0;
volatile unsigned int encoder0PosB = 0;

// for motor shield declaration
int EN1 = 6; 
int EN2 = 5;  
int M1 = 7;
int M2 = 4; 

// for button declaration
const int buttonPin1 = A3;
const int buttonPin2 = A2;
const int buttonPin3 = A1;

volatile unsigned int rotate = 1;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;

// for motor shield ON/OFF setting with PWM 
void Motor1(int pwm, boolean reverse)
     {
      analogWrite(EN1,pwm); //set pwm control, 0 for stop, and 255 for maximum speed
      if(reverse)
        {
         digitalWrite(M1,HIGH);   
        }
      else
        {
          digitalWrite(M1,LOW);   
        }
     } 
         
void Motor2(int pwm, boolean reverse)
     {
      analogWrite(EN2,pwm);
      if(reverse)
        {
         digitalWrite(M2,HIGH);   
        }
      else
        {
         digitalWrite(M2,LOW);   
        }
     }  
        
        
void setup() { 
    
    //Robot Name
    lcd.begin(16, 2);
    lcd.setCursor(1, 0);
    lcd.print("ENCODER ROBOT!"); 
    lcd.setCursor(0, 1);
    lcd.print("(0.5/1/1.5)METER"); 
  
    //Motor stop
    Motor1(0,false);  
    Motor2(0,false);
    
    //Declaration Input for button
    pinMode(buttonPin1, INPUT);
    pinMode(buttonPin2, INPUT);
    pinMode(buttonPin3, INPUT);
    
    //Declaration Input for encoder
    pinMode(encoder0PinA, INPUT); 
    digitalWrite(encoder0PinA, HIGH);
    pinMode(encoder0PinB, INPUT); 
    digitalWrite(encoder0PinB, HIGH);       // turn on pullup resistor
    pinMode(encoder0PinC, INPUT); 
    digitalWrite(encoder0PinC, HIGH);       // turn on pullup resistor 
    pinMode(encoder0PinD, INPUT); 
    digitalWrite(encoder0PinD, HIGH);       // turn on pullup resistor  
    
    //Serial baud rate setup
    Serial.begin (9600);
    Serial.println("start");                // a personal quirk 
 
} 

void loop()

{
  buttonState1 = digitalRead(buttonPin1);  // read the state of the pushbutton value:
  buttonState2 = digitalRead(buttonPin2);  // read the state of the pushbutton value:
  buttonState3 = digitalRead(buttonPin3);  // read the state of the pushbutton value:
  
//============================================================================================================================  
  //When pushbutton 1 energized, it will do this program
  
  if (buttonState1 == HIGH)  
  {
    //Display targeting location
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("BUTTON 1 PRESSED");
    lcd.setCursor(0, 1);
    lcd.print("TARGET 0.5 METER");
    
    if (rotate==1)
     {
           Motor1(100,true);  //Motor1 stop
           Motor2(99,true);  //Motor2 stop
         
          for (encoder0PosA = 0 ; encoder0PosA <= 1390 ; encoder0PosA ++)
          { 
          if (!(encoder0PinA == HIGH )&&(!(encoder0PinB == HIGH ))) 
            {
            Serial.println (encoder0PosA, DEC);
            } 
          }
          Motor1(0,false);  //Motor1 stop
          Motor2(0,false);  //Motor2 stop
          
          for (encoder0PosB = 0 ; encoder0PosB <= 1390 ; encoder0PosB ++)
          {
          if (!(encoder0PinC == HIGH )&&(!(encoder0PinD == HIGH )))
            {
            //Serial.println (encoder0PosB, DEC);
            }
          }
          Motor1(0,false);  //Motor1 stop
          Motor2(0,false);  //Motor2 stop
          Serial.println ("0.5 Meter");
          rotate = 0;     
     }     
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
      lcd.print("RIGHT");
      lcd.setCursor(6, 0);
      lcd.print("LEFT");
      lcd.setCursor(11, 0);
      lcd.print("METER");
      
      lcd.setCursor(0, 1);
      lcd.print(encoder0PosA - 1);
      lcd.setCursor(6, 1);
      lcd.print(encoder0PosB - 1);
      lcd.setCursor(12, 1);
      lcd.print("0.5");
      rotate = 1;
  }
  

//============================================================================================================================ 
//When pushbutton 2 energized, it will do this program
  
  if (buttonState2 == HIGH)  
  {
    //Display targeting location
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("BUTTON 2 PRESSED");
    lcd.setCursor(1, 1);
    lcd.print("TARGET 1 METER");
    
    if (rotate==1)
     {
           Motor1(100,true);  //Motor1 stop
           Motor2(99,true);  //Motor2 stop
         
          for (encoder0PosA = 0 ; encoder0PosA <= 2590 ; encoder0PosA ++)
          { 
          if (!(encoder0PinA == HIGH )&&(!(encoder0PinB == HIGH ))) 
            {
            Serial.println (encoder0PosA, DEC);
            } 
          }
          Motor1(0,false);  //Motor1 stop
          Motor2(0,false);  //Motor2 stop
          
          for (encoder0PosB = 0 ; encoder0PosB <= 2590 ; encoder0PosB ++)
          {
          if (!(encoder0PinC == HIGH )&&(!(encoder0PinD == HIGH )))
            {
            //Serial.println (encoder0PosB, DEC);
            }
          }
          Motor1(0,false);  //Motor1 stop
          Motor2(0,false);  //Motor2 stop
          Serial.println ("1 Meter");
          rotate = 0;     
     }     
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
      lcd.print("RIGHT");
      lcd.setCursor(6, 0);
      lcd.print("LEFT");
      lcd.setCursor(11, 0);
      lcd.print("METER");
      
      lcd.setCursor(0, 1);
      lcd.print(encoder0PosA - 1);
      lcd.setCursor(6, 1);
      lcd.print(encoder0PosB - 1);
      lcd.setCursor(13, 1);
      lcd.print("1");
      rotate = 1;
  }
 
//============================================================================================================================ 
//When pushbutton 3 energized, it will do this program

  if (buttonState3 == HIGH)  
  {
    //Display targeting location
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("BUTTON 3 PRESSED");
    lcd.setCursor(0, 1);
    lcd.print("TARGET 1.5 METER");
    
    if (rotate==1)
     {
           Motor1(100,true);  //Motor1 running
           Motor2(98,true);  //Motor2 running
         
          for (encoder0PosA = 0 ; encoder0PosA <= 3790 ; encoder0PosA ++)
          { 
          if (!(encoder0PinA == HIGH )&&(!(encoder0PinB == HIGH ))) 
            {
            Serial.println (encoder0PosA, DEC);
            } 
          }
          Motor1(0,false);  //Motor1 stop
          Motor2(0,false);  //Motor2 stop
          
          for (encoder0PosB = 0 ; encoder0PosB <= 3790 ; encoder0PosB ++)
          {
          if (!(encoder0PinC == HIGH )&&(!(encoder0PinD == HIGH )))
            {
            //Serial.println (encoder0PosB, DEC);
            }
          }
          Motor1(0,false);  //Motor1 stop
          Motor2(0,false);  //Motor2 stop
          Serial.println ("1.5 Meter");
          rotate = 0;     
     }     
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
      lcd.print("RIGHT");
      lcd.setCursor(6, 0);
      lcd.print("LEFT");
      lcd.setCursor(11, 0);
      lcd.print("METER");
      
      lcd.setCursor(0, 1);
      lcd.print(encoder0PosA - 1);
      lcd.setCursor(6, 1);
      lcd.print(encoder0PosB - 1);
      lcd.setCursor(12, 1);
      lcd.print("1.5");
      rotate = 1;
  }

   else 
      {
      rotate = 1;
      encoder0PosA = 0;
      encoder0PosB = 0; 
      }
}

//Programming Ends 
//============================================================================================================================

I’m sorry, but I don’t understand your question.

- Ben

for (encoder0PosA = 0 ; encoder0PosA <= 1390 ; encoder0PosA

here is the line from my source code which tells how many pulses that I have to put to make the robot travel at certain distance. From the code above I have to put 1390 pulses for 0.5m (19.685039 inches). But if I want to apply your formula which is :

19.685039 inches / O.43 = x (pulse)

= 45.779 ≈ 46 pulse

why the theoretical doesn’t fit with the actual situation?

Ok, I see now, but did you really expect me to get that from what you posted previously? Do you appreciate how much time it would take for someone else to read through a program that long and understand it well enough to figure what it does versus what you want it to do? It makes things a lot easier when you specifically call out the problem!

At any rate, it looks like you’re not actually reading the encoders, but it’s hard to tell since your program is still much more complicated than it needs to be. Please simplify it to the shortest program that still demonstrates the problem. For example, you should be able to write a very short program that prints the pulse count to the LCD or serial monitor as you rotate the wheel by hand.

- Ben