SlideShare a Scribd company logo
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 1
Exp. No.: 2 Date:
Aim:
Design a series of 4 LED brightness controllers using Rotary Encoder.
Objective:
Designing a circuit for controlling the brightness of LED’s by using Rotary encoder.
Hardware Requirements:
S.No. Title of Component Component Image Quantity
1. Arduino Uno 01
2. Rotary encoder KY-040 01
3. 10KΩ resistor/ POT 02
4. 220Ω Resistor 04
5.
Connecting Wires & USB
Cable
As per
Requirement
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 2
Pre Lab Session:
1. Study of Rotary encoder module and Its Description.
2. Study of various Rotary encoder modules.
3. Perform the experiment to light the LED.
4. Study how to vary the brightness of LED
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 3
Description:
The objective of this experiment is to construct a module that varies the brightness of
LED by using Rotary encoder and an Arduino.
Rotary encoder:
With a rotary encoder we have two square wave outputs (A and B) which are 90 degrees
out of phase with each other. The number of pulses or steps generated per complete turn varies.
The Sparkfun Rotary Encoder has 12 steps but others may have more or less. The diagram below
shows how the phases A and B relate to each other when the encoder is turned clockwise or
counter clockwise.
Every time the A signal pulse goes from positive to zero, we read the value of the B pulse. We
see that when the encoder is turned clockwise the B pulse is always positive. When the encoder
is turned counter-clockwise the B pulse is negative. By testing both outputs with a
microcontroller we can determine the direction of turn and by counting the number of A pulses
how far it has turned. Indeed, we could go one stage further and count the frequency of the
pulses to determine how fast it is being turned. We can see that the rotary encoder has a lot of
advantages over a potentiometer.
We will now use the rotary encoder in the simplest of applications, we will use it to control the
brightness of an led by altering a pwm signal. We will use the easiest method to read the
encoder, that is the use of a timer interrupt to check on the values.
We will use the sparkfun encoder as discussed above. The first thing is to determine how fast we
need our timer to operate. If you imagine that at best we could turn the encoder through 180
degrees in 1/10th of a second, that would give us 6 pulses in 1/10th second or 60 pulse per
second. In reality its never likely to be this fast. As we need to detect both high and low values
this gives us a minimum frequency of 120Hz. Lets go for 200Hz just to be sure. (Note: as these
units are mechanical switches, there is the possibility of switch bounce. Using a fairly low
frequency allows us to effectively filter out any switch bounce)
Each time our timer code triggers, we compare the value of our A pulse with its previous value.
If it has gone from positive to zero, we then check the value of the B pulse to see if it is positive
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 4
or zero. Depending on the outcome we can increment of decrement a counter. We then use this
to control the PWM value to increase or decrease the brightness of the LED
Fig:1.1 Rotary encoder
Circuit
 Pin SW on the Rotary Encoder to pin 0 of Arduino.
 Pin clk on the Rotary Encoder to pin 12 of Arduino.
 Pin DT on the Rotary Encoder to pin 11 of Arduino.
 Pin GND on the Rotary Encoder to pin GND of Arduino.
 Connect pin 12 of Rotary encoder to pin GND of Arduino via 10kΩ resistor/pot.
 Connect pin 11 of Rotary encoder to pin GND of Arduino via 10kΩ resistor/pot Connect.
 Connect Pin 3 of Arduino to positive terminal of LED & connect negative terminal of
LED to ground pin of Arduino through 220Ω resistor .
 Connect Pin 5 of Arduino to positive terminal of LED & connect negative terminal of
LED to ground pin of Arduino through 220Ω resistor .
 Connect Pin 6 of Arduino to positive terminal of LED & connect negative terminal of
LED to ground pin of Arduino through 220Ω resistor
 Connect Pin 9 of Arduino to positive terminal of LED & connect negative terminal of
