Categories

Arduino with a rotary switch

Arduino in conjunction with a rotary switch - enkoderem MOD-16

Demonstrates substantive support to the sensor module with the Arduino microcontroller.

 

In this example we used the following elements:

 

Connection

The module works directly with the Arduino, so no need for an external source of energy. Contacts connect your null-modem according to the following table:

 

The module PinPin Arduino
+ V5 V
GNDGND
S1A5 V
S1B10
S27
S36

 

In addition, the fee includes the LEDs are tied through resistors 220 Ohm between terminal 11 and 12 and ground. The whole system is visible in the following figure.

 

 

Wiring diagram for module and Arduino Uno.

 

Service

Output S1A and S1B is the button located on the handle. After clicking it they are short. And release S2 and S3 determine the direction of movement of the disk, respectively, right and left. When motion is detected at the output the contact status appears high.

 

In the example, we used the following program code:

 

 

int led1 = 11; //led podpięta to terminal 11 
int led2 = 12; //led podpięta to pin 12 
int brightness = 0; //brightness of the led led1 
int fadeAmount = 5; //change brightness when you turn pokrętłą for led1 

void setup(){ 
 pinMode(6,INPUT); //configure the pins 6, 7 and 10 as input 
 pinMode(7,INPUT); 
 pinMode(10,INPUT); 
 pinMode(led1, OUTPUT); //pins with LEDs as output 
 pinMode(led1, OUTPUT); 

} 

void loop(){ 

 analogWrite(led1, brightness); //assign values of brightness for led1 

 if (brightness = 255) 
 brightness = 255 ; 
 if(digitalRead(6) == 1) //if there is a turnover popkrętła right or left, then the led of led1 will start to increase or decrease its brightness 
 {brightness = brightness + fadeAmount;} 
 if(digitalRead(7) == 1) 
 {brightness = brightness - fadeAmount;} 

 if(digitalRead(10) == 1 && digitalRead(led2, HIGH)) //when the button in the handle led led2 will change its state (if on, will turn off when not lit - lit) 
 {digitalWrite(led2,LOW)} 
 if(digitalRead(10) == 1 && digitalRead(led2,LOW)) 
 {digitalWrite(led2,HIGH)} 
} 

 

Pressing the handle causes the change of state of the yellow led (will alternately flash on and off). And the rotating knob we can change the brightness of the red led (to release it, and stew).