Rotary Encoder with Nokia 5110 display Tutorial
Today in this instructable iam going to share how the rotary encoder works with the nokia 5110 LCD display, the rotary are used in many applications that require precise shaft unlimited rotation-including industrial controls, robotics, special purpose photographic lenses, computer input devices, controlled stress rheometers, and rotating radar platforms. we are going to use the nokia 5110 LCD to display the value of the roatary.
What Will I Learn?
What you may learn in this tutotria is how the rotary encoder works, how to add zip library to arduino IDE and the connection of the nokia LCD to arduino, so lets start this.
Requirements
There are couple of arduino components er are going to use;
Difficulty
When its come to difficulties this tutorial is just a** basic one**, first we need to connect the wires and follow the diagrams download the zip file then connect the arduino to your computer then upload the code. so you have to follow the steps below:)
Tutorial Contents
Lets start this tutorial by following the circuit diagram that i made on fritzing some parts of the roatary encoder may be different but you can check my wiring below.
Connect the Nokia 5110 display. Remember that the LCD runs on 3.3V pin on the uno board and some people have connected it to 5V, it has worked but gave some weird grahics effects, the LCD has 8 pins which will be connected to a specified pin on the arduino.
The Rotary that am using has 5 pins which will be connected to specified pin on the arduino. it is also called a shaft encoder, is an electro-mechanical device that converts the angular position or motion of a shaft or axle to an analog or digital code.
SOFTWARE
We are done building the circuit so lets start to set up and make a code for this. we are going to use the arduino ide, to set the sketch for this, if you dont have make sure to download the Arduino IDE for your specific operating system. I’ll leave a link to where you can download this software: https://www.arduino.cc/en/Main/Software
I have the IDE downloaded to my computer so lets start to work for the libraries we have to download 3 libraries listed below.
-To get the nokia 5110 LCD library we need to download the zip file from rinkydinkelectronics you can download it directly here http://www.rinkydinkelectronics.com/library.php?id=47
-To get the encoder library: https://github.com/0xPIT/encoder/tree/arduino
-To get the TimerOne library: https://github.com/PaulStoffregen/TimerOne
When the download is finished open the zip file then copy the folder nameTimerOne-master, Nokia 5110-graph and rotaryencoder unzip the folder to your desktop you can rename it as well.
Cut the folder of the 3 libraries in your desktop then go to your folders then locate the arduino folder>> libraries then paste it there. and now the folder LCD5110_Grap, The Timerone and the rotaryencoder is already in the arduino ide libraries.
The first thing we need to do like with every other code, is include all the libraries we will be using we have to add the 3 library that we have recently downloaded.
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <LCD5110_Graph.h>
COPY CODE HERE:
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <LCD5110_Graph.h>
LCD5110 lcd(8,9,10,12,11);
extern unsigned char SmallFont[];
extern unsigned char TinyFont[];
ClickEncoder *encoder;
int16_t last, value;
void timerIsr() {
encoder->service();
}
void setup() {
lcd.InitLCD();
lcd.setFont(TinyFont);
lcd.print("Rotary Endcoder",CENTER,0);
lcd.print("DEMO",CENTER,20);
lcd.update();
delay(2000);
lcd.setFont(SmallFont);
encoder = new ClickEncoder(A1, A0, A2);
encoder->setAccelerationEnabled(false);
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);
last = -1;
}
void loop() {
int encoderValue;
int encoderPosition;
lcd.setFont(SmallFont);
char encoderValueArray[3];
char encoderPositionArray[3];
value += encoder->getValue();
if (value/4 != last) {
encoderValue = value/4;
encoderPosition = encoderValue%20;
last = encoderValue;
lcd.clrScr();
lcd.print("Value: ",LEFT,0);
dtostrf(encoderValue, 3, 0, encoderValueArray);
lcd.print(encoderValueArray,LEFT+55,0);
dtostrf(encoderPosition, 3, 0, encoderPositionArray);
lcd.print("Position:",LEFT,20);
if(encoderPosition <0)
encoderPosition = -encoderPosition;
lcd.print(encoderPositionArray,LEFT+55,20);
//Serial.print("\n");
lcd.update();
}
ClickEncoder::Button b = encoder->getButton();
if (b != ClickEncoder::Open) {
#define VERBOSECASE(label) case label:lcd.setFont(TinyFont);lcd.print(#label,CENTER,40);lcd.update(); break;
switch (b) {
VERBOSECASE(ClickEncoder::Pressed);
VERBOSECASE(ClickEncoder::Held)
VERBOSECASE(ClickEncoder::Released)
VERBOSECASE(ClickEncoder::Clicked)
case ClickEncoder::DoubleClicked:
encoder->setAccelerationEnabled(!encoder->getAccelerationEnabled());
break;
}
}
}
When i turn the rotary encoder to the right it increase its value and when i turn it to the left it decreases its value, the main advantage of the the rotary encoder is we can turn it unlimited times. if we are going to press the button the display relects that the roatry is held and release after i pull my finger.
This is my first project using the rotary encoder module so i hope you enjoy this actitvity if want to learn how arduino works, and how to make a sketch, then maybe this site http://educ8s.tv/ might help you, i was inspired by educ8 and electronic-lab for this wonderful stuff. so thats it, if you want to know and see my future activity follow me! and dont forget to follow me! thank you.
You can also check my previous posts:
How to connect nokia 5110 LCD to arduino
TM1637 4 digit 7-segment display with Arduino
How to adjust LED brightness using potentiometer/ visual programming XOD
How to make 12 LED chaser without shift
Posted on Utopian.io - Rewarding Open Source Contributors












Good post
Thank you
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Keep up the good work!
Thank you
Hey @pakganern I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x