LED to ground pin of Arduino through 220Ω resistor
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 5
Fig 1.2 Circuit setup for interfacing single LED with Arduino UNO and rotary encoder
Procedure:
Step 1: Connect the circuit as shown in Fig 1.4.
Step 2: Complete the programme verification in Arduino Sketch and save the sketch.
Step 3: Connect the Arduino board to PC and upload the verified sketch.
Step 4: Check whether the connected LED’s are glowing or not.
Step 5: If glowing vary the brightness of the LED by rotating the knob of rotary encoder.
Programming Code:
int brightness = 120; // how bright the LED is, start at half brightness
int fadeAmount = 10; // how many points to fade the LED by
unsigned long currentTime;
unsigned long loopTime;
const int pin_A = 12; // pin 12
const int pin_B = 11; // pin 11
unsigned char encoder_A;
unsigned char encoder_B;
unsigned char encoder_A_prev=0 ;
void setup() {
// declare pin 3 to be an output:
// declare pin 5 to be an output:
// declare pin 6 to be an output:
// declare pin 9 to be an output:
pinMode(9, OUTPUT);
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 6
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(pin_A, INPUT);
pinMode(pin_B, INPUT);
currentTime = millis();
loopTime = currentTime;
}
void loop() {
// get the current elapsed time
currentTime = millis();
if(currentTime >= (loopTime + 5)){
// 5ms since last check of encoder = 200Hz
encoder_A = digitalRead(pin_A); // Read encoder pins
encoder_B = digitalRead(pin_B);
if((!encoder_A) && (encoder_A_prev)){
// A has gone from high to low
if(encoder_B) {
// B is high so clockwise
// increase the brightness, dont go over 255
if(brightness + fadeAmount <= 255) brightness += fadeAmount;
}
else {
// B is low so counter-clockwise
// decrease the brightness, dont go below 0
if(brightness - fadeAmount >= 0) brightness -= fadeAmount;
}
}
encoder_A_prev = encoder_A; // Store value of A for next time
// set the brightness of pin 9,3,5,6:
analogWrite(9, brightness);
analogWrite(3, brightness);
analogWrite(5, brightness);
analogWrite(6, brightness);
loopTime = currentTime; // Updates loopTime
}
}
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 7
Output:
Fig 1.3 Circuit with glowing LED’s
Interference Analysis:
The Rotary Encoder ships with LEDs so the end user may increase the brightness to a
level appropriate for the application. The current to each of the 4 LEDs is constant and is set per
the datasheet. A surface mount 220kΩ resistor is provided and a parallel thru-hole resistor may
be added to increase the brightness by lowering the resistance With the surface mount 220kΩ
resistor, the output current is set to about 1mA. Adding a 1kΩ resistor thru-hole will increase the
LED brightness to their highest setting.
Applications
With the help of rotary encoder , we can implement several project related not only
brightness adjustments of LED but can also implement stepper motor, counters, shafting angles
etc,.
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 8
Post Lab Session:
1. Construct a module to on and off a LED by using Rotary encoder
2. Construct a module to vary the brightness of 8 LED’s by using Rotary encoder.
3. Construct a counter module using Rotary encoder
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 9
Viva voice Questions:
Hardware Related Question.
1. What is incremental encoder ?
2. What is absolute encoder ?
3. How do you define the resolution of an encoder ?
4. AC LED - What is it?
5. Light Emitting Diode (LED) - what is it?
6. I have a "5 Volt LED" - what does it mean?
7. LED array - what is it?
8. What is PWM?
9. what is difference between 10k resistor and 10k pot?
10. why 220 resistor is connected along the LED?
Embedded Systems and Applications Laboratory Manual 2019
Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 10
Programming Related Questions
1. Does the pin SW in rotary encoder is input/output ?
2. Does the pin CLK in rotary encoder is input/output ?
3. What is the command for declaring a pin as input ?
4. What is the command for declaring a pin as output ?
5. Explain the command analogRead().
6. Explain the command digitalRead().
7. Differentiate analogRead() and digitalRead().
8. Explain the command analogWrite().
9. Differentiate analogWrite() and digitalWrite().
10. How do you modify the brightness of LED ?
Results
The design of a module that varies the brightness of LED by using Rotary encoder and an
Arduino is done. The Rotary encoder is used to vary the brightness of the LED dynamically. This
experiment can be extended to perform various projects.

More Related Content

What's hot

IRJET- Intelligent Lighting System using Arduino and PWM
IRJET- Intelligent Lighting System using Arduino and PWMIRJET- Intelligent Lighting System using Arduino and PWM
IRJET- Intelligent Lighting System using Arduino and PWM
IRJET Journal
 
Arduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIYArduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIY
Vishnu
 
Fading leds via pwm
Fading leds via pwmFading leds via pwm
Fading leds via pwm
HIET
 
Automatic control of electrical Appliances
Automatic control of electrical AppliancesAutomatic control of electrical Appliances
Automatic control of electrical Appliances
Shubham Sachan
 
Basic arduino sketch example
Basic arduino sketch exampleBasic arduino sketch example
Basic arduino sketch example
mraziff2009
 
Deepak
DeepakDeepak
Deepak
rajarjun
 
Lec 3
Lec 3Lec 3
Inbuilt Digital Weighing System Inside Travel Bag
Inbuilt Digital Weighing System Inside Travel BagInbuilt Digital Weighing System Inside Travel Bag
Inbuilt Digital Weighing System Inside Travel Bag
MOHAMMAD TANVEER
 
Smart Lighting Using IOT
Smart Lighting Using IOTSmart Lighting Using IOT
Smart Lighting Using IOT
Shrikant Chandan
 
