"God carved learn programming" DIY Arduino (40) - rotary encoder modules

Paragraph 37 and reference sensor module, widely circulated on the Internet, in fact, compatible with Arduino sensor module must be more than 37 species. Since I am on hand accumulated a number of sensors and modules, in accordance with the practice makes perfect (be sure to DIY) concept, learning and communication for the purpose of preparing here one by one to try to do hands-on experiments, whether successful or not, will be recorded --- little progress or can not handle the problem, hoping to initiate. 

[Arduino] 168 kinds of sensor module series of experiments (data + Code + + graphics programming simulation programming)

Experimental forty: 360 degree rotation incremental encoder module (KY-040)

 

The rotary encoder EC11

Also called switching encoder, rotary encoder, EC11 series of line encoder has an encoder, encoder SMD, Shen plate encoder, encoder-side interpolation, EC11A is a line encoder. Due to the widely used on car DVD, car navigation, car audio, car often been called an encoder. EC11 encoder for controlling the parameters frequency, volume, speed, temperature, voltage, menu selection, the light intensity in the various instruments and the like. Section 20 to make the pulse encoder 20 has a positioning point, 15 points of said two pulse 30 is positioned. Adjustment shaft and a metal shank plastic handle, the axial length range 9-30mm, full adjustment shaft has a handle, semi-shank, a threaded shank and other versions are available. EC11 series encoders are mainly used in automotive electronics, multimedia audio, instrumentation, home appliances, intelligent home, computer peripherals, medical equipment. Mainly used for frequency adjustment, brightness adjustment, temperature adjustment, volume adjustment control parameters.

Technical parameters
Temperature range: -30 ℃ to + 80 ℃
Storage temperature range: -40 ℃ to + 85 ℃
Rated voltage: DC 5V (up to 12V)
Azimuth angle: 360 degrees (no stop points)
Rotational Life: 30,000 + 200 Cycles
Contact resistance: ≤100mΩ
insulation resistance: 100MΩ above
oscillation: ≤10mS pressed (switch SW)
life:. 20,000 ± 200 times (0.5 stroke)
          15,000 ± 200 is views (1.5 stroke).

It works
incremental encoder is to convert the displacement into an electric signal periodically, then converted into the electrical signal pulses counted, with the number of pulses indicates the displacement size. The encoder converts the angular displacement is a linear displacement into an electrical signal, or a device. Encoder in accordance with the readout approach can be divided into mechanical and non-mechanical two: mechanical output selection brush, brush touch a conductive region or insulating region to indicate status of the code is "1" is still "0"; non sensitive mechanical element is subjected to the magnetic sensing member or a photosensitive member to the light-transmitting region and the opaque areas of the photosensitive member to indicate the selection status of the code is "1" is still "0." Rotary incremental encoder output pulse to the transition, by counting device to know its position, when the encoder does not move or power, relying on the counting device to remember the orientation of the internal memories. Thus, when the power failure, the encoder does not have any movement, when the job call, the process of the encoder output pulses, there can not be disturbed and lost pulse, otherwise it will count zero offset memory device, and such partial the amount of shift is no way to know, after presenting the results as long as the fault of the production know.

Commonly used incremental encoders have a mechanical encoder, easy to use and low cost, non-mechanical high photoelectric general formula.

The rotary encoder
may be counted by the positive rotation direction and a reverse direction during the rotation number of output pulses, not counting the rotary potentiometer, this rotation count is not limited. With the button on the rotary encoder can be reset to the initial state, i.e., from 0 to start counting. Incremental encoders convert the rotational displacement is a series of digital pulse signals to the rotary sensor. These pulses are used to control the angular displacement. In Eltra angular displacement encoder using a photoelectric conversion scanning principle. Reading system to rotate radially indexing table (code disk) composed of alternating opaque and light transmitting window based on the window, while being perpendicularly irradiated with an infrared light source, the light image projected onto the code disk on the surface of the receiver . The receiver is covered with a diffraction grating, and a code wheel having the same window width. The working of the receiver is sensitive to changes in an optical disk generated by the rotation, and then converts the light into a corresponding electrical variations change. So that a low level signal again rises to a higher level, and generates a square pulse without any interference, which must be treated with an electronic circuit. Reading systems typically employ differential mode, i.e. two waveforms are compared to the same phase but different signals 180 ° in order to improve the quality and stability of the output signal. Two readings are then formed on the basis of the signal difference, thus eliminating the interference.

