Motor, limit switches and a rotary angle sensor

Based on your picture, I see this in the web site that would concern me "Purchase instructions:
Disassembled goods, used motor, motor looks very beautiful!
Only test the normal rotation of the motor!
Encoder does not know how to test, so no test, no guarantee encoder good or bad!"

Also the specifications I found repeat the idea that this is a deceleration motor from some type of Swiss machine. That tells me it was used to control the deceleration speed of some other motor.
Good luck with your project.

How can we check if the encoder is working or not?

A good start would be to look at the encoder out and since I can't find a good data sheet I have no idea which leads do what or what the encoder out should even look like.

Ron

It has 6 conclusions. The last one starts VCC.
I assume the connection is like this:

Hi, @muhammedjan

Then write some simple code to output to the IDE monitor the digital values of D2 and D4.
Don't worry about interrupts or anything fancy.
Just output the raw data from those input pins as you slowly rotate the encoder to the IDE.

This way you are also learning the basics of troubleshooting.

Tom.. :smiley: :+1: :coffee: :australia:

Using your Arduino board to drive your motor power is not a good idea. First I have no idea what your motor current will be and next you are adding motor noise to your Arduino and micro controllers hate noise. Now if Vcc is strictly the encoder power that is fine. So motor power is Motor(+) and Motor(-).

As drawn your motor looks to have a quadurature encoded output. I would be looking at A and B out on a scope. The link explains it.

Earlier you mentioned limit switches and in the latest image I see no limit switch outputs? I see what looks to be a quadrature encoded output.

Ron

I'm trying esp8266 instead of arduino uno.
I didn't turn on the power to the motor
Here is the connection:
image

Here is the code:

/*
   Author: Automatic Addison
   Website: https://automaticaddison.com
   Description: Count the number of encoder pulses per revolution.
*/

// Encoder output to Arduino Interrupt pin. Tracks the pulse count.
#define ENC_IN_RIGHT_A 2

// Keep track of the number of right wheel pulses
volatile long right_wheel_pulse_count = 0;

void setup() {

  // Open the serial port at 9600 bps
  Serial.begin(9600);

  // Set pin states of the encoder
  pinMode(ENC_IN_RIGHT_A , INPUT_PULLUP);

  // Every time the pin goes high, this is a pulse
  attachInterrupt(digitalPinToInterrupt(ENC_IN_RIGHT_A), right_wheel_pulse, RISING);

}

void loop() {

  Serial.print(" Pulses: ");
  Serial.println(right_wheel_pulse_count);
}

// Increment the number of pulses by 1
void right_wheel_pulse() {
  right_wheel_pulse_count++;
}

Here is the Serial result:

--------------- CUT HERE FOR EXCEPTION DECODER ---------------
⸮a⸮⸮⸮⸮5ya肊⸮ISR not in IRAM!

User exception (panic/abort/assert)
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Abort called

>>>stack>>>

ctx: cont
sp: 3fffff80 end: 3fffffd0 offset: 0010
3fffff90:  00002580 0000001c 00000002 40202281  
3fffffa0:  3fffdad0 00000000 3ffee570 4020105b  
3fffffb0:  3fffdad0 00000000 3ffee570 40201970  
3fffffc0:  feefeffe feefeffe 3fffdab0 40100d95  
<<<stack<<<

Please take a look

You can run this simple output test. Turn the motor shaft slowly by hand.

#define encoderPinA 2
#define encoderPinB 4

byte readingA = 0;
byte readingB = 0;
byte last_readingA = 0;
byte last_readingB = 0;

void setup() {
  Serial.begin (115200);

  //pinMode(encoderPinA, INPUT);
  //pinMode(encoderPinB, INPUT);
   pinMode(encoderPinA, INPUT_PULLUP);
   pinMode(encoderPinB, INPUT_PULLUP);
}

void loop() {
  last_readingA = readingA;
  last_readingB = readingB;
  readingA = digitalRead(encoderPinA);
  readingB = digitalRead(encoderPinB);
  if ((readingA != last_readingA) or (readingB != last_readingB)) // a or b has changed
    // if(readingA != last_readingA) //only a changed
  {
    Serial.print(readingA);
    Serial.print('\t');
    Serial.println(readingB);
  }
}

Report the pattern you see.

There is nothing in Serial. But in the end , such symbols came out:

Is the Serial Monitor set for 115200 baud rate to match the rate used by the sketch?

Yes
image

Hi, @muhammedjan

It would be preferable that you use the UNO, it is 5V logic like the encoder.

Do not power the motor, just turn it's output shaft to turn the encoder.

Make sure you have the IDE Monitor serial set to the Serial.begin baud rate.

Tom.. :smiley: :+1: :coffee: :australia:

I don't have an arduino uno in my hands right now. Instead, i can use the arduino mega 2560 ?(mini version)

Is it possible to use a different pin 2,3. I just need to change the code too, right?

Using a Mega is fine.
Use any two pins you want for the digitalRead() test of the encoder output pattern. Change the code to match the pins you use.

There was such a result, at first, then there is nothing
image

This is not normal output. Nothing is changing as you rotate the encoder. All you are seeing is the initial pull up values on the pins.

There should be 4 wires connected to the Arduino. Two for power (+5v and Gnd) and two A and B leads to pins 2 and 3.

If you are connected correctly, then the encoder may be broken.

When I unscrewed the rear of the motor, I scratched the factory wires. I had to solder everything and solder new wires. Please look at all the norms soldered in?

Please take a look

Please take a look