IRJET- Intelligent Power Emulator
IRJET- Intelligent Power EmulatorIRJET- Intelligent Power Emulator
IRJET- Intelligent Power Emulator
IRJET Journal
 
ppt of automatic room light controller and BI directional counter
ppt of automatic room light controller and BI directional counterppt of automatic room light controller and BI directional counter
ppt of automatic room light controller and BI directional counter
Mannavapremkumar
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral Interfacing
Wingston
 
Home Automation System
Home Automation SystemHome Automation System
Home Automation System
MOHAMMAD TANVEER
 
How to Build a Digital Weighing Scale
How to Build a Digital Weighing ScaleHow to Build a Digital Weighing Scale
How to Build a Digital Weighing Scale
Tacuna Systems
 
Automatic room light controlling Capstone Report
Automatic room light controlling Capstone ReportAutomatic room light controlling Capstone Report
Automatic room light controlling Capstone Report
Shubham Sachan
 
How to Build Digital Weighing Scales
How to Build Digital Weighing ScalesHow to Build Digital Weighing Scales
How to Build Digital Weighing Scales
Tacuna Systems
 
Clap Pattern Based Electrical Appliance control
Clap Pattern Based Electrical Appliance controlClap Pattern Based Electrical Appliance control
Clap Pattern Based Electrical Appliance control
IRJET Journal
 
Automatic street light control using LDR.
Automatic street light control using LDR.Automatic street light control using LDR.
Automatic street light control using LDR.
Fazlur Rahman
 

What's hot (20)

IRJET- Intelligent Lighting System using Arduino and PWM
IRJET- Intelligent Lighting System using Arduino and PWMIRJET- Intelligent Lighting System using Arduino and PWM
IRJET- Intelligent Lighting System using Arduino and PWM
 
Arduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIYArduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIY
 
Fading leds via pwm
Fading leds via pwmFading leds via pwm
Fading leds via pwm
 
Automatic control of electrical Appliances
Automatic control of electrical AppliancesAutomatic control of electrical Appliances
Automatic control of electrical Appliances
 
Presentation
PresentationPresentation
Presentation
 
Basic arduino sketch example
Basic arduino sketch exampleBasic arduino sketch example
Basic arduino sketch example
 
Deepak
DeepakDeepak
Deepak
 
Lec 3
Lec 3Lec 3
Lec 3
 
Inbuilt Digital Weighing System Inside Travel Bag
Inbuilt Digital Weighing System Inside Travel BagInbuilt Digital Weighing System Inside Travel Bag
Inbuilt Digital Weighing System Inside Travel Bag
 
Smart Lighting Using IOT
Smart Lighting Using IOTSmart Lighting Using IOT
Smart Lighting Using IOT
 
IRJET- Intelligent Power Emulator
IRJET- Intelligent Power EmulatorIRJET- Intelligent Power Emulator
IRJET- Intelligent Power Emulator
 
ppt of automatic room light controller and BI directional counter
ppt of automatic room light controller and BI directional counterppt of automatic room light controller and BI directional counter
ppt of automatic room light controller and BI directional counter
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral Interfacing
 
Home Automation System
Home Automation SystemHome Automation System
Home Automation System
 
How to Build a Digital Weighing Scale
How to Build a Digital Weighing ScaleHow to Build a Digital Weighing Scale
How to Build a Digital Weighing Scale
 
Automatic room light controlling Capstone Report
Automatic room light controlling Capstone ReportAutomatic room light controlling Capstone Report
Automatic room light controlling Capstone Report
 
How to Build Digital Weighing Scales
How to Build Digital Weighing ScalesHow to Build Digital Weighing Scales
How to Build Digital Weighing Scales
 
Clap Pattern Based Electrical Appliance control
Clap Pattern Based Electrical Appliance controlClap Pattern Based Electrical Appliance control
Clap Pattern Based Electrical Appliance control
 
Arduino_Project_Report
Arduino_Project_ReportArduino_Project_Report
Arduino_Project_Report
 
Automatic street light control using LDR.
Automatic street light control using LDR.Automatic street light control using LDR.
Automatic street light control using LDR.
 

Similar to 4. exp.2 rotary encoder

Drowsiness Detected For Vehicle Using Smart Glass With Eye Blink Sensor
Drowsiness Detected For Vehicle Using Smart Glass With Eye Blink SensorDrowsiness Detected For Vehicle Using Smart Glass With Eye Blink Sensor
Drowsiness Detected For Vehicle Using Smart Glass With Eye Blink Sensor
IRJET Journal
 
IRJET- Automated Elevator-An Attentive Elevator to Elevate using Speech Recog...
IRJET- Automated Elevator-An Attentive Elevator to Elevate using Speech Recog...IRJET- Automated Elevator-An Attentive Elevator to Elevate using Speech Recog...
IRJET- Automated Elevator-An Attentive Elevator to Elevate using Speech Recog...
IRJET Journal
 