Photoelectric encoder
is a method of converting an analog signal into a corresponding displacement or angle of electrical pulses or digital angle / angular velocity detection element, with high accuracy, small size, reliability, etc. Digital interfaces. Photoelectric encoder typically by a lens, grating disk (code wheel), the photosensitive member and the amplification and shaping circuit. In operation, with the grating disk and the motor rotation speed, while a fan-shaped sheet with the disc disposed in parallel to the identified slot (or slot group), and when the light passes through the two grating disk do relative movement, the photosensitive member the received light flux is small when a large change continuously, after amplification and shaping circuit for processing signals in a pulse. Captured by measuring the number of pulses and frequency and can measure the rotational angle of the shaft rotation speeds. And the number of the current rotational speed by photoelectric encoder output pulses per second, the motor can be calculated.

The rotary encoder module 
operating voltage: 5V
revolution number of pulses: 20
rotary encoder may be counted by the positive rotation direction and a reverse direction during the rotation number of output pulses, not counting the rotary potentiometer, this rotation is no limit count . With the button on the rotary encoder can be reset to the initial state, i.e., from 0 to start counting.

 

 

I do rotary encoder module has five pins, namely, VCC, GND, SW, CLK, DT. Wherein VCC and GND for ground and power supply, the press should be abbreviated SW Switch (Switch), the CLK is Clock (clock), DT is the Data (data). Two pins that end as an ordinary key, that is, round handle press down the keys, you can use as a normal button. Right middle three pin GND, on both sides of two pulse signals CLK and DT. Operation of the rotary encoder is rotating and pushing the shaft, when the shaft is pressed vary the level of the SW pin, when the rotation of each rotation step and DT CLK level is regularly changed.

Terminal pin
Arduino Uno rotation sensor module 
D2 CLK (Clock Clock)
D3 DT (the Data data)
D4 SW (push switch)   
5V + the VCC   
the GND the GND  

/ * 

[] Arduino sensor module 168 kinds series of experiments (the code information + + + Graphic simulation program) 

experiments forty: 360 degree rotation incremental encoder module (KY-040) 



* / 

int the CLK = 2; 

int. 3 DT = ; 

int SW =. 4; 

const int interrupt0 = 0; 

int COUNT = 0; 

int lastCLK = 0; 

void Setup () 

{ 

  the pinMode (SW, the INPUT); 

  digitalWrite (SW, HIGH); 

  the pinMode (the CLK, the INPUT); 

  the pinMode ( DT, the INPUT); 

  attachInterrupt (interrupt0, ClockChanged, the CHANGE); 

  Serial.begin (9600); 

} 

void Loop () 

{ 

  ! IF (digitalRead (SW)! = 0 && COUNT) 

  { 

  COUNT = 0; 

  Serial.print ( " COUNT: "); 

  Serial.println (COUNT); 

  } 

}

void ClockChanged()

{

  int clkValue = digitalRead(CLK);

  int dtValue = digitalRead(DT);

  if (lastCLK != clkValue)

  {

  lastCLK = clkValue;

  count += (clkValue != dtValue ? 1 : -1);

  Serial.print("count:");

  Serial.println(count);

  }

}

  

 

Module electrical schematics

/ * 

[] Arduino sensor module 168 kinds series of experiments (the code information + + + Graphic simulation program) 

experiments forty: 360 degree rotation incremental encoder module (KY-040) of the two 

output digital to screen 

* / 

 

const int clkPin = 2; 

const int dtPin =. 3; 

const int swPin =. 4; 

int encoderVal = 0; 

 

void Setup () 

{ 

  

  the pinMode (clkPin, the INPUT); 

  the pinMode (dtPin, the INPUT); 

  the pinMode (swPin, the INPUT); 

  digitalWrite (swPin, HIGH); 

  Serial.begin (9600); 

} 

 

void Loop () 

{ 

  int = getEncoderTurn Change (); 

  encoderVal encoderVal + = Change; 

  IF (digitalRead (swPin) == the LOW) 

  { 

    encoderVal = 0; 

  } 

  Serial.println (encoderVal ); 

}

int getEncoderTurn(void)

{

  static int oldA = HIGH; 

  static int oldB = HIGH;

  int result = 0;

  int newA = digitalRead(clkPin);

  int newB = digitalRead(dtPin);

  if (newA != oldA || newB != oldB) 

  {

 

    if (oldA == HIGH && newA == LOW)

    {

      result = (oldB * 2 - 1);

    }

  }

  oldA = newA;

  oldB = newB;

  return result;

  delay(500);

}

  

 

Guess you like

Origin www.cnblogs.com/eagler8/p/11641051.html