EESS.pptx
EESS.pptxEESS.pptx
EESS.pptx
IshaanSinghal7
 
Power Efficient 4 Bit Flash ADC Using Cadence Tool
Power Efficient 4 Bit Flash ADC Using Cadence ToolPower Efficient 4 Bit Flash ADC Using Cadence Tool
Power Efficient 4 Bit Flash ADC Using Cadence Tool
IRJET Journal
 
IRJET- Monitoring and Measurement of Solar Parameters using IoT
IRJET- Monitoring and Measurement of Solar Parameters using IoTIRJET- Monitoring and Measurement of Solar Parameters using IoT
IRJET- Monitoring and Measurement of Solar Parameters using IoT
IRJET Journal
 
Digital Tachometer using Aurdino
Digital Tachometer using AurdinoDigital Tachometer using Aurdino
Digital Tachometer using Aurdino
ijtsrd
 
IRJET - Automatic Mechanism for LED Parameters Testing & Checking
IRJET -  	  Automatic Mechanism for LED Parameters Testing & CheckingIRJET -  	  Automatic Mechanism for LED Parameters Testing & Checking
IRJET - Automatic Mechanism for LED Parameters Testing & Checking
IRJET Journal
 
IOT BASED SMART ENERGY METER USING ARDUINO UNO
IOT BASED SMART ENERGY METER USING ARDUINO UNOIOT BASED SMART ENERGY METER USING ARDUINO UNO
IOT BASED SMART ENERGY METER USING ARDUINO UNO
IRJET Journal
 
Digital Weight Scale
Digital Weight ScaleDigital Weight Scale
Digital Weight Scale
Harunnur Rasid
 
IRJET- Arduino Nano based All in One Meter
IRJET- Arduino Nano based All in One MeterIRJET- Arduino Nano based All in One Meter
IRJET- Arduino Nano based All in One Meter
IRJET Journal
 
IRJET - IoT based Gas Level Detection and the Automatic Booking of the Gas
IRJET - IoT based Gas Level Detection and the Automatic Booking of the GasIRJET - IoT based Gas Level Detection and the Automatic Booking of the Gas
IRJET - IoT based Gas Level Detection and the Automatic Booking of the Gas
IRJET Journal
 
Udayan_219209024_DA1001_FTP.pptx
Udayan_219209024_DA1001_FTP.pptxUdayan_219209024_DA1001_FTP.pptx
Udayan_219209024_DA1001_FTP.pptx
Syncrotrone
 
IRJET- Design of Arduino based Underground Cable Fault Detector
IRJET- Design of Arduino based Underground Cable Fault DetectorIRJET- Design of Arduino based Underground Cable Fault Detector
IRJET- Design of Arduino based Underground Cable Fault Detector
IRJET Journal
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docx
RashidFaridChishti
 
IRJET- Design and Implementation of Solar Charge Controller
IRJET- Design and Implementation of Solar Charge ControllerIRJET- Design and Implementation of Solar Charge Controller
IRJET- Design and Implementation of Solar Charge Controller
IRJET Journal
 
c ppt.pptx
c ppt.pptxc ppt.pptx
c ppt.pptx
RajHingar
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
Tony Olsson.
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
Tony Olsson.
 
IRJET- Design and Analysis of Electronics Devices V-I Characteristics usi...
IRJET-  	  Design and Analysis of Electronics Devices V-I Characteristics usi...IRJET-  	  Design and Analysis of Electronics Devices V-I Characteristics usi...
IRJET- Design and Analysis of Electronics Devices V-I Characteristics usi...
IRJET Journal
 

Similar to 4. exp.2 rotary encoder (20)

Drowsiness Detected For Vehicle Using Smart Glass With Eye Blink Sensor
Drowsiness Detected For Vehicle Using Smart Glass With Eye Blink SensorDrowsiness Detected For Vehicle Using Smart Glass With Eye Blink Sensor
Drowsiness Detected For Vehicle Using Smart Glass With Eye Blink Sensor
 
IRJET- Automated Elevator-An Attentive Elevator to Elevate using Speech Recog...
IRJET- Automated Elevator-An Attentive Elevator to Elevate using Speech Recog...IRJET- Automated Elevator-An Attentive Elevator to Elevate using Speech Recog...
IRJET- Automated Elevator-An Attentive Elevator to Elevate using Speech Recog...
 
EESS.pptx
EESS.pptxEESS.pptx
EESS.pptx
 
Report
ReportReport
Report
 
Power Efficient 4 Bit Flash ADC Using Cadence Tool
Power Efficient 4 Bit Flash ADC Using Cadence ToolPower Efficient 4 Bit Flash ADC Using Cadence Tool
Power Efficient 4 Bit Flash ADC Using Cadence Tool
 
IRJET- Monitoring and Measurement of Solar Parameters using IoT
IRJET- Monitoring and Measurement of Solar Parameters using IoTIRJET- Monitoring and Measurement of Solar Parameters using IoT
IRJET- Monitoring and Measurement of Solar Parameters using IoT
 
Digital Tachometer using Aurdino
Digital Tachometer using AurdinoDigital Tachometer using Aurdino
Digital Tachometer using Aurdino
 
IRJET - Automatic Mechanism for LED Parameters Testing & Checking
IRJET -  	  Automatic Mechanism for LED Parameters Testing & CheckingIRJET -  	  Automatic Mechanism for LED Parameters Testing & Checking
IRJET - Automatic Mechanism for LED Parameters Testing & Checking
 
IOT BASED SMART ENERGY METER USING ARDUINO UNO
IOT BASED SMART ENERGY METER USING ARDUINO UNOIOT BASED SMART ENERGY METER USING ARDUINO UNO
IOT BASED SMART ENERGY METER USING ARDUINO UNO
 
Digital Weight Scale
Digital Weight ScaleDigital Weight Scale
Digital Weight Scale
 
IRJET- Arduino Nano based All in One Meter
IRJET- Arduino Nano based All in One MeterIRJET- Arduino Nano based All in One Meter
IRJET- Arduino Nano based All in One Meter
 
IRJET - IoT based Gas Level Detection and the Automatic Booking of the Gas
IRJET - IoT based Gas Level Detection and the Automatic Booking of the GasIRJET - IoT based Gas Level Detection and the Automatic Booking of the Gas
IRJET - IoT based Gas Level Detection and the Automatic Booking of the Gas
 
Udayan_219209024_DA1001_FTP.pptx
Udayan_219209024_DA1001_FTP.pptxUdayan_219209024_DA1001_FTP.pptx
Udayan_219209024_DA1001_FTP.pptx
 
IRJET- Design of Arduino based Underground Cable Fault Detector
IRJET- Design of Arduino based Underground Cable Fault DetectorIRJET- Design of Arduino based Underground Cable Fault Detector
IRJET- Design of Arduino based Underground Cable Fault Detector
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docx
 
IRJET- Design and Implementation of Solar Charge Controller
IRJET- Design and Implementation of Solar Charge ControllerIRJET- Design and Implementation of Solar Charge Controller
IRJET- Design and Implementation of Solar Charge Controller
 
c ppt.pptx
c ppt.pptxc ppt.pptx
c ppt.pptx
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
IRJET- Design and Analysis of Electronics Devices V-I Characteristics usi...
IRJET-  	  Design and Analysis of Electronics Devices V-I Characteristics usi...IRJET-  	  Design and Analysis of Electronics Devices V-I Characteristics usi...
IRJET- Design and Analysis of Electronics Devices V-I Characteristics usi...
 

Recently uploaded

Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptxStatistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
coc7987515756
 
Digital Fleet Management - Why Your Business Need It?
Digital Fleet Management - Why Your Business Need It?Digital Fleet Management - Why Your Business Need It?
Digital Fleet Management - Why Your Business Need It?
jennifermiller8137
 
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
Fifth Gear Automotive Cross Roads
 
What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?
Hyundai Motor Group
 
一比一原版(AIS毕业证)奥克兰商学院毕业证成绩单如何办理
一比一原版(AIS毕业证)奥克兰商学院毕业证成绩单如何办理一比一原版(AIS毕业证)奥克兰商学院毕业证成绩单如何办理
一比一原版(AIS毕业证)奥克兰商学院毕业证成绩单如何办理
eygkup
 
Why Is Your BMW X3 Hood Not Responding To Release Commands
Why Is Your BMW X3 Hood Not Responding To Release CommandsWhy Is Your BMW X3 Hood Not Responding To Release Commands
Why Is Your BMW X3 Hood Not Responding To Release Commands
Dart Auto
 
Things to remember while upgrading the brakes of your car
Things to remember while upgrading the brakes of your carThings to remember while upgrading the brakes of your car
Things to remember while upgrading the brakes of your car
jennifermiller8137
 
Antique Plastic Traders Company Profile
Antique Plastic Traders Company ProfileAntique Plastic Traders Company Profile
Antique Plastic Traders Company Profile
Antique Plastic Traders
 
Renal elimination.pdf fffffffffffffffffffff
Renal elimination.pdf fffffffffffffffffffffRenal elimination.pdf fffffffffffffffffffff
Renal elimination.pdf fffffffffffffffffffff
RehanRustam2
 
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
ahmedendrise81
 
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
Fifth Gear Automotive Argyle
 
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
mymwpc
 
Regeneration of Diesel Particulate Filter in Automobile
Regeneration of Diesel Particulate Filter in AutomobileRegeneration of Diesel Particulate Filter in Automobile
Regeneration of Diesel Particulate Filter in Automobile
AtanuGhosh62
 
5 Warning Signs Your BMW's Intelligent Battery Sensor Needs Attention
5 Warning Signs Your BMW's Intelligent Battery Sensor Needs Attention5 Warning Signs Your BMW's Intelligent Battery Sensor Needs Attention
5 Warning Signs Your BMW's Intelligent Battery Sensor Needs Attention
Bertini's German Motors
 
What Does the PARKTRONIC Inoperative, See Owner's Manual Message Mean for You...
What Does the PARKTRONIC Inoperative, See Owner's Manual Message Mean for You...What Does the PARKTRONIC Inoperative, See Owner's Manual Message Mean for You...
What Does the PARKTRONIC Inoperative, See Owner's Manual Message Mean for You...
Autohaus Service and Sales
 
Empowering Limpopo Entrepreneurs Consulting SMEs.pptx
Empowering Limpopo Entrepreneurs  Consulting SMEs.pptxEmpowering Limpopo Entrepreneurs  Consulting SMEs.pptx
Empowering Limpopo Entrepreneurs Consulting SMEs.pptx
Precious Mvulane CA (SA),RA
 
Why Isn't Your BMW X5's Comfort Access Functioning Properly Find Out Here
Why Isn't Your BMW X5's Comfort Access Functioning Properly Find Out HereWhy Isn't Your BMW X5's Comfort Access Functioning Properly Find Out Here
Why Isn't Your BMW X5's Comfort Access Functioning Properly Find Out Here
Masters European & Gapanese Auto Repair
 
Skoda Octavia Rs for Sale Perth | Skoda Perth
Skoda Octavia Rs for Sale Perth | Skoda PerthSkoda Octavia Rs for Sale Perth | Skoda Perth
Skoda Octavia Rs for Sale Perth | Skoda Perth
Perth City Skoda
 
Wondering if Your Mercedes EIS is at Fault Here’s How to Tell
Wondering if Your Mercedes EIS is at Fault Here’s How to TellWondering if Your Mercedes EIS is at Fault Here’s How to Tell
Wondering if Your Mercedes EIS is at Fault Here’s How to Tell
Vic Auto Collision & Repair
 
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
Import Motorworks
 

Recently uploaded (20)

Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptxStatistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
 
Digital Fleet Management - Why Your Business Need It?
Digital Fleet Management - Why Your Business Need It?Digital Fleet Management - Why Your Business Need It?
Digital Fleet Management - Why Your Business Need It?
 
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
 
What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?
 
一比一原版(AIS毕业证)奥克兰商学院毕业证成绩单如何办理
一比一原版(AIS毕业证)奥克兰商学院毕业证成绩单如何办理一比一原版(AIS毕业证)奥克兰商学院毕业证成绩单如何办理
一比一原版(AIS毕业证)奥克兰商学院毕业证成绩单如何办理
 
Why Is Your BMW X3 Hood Not Responding To Release Commands
Why Is Your BMW X3 Hood Not Responding To Release CommandsWhy Is Your BMW X3 Hood Not Responding To Release Commands
Why Is Your BMW X3 Hood Not Responding To Release Commands
 
Things to remember while upgrading the brakes of your car
Things to remember while upgrading the brakes of your carThings to remember while upgrading the brakes of your car
Things to remember while upgrading the brakes of your car
 
Antique Plastic Traders Company Profile
Antique Plastic Traders Company ProfileAntique Plastic Traders Company Profile
Antique Plastic Traders Company Profile
 
Renal elimination.pdf fffffffffffffffffffff
Renal elimination.pdf fffffffffffffffffffffRenal elimination.pdf fffffffffffffffffffff
Renal elimination.pdf fffffffffffffffffffff
 
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
 
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
 
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
 
Regeneration of Diesel Particulate Filter in Automobile
Regeneration of Diesel Particulate Filter in AutomobileRegeneration of Diesel Particulate Filter in Automobile
Regeneration of Diesel Particulate Filter in Automobile
 
5 Warning Signs Your BMW's Intelligent Battery Sensor Needs Attention
5 Warning Signs Your BMW's Intelligent Battery Sensor Needs Attention5 Warning Signs Your BMW's Intelligent Battery Sensor Needs Attention
5 Warning Signs Your BMW's Intelligent Battery Sensor Needs Attention
 
What Does the PARKTRONIC Inoperative, See Owner's Manual Message Mean for You...
What Does the PARKTRONIC Inoperative, See Owner's Manual Message Mean for You...What Does the PARKTRONIC Inoperative, See Owner's Manual Message Mean for You...
What Does the PARKTRONIC Inoperative, See Owner's Manual Message Mean for You...
 
Empowering Limpopo Entrepreneurs Consulting SMEs.pptx
Empowering Limpopo Entrepreneurs  Consulting SMEs.pptxEmpowering Limpopo Entrepreneurs  Consulting SMEs.pptx
Empowering Limpopo Entrepreneurs Consulting SMEs.pptx
 
Why Isn't Your BMW X5's Comfort Access Functioning Properly Find Out Here
Why Isn't Your BMW X5's Comfort Access Functioning Properly Find Out HereWhy Isn't Your BMW X5's Comfort Access Functioning Properly Find Out Here
Why Isn't Your BMW X5's Comfort Access Functioning Properly Find Out Here
 
Skoda Octavia Rs for Sale Perth | Skoda Perth
Skoda Octavia Rs for Sale Perth | Skoda PerthSkoda Octavia Rs for Sale Perth | Skoda Perth
Skoda Octavia Rs for Sale Perth | Skoda Perth
 
Wondering if Your Mercedes EIS is at Fault Here’s How to Tell
Wondering if Your Mercedes EIS is at Fault Here’s How to TellWondering if Your Mercedes EIS is at Fault Here’s How to Tell
Wondering if Your Mercedes EIS is at Fault Here’s How to Tell
 
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
 

4. exp.2 rotary encoder

  • 1. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 1 Exp. No.: 2 Date: Aim: Design a series of 4 LED brightness controllers using Rotary Encoder. Objective: Designing a circuit for controlling the brightness of LED’s by using Rotary encoder. Hardware Requirements: S.No. Title of Component Component Image Quantity 1. Arduino Uno 01 2. Rotary encoder KY-040 01 3. 10KΩ resistor/ POT 02 4. 220Ω Resistor 04 5. Connecting Wires & USB Cable As per Requirement
  • 2. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 2 Pre Lab Session: 1. Study of Rotary encoder module and Its Description. 2. Study of various Rotary encoder modules. 3. Perform the experiment to light the LED. 4. Study how to vary the brightness of LED
  • 3. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 3 Description: The objective of this experiment is to construct a module that varies the brightness of LED by using Rotary encoder and an Arduino. Rotary encoder: With a rotary encoder we have two square wave outputs (A and B) which are 90 degrees out of phase with each other. The number of pulses or steps generated per complete turn varies. The Sparkfun Rotary Encoder has 12 steps but others may have more or less. The diagram below shows how the phases A and B relate to each other when the encoder is turned clockwise or counter clockwise. Every time the A signal pulse goes from positive to zero, we read the value of the B pulse. We see that when the encoder is turned clockwise the B pulse is always positive. When the encoder is turned counter-clockwise the B pulse is negative. By testing both outputs with a microcontroller we can determine the direction of turn and by counting the number of A pulses how far it has turned. Indeed, we could go one stage further and count the frequency of the pulses to determine how fast it is being turned. We can see that the rotary encoder has a lot of advantages over a potentiometer. We will now use the rotary encoder in the simplest of applications, we will use it to control the brightness of an led by altering a pwm signal. We will use the easiest method to read the encoder, that is the use of a timer interrupt to check on the values. We will use the sparkfun encoder as discussed above. The first thing is to determine how fast we need our timer to operate. If you imagine that at best we could turn the encoder through 180 degrees in 1/10th of a second, that would give us 6 pulses in 1/10th second or 60 pulse per second. In reality its never likely to be this fast. As we need to detect both high and low values this gives us a minimum frequency of 120Hz. Lets go for 200Hz just to be sure. (Note: as these units are mechanical switches, there is the possibility of switch bounce. Using a fairly low frequency allows us to effectively filter out any switch bounce) Each time our timer code triggers, we compare the value of our A pulse with its previous value. If it has gone from positive to zero, we then check the value of the B pulse to see if it is positive
  • 4. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 4 or zero. Depending on the outcome we can increment of decrement a counter. We then use this to control the PWM value to increase or decrease the brightness of the LED Fig:1.1 Rotary encoder Circuit  Pin SW on the Rotary Encoder to pin 0 of Arduino.  Pin clk on the Rotary Encoder to pin 12 of Arduino.  Pin DT on the Rotary Encoder to pin 11 of Arduino.  Pin GND on the Rotary Encoder to pin GND of Arduino.  Connect pin 12 of Rotary encoder to pin GND of Arduino via 10kΩ resistor/pot.  Connect pin 11 of Rotary encoder to pin GND of Arduino via 10kΩ resistor/pot Connect.  Connect Pin 3 of Arduino to positive terminal of LED & connect negative terminal of LED to ground pin of Arduino through 220Ω resistor .  Connect Pin 5 of Arduino to positive terminal of LED & connect negative terminal of LED to ground pin of Arduino through 220Ω resistor .  Connect Pin 6 of Arduino to positive terminal of LED & connect negative terminal of LED to ground pin of Arduino through 220Ω resistor  Connect Pin 9 of Arduino to positive terminal of LED & connect negative terminal of LED to ground pin of Arduino through 220Ω resistor
  • 5. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 5 Fig 1.2 Circuit setup for interfacing single LED with Arduino UNO and rotary encoder Procedure: Step 1: Connect the circuit as shown in Fig 1.4. Step 2: Complete the programme verification in Arduino Sketch and save the sketch. Step 3: Connect the Arduino board to PC and upload the verified sketch. Step 4: Check whether the connected LED’s are glowing or not. Step 5: If glowing vary the brightness of the LED by rotating the knob of rotary encoder. Programming Code: int brightness = 120; // how bright the LED is, start at half brightness int fadeAmount = 10; // how many points to fade the LED by unsigned long currentTime; unsigned long loopTime; const int pin_A = 12; // pin 12 const int pin_B = 11; // pin 11 unsigned char encoder_A; unsigned char encoder_B; unsigned char encoder_A_prev=0 ; void setup() { // declare pin 3 to be an output: // declare pin 5 to be an output: // declare pin 6 to be an output: // declare pin 9 to be an output: pinMode(9, OUTPUT);
  • 6. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 6 pinMode(3, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(pin_A, INPUT); pinMode(pin_B, INPUT); currentTime = millis(); loopTime = currentTime; } void loop() { // get the current elapsed time currentTime = millis(); if(currentTime >= (loopTime + 5)){ // 5ms since last check of encoder = 200Hz encoder_A = digitalRead(pin_A); // Read encoder pins encoder_B = digitalRead(pin_B); if((!encoder_A) && (encoder_A_prev)){ // A has gone from high to low if(encoder_B) { // B is high so clockwise // increase the brightness, dont go over 255 if(brightness + fadeAmount <= 255) brightness += fadeAmount; } else { // B is low so counter-clockwise // decrease the brightness, dont go below 0 if(brightness - fadeAmount >= 0) brightness -= fadeAmount; } } encoder_A_prev = encoder_A; // Store value of A for next time // set the brightness of pin 9,3,5,6: analogWrite(9, brightness); analogWrite(3, brightness); analogWrite(5, brightness); analogWrite(6, brightness); loopTime = currentTime; // Updates loopTime } }
  • 7. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 7 Output: Fig 1.3 Circuit with glowing LED’s Interference Analysis: The Rotary Encoder ships with LEDs so the end user may increase the brightness to a level appropriate for the application. The current to each of the 4 LEDs is constant and is set per the datasheet. A surface mount 220kΩ resistor is provided and a parallel thru-hole resistor may be added to increase the brightness by lowering the resistance With the surface mount 220kΩ resistor, the output current is set to about 1mA. Adding a 1kΩ resistor thru-hole will increase the LED brightness to their highest setting. Applications With the help of rotary encoder , we can implement several project related not only brightness adjustments of LED but can also implement stepper motor, counters, shafting angles etc,.
  • 8. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 8 Post Lab Session: 1. Construct a module to on and off a LED by using Rotary encoder 2. Construct a module to vary the brightness of 8 LED’s by using Rotary encoder. 3. Construct a counter module using Rotary encoder
  • 9. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 9 Viva voice Questions: Hardware Related Question. 1. What is incremental encoder ? 2. What is absolute encoder ? 3. How do you define the resolution of an encoder ? 4. AC LED - What is it? 5. Light Emitting Diode (LED) - what is it? 6. I have a "5 Volt LED" - what does it mean? 7. LED array - what is it? 8. What is PWM? 9. what is difference between 10k resistor and 10k pot? 10. why 220 resistor is connected along the LED?
  • 10. Embedded Systems and Applications Laboratory Manual 2019 Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 10 Programming Related Questions 1. Does the pin SW in rotary encoder is input/output ? 2. Does the pin CLK in rotary encoder is input/output ? 3. What is the command for declaring a pin as input ? 4. What is the command for declaring a pin as output ? 5. Explain the command analogRead(). 6. Explain the command digitalRead(). 7. Differentiate analogRead() and digitalRead(). 8. Explain the command analogWrite(). 9. Differentiate analogWrite() and digitalWrite(). 10. How do you modify the brightness of LED ? Results The design of a module that varies the brightness of LED by using Rotary encoder and an Arduino is done. The Rotary encoder is used to vary the brightness of the LED dynamically. This experiment can be extended to perform various projects.