Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

26.04.2020 Ardu no Rotary Encoder Menu - educ8s.

tv - Watch Learn Bu ld

Videos Tutorials Support Contact Blog About

Arduino Rotary Encoder Menu Home / Arduino Projects / Arduino Rotary Encoder Menu

 Previous Next  Custom Searc

Free Project Articles


Arduino Rotary Encoder Menu Get the latest Arduino, Raspberry
Pi and electronics project articles
rst.
Products are manufactured
using technologies of leading  Name

companies of PCB…  Email


Ad Novatek-Electro
Join Now
Open
100% Privacy. We don't spam.

Hello guys, Nick again, welcome to educ8s.tv,  a channel dedicated to DIY electronics projects with Arduino,
Raspberry Pi, ESP8266 and other popular boards.

Today we are going to be creating a rotary encoder controlled menu on a Nokia 5110 LCD display. Let’s get
started!

Arduino Menu Tutorial with a Rotary Encoder and a Nokia 5110 …


educ8s.tv/ardu no-rotary-encoder-menu/ 1/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

In today’s tutorial, we are going learn how to build our own menu for the popular Nokia 5110 LCD display, in
order to make our projects more user-friendly and infuse it with more capabilities. We have built a similar
project in the past, but a lot of our viewers suggested that I should prepare another video on this subject so
here it is.

The last time out, we used pushbuttons to navigate through the menu, but today, we will be using the rotary
encoder to navigate through the menu. We will also be adding more options to the menu from the previous
tutorial to enable us fully explore the ability of the rotary encoder to serve as a navigation tool.

A rotary encoder is an electro-mechanical device which converts the angular position or rotation of its shaft
or axle to an analog or digital signal. They are used in several systems where precision and feedback in terms
of rotational motion or angular position are required. Another good feature of the rotary encoder which will
come in handy for this tutorial is that they come with buttons attached, so it can be clicked by pressing the
nob and it will be recognized by the Arduino just as it will if it were any other button or switch.

Rotary Encoder

educ8s.tv/ardu no-rotary-encoder-menu/ 2/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

To demonstrate the Arduino rotary encoder menu, we will be creating a simple menu which is displayed on
the Nokia 5110 LCD display when the project is powered and with the rotary encoder, we will be able to
navigate up or down the menu, selecting a menu option by pressing the rotary encoder button. The menu has
6 items, and as we navigate and select each item, the display will change accordingly. Sound’s exciting then
let’s build.

Required Components and Where to Buy

The following components/parts are required to build this project and they can be bought through the link in
front of each component.

1. Arduino Uno   https://educ8s.tv/part/ArduinoUno

2. Rotary Encoder   https://educ8s.tv/part/RotaryEncoder

3. Nokia 5110 LCD   https://educ8s.tv/part/NOKIA5110

4. Small Breadboard   https://educ8s.tv/part/SmallBreadboard

5. Jumper Wires   https://educ8s.tv/part/JumperWires

6. Wires   https://educ8s.tv/part/Wires

7. Power Bank   https://educ8s.tv/part/Powerbank

Full disclosure: All of the links above are af liate links. I get a small percentage of each sale they generate.
Thank you for your support!

Schematics
Connect the components/parts as shown in the schematics below.


educ8s.tv/ardu no-rotary-encoder-menu/ 3/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

Schematics

To simplify the schematics further, the pin connection between the components is described below.

LCD Arduino

Reset D3

pin2 D4

pin3 D5

pin4 D11

pin5 D13 
educ8s.tv/ardu no-rotary-encoder-menu/ 4/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

VCC 3.3v

Backlight D7

GND GND

Rotary Encoder Arduino

GND GND

VCC VCC

SW A2

DT A1

CLK A0

Connect the components as described and double check your connections to make sure there is no mistake.

Code
The code of the project is complex but I will do my best to explain it. You will get a basic understanding of
how the code works but to totally grab it, I will advise you try creating your own menu and see exactly how it
works.

To implement this project, we will be using 4 libraries. Two out of the four libraries will be used for the
display, and the remaining two will be used to interface with the rotary encoder.

LIBRARIES

  Adafruit GFX: https://github.com/adafruit/Adafruit-GFX-Library

 Nokia 5110: https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library

 Encoder Library: https://github.com/0xPIT/encoder/tree/arduino

TimerOne library: https://github.com/PaulStoffregen/TimerOne 


educ8s.tv/ardu no-rotary-encoder-menu/ 5/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

To brie y explain the code;

The rst thing we do is include the libraries we will be using for the project.

//////////////////////////////////////////////
// Arduino Rotary Encoder Menu //
// v1.0 //
// http://www.educ8s.tv //
/////////////////////////////////////////////

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <ClickEncoder.h>
#include <TimerOne.h>

Next, we create variables to hold the menus after which we create an object of the click encoder and the LCD
library.

int menuitem = 1;
int frame = 1;
int page = 1;
int lastMenuItem = 1;

String menuItem1 = "Contrast";


String menuItem2 = "Volume";
String menuItem3 = "Language";
String menuItem4 = "Difficulty";
String menuItem5 = "Light: ON";
String menuItem6 = "Reset";

boolean backlight = true;


int contrast=60;
int volume = 50;

String language[3] = { "EN", "ES", "EL" };


int selectedLanguage = 0;

String difficulty[2] = { "EASY", "HARD" };


int selectedDifficulty = 0;

boolean up = false;
boolean down = false;

educ8s.tv/ardu no-rotary-encoder-menu/ 6/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

boolean middle = false;

ClickEncoder *encoder;
int16_t last, value;

Adafruit_PCD8544 display = Adafruit_PCD8544( 5, 4, 3); //Download the latest Adafruit Library in order to use this constructor

Next, we write the void setup function. The void setup function contains the code used to initialize our screen
and the rotary encoder setting it to start at zero. We also created an interrupt routine which will be used to
detect button press during within any of the menu pages.

void setup() {

pinMode(7,OUTPUT);
turnBacklightOn();

encoder = new ClickEncoder(A1, A0, A2);


encoder->setAccelerationEnabled(false);

display.begin();
display.clearDisplay();
setContrast();

Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);

last = encoder->getValue();
}

With the void setup() all done, we proceed to write the void loop function which is the one with some level of
complexity. The function basically creates the menu and uses the variables created initially to keep track of
the previous, current and next state so when the rotary encoder is turned, it knows the right menu to display.
The menu selection part of the code is also handled by a routine within the void loop() function.

The complete code for this project (Arduino Rotary Encoder Menu.) can be downloaded by clicking the link
below.

CODE OF THE PROJECT


 
 DOWNLOAD
 

educ8s.tv/ardu no-rotary-encoder-menu/ 7/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

Upload the code to your Arduino board and you should see the display come up as shown in the image below.

Demo

That’s it for this tutorial guys, thanks for watching/reading. As usual, feel free to reach out to me via
comments should you get stuck with any of the steps, I will be glad to help. Also by subscribing, you get
noti ed by youtube whenever we post a new tutorial video so please, subscribe.

——————–

SUBSCRIBE ON YOUTUBE

——————–
Never miss a video: Subscribe to educ8s.tv


educ8s.tv/ardu no-rotary-encoder-menu/ 8/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

Professional design of Arduino Nokia 5110 CONTROLLINO - Arduino IR


PCBs Menu Software Open Source thermometer project
PLC

Ad Novatek-Electro educ8s.tv Ad controllino.biz educ8s.tv

Digital/Analog Arduino Easy Module Arduino Weather ESP32 Weather Station


Inclinometers - ZC® Shield Station Project with
inclinometer ATMEGA328P, DHT22,
Manufacturer BMP180, BH1750…
Ad inclinesensor.com educ8s.tv educ8s.tv educ8s.tv

Share This Story, Choose Your Platform!         

25 Comments

p_ferreira April 8, 2017 at 9:53 pm - Reply

Excuse me, but isn’t missing the link to the “CODE OF THE PROJECT & SCHEMATIC”?

Nick April 9, 2017 at 8:37 am - Reply

You are right. I am going to x it soon! 


educ8s.tv/ardu no-rotary-encoder-menu/ 9/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

aboodys April 9, 2017 at 1:33 am - Reply

sir the link is broken. Thx

Nick April 9, 2017 at 8:37 am - Reply

Yes, I am going to x it soon!

aboodys April 10, 2017 at 7:46 pm - Reply

Thx a lot , please do it very soon.

Nick April 10, 2017 at 10:06 pm - Reply

Done

arducomp April 9, 2017 at 6:33 am - Reply

Dear friend Nick, sorry to inform you that you’ve forgotten top put the link to your Arduino code.

Nick April 9, 2017 at 8:36 am - Reply

You are right! I am going to upload it soon!

William April 12, 2017 at 8:59 pm - Reply

If you don’t already know it the code link has been xed and the sketch is now available. It works
great too! 
educ8s.tv/ardu no-rotary-encoder-menu/ 10/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

Helcio May 5, 2017 at 11:11 pm - Reply

I really appreciate the code, and the effort to share it in details!


I would like to ask you, about more simple code, with three option menu line, instead six.
Example: voltage, current and power ( Watts ).
Another question, how can I place some useful information from the ADC on the LCD?
Thank you,
Helcio

shashank shivhare March 30, 2018 at 11:09 am - Reply

wonderful code sir can you please help with it.I want to make list within list.i.e. i want to display
[EN ES EL ] in list form.All these three should be in one frame inside menu item.
Thank you sir.Hope to get reply soon
SHASHANK

Arkey June 5, 2018 at 9:54 pm - Reply

Thank you!!! for sharing, what a nice project. I thinking introduce it to my project.
I have a question, how I can get some extra option:

1. How to setting hierarchy menu, eg. rst start “welcome” page after second page where can be
showing for eg.. visualization signal and if encoder is touch or click then start menu?
2. If no activity by 10sec. in menu, automatically go back to page with visualization?

I need just to know how to set up behavior menu.


Thank you

David June 14, 2018 at 2:42 am - Reply

I’ll second Arkey comment. And how do you move the pins for the display, or assign them for
use in a Nano with less than 13 pins? I didn’t see anything in the sketch for pins 11 and 13,
I’m assuming This Adafruit_PCD8544( 5, 4, 3) and this pinMode(7,OUTPUT) can be changed
to change those wires locations, but stumped on pins 11 and 13.

David June 14, 2018 at 3:28 am - Reply 


educ8s.tv/ardu no-rotary-encoder-menu/ 11/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

Got the pins…. 11 and 13 are MISO and SCK, so they go to D12 and D13 on Nano.

Arkey July 28, 2018 at 5:29 pm - Reply

Yeah! I rewrite it for oled 0.96 128×64 display + own startup logo and welcome text. Moreover I
rewrite from beginning encoder and button. Now I didn’t need lib ClickEncoder and TomerOne and
all working without problem and faster than original. My version had more options for button and
encoder can be easy con gurable in range -999 to 999 , can be setting just from 0-127 or
anywhere as you like in main range. Also I added setup initial encoder value. Will be some more
options. I will report here my progress and if someone wants get my code, I put it on GitHub if
nished. Now mentioned option working nice without any problems.

ad April 4, 2019 at 2:42 pm - Reply

I’m looking for this! Can you tell me how you achieved this?

Arkey July 28, 2018 at 5:33 pm - Reply

Just I forgot, my project is for Teensy 3,2 but should be easy adaptatable for Arduino

Tim August 2, 2018 at 4:38 am - Reply

That is amazing! i was wordering if it would be possible to port this menu to different
displays..
I want it to work on a teensy 3.6 with a Teensyview (oled 128×32) or a Adafruit ssd1306
(oled 128×64) So i am really curios how you did it…

gvg August 30, 2018 at 6:40 pm - Reply

Hi. This is a great project. What is the purpose of String dif culty variables?

ad April 4, 2019 at 2:41 pm - Reply

Is it possible to use this on a SSD1306 I2C OLED display? How to achieve this?

educ8s.tv/ardu no-rotary-encoder-menu/ 12/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld
David May 16, 2019 at 4:54 pm - Reply

I just want to give you some hopefully constructive criticism.


The rst thing that I do when I downloads someone else’s code in order to learn from it is to go
through it and edit the whole code so that it follows my preferred coding style, personally I prefer
this:
if()
{
action();
}

as opposed to this(which I nd to be much more unclear to read when there is a lot of if’s and else
if’s):
if(){
action();
}

My criticism is about how you haven’t chosen a style but instead alternates between them, this
might to some seem like a trivial and unimportant subject but I really do believe that the person
whom chooses a particular style bene ts from it but particularly in case a person is sharing
he’s/her’s code with others then it makes the reading of the code much more pleasant if the code
adheres to one coding style instead of two, it also minimizes the chance of errors on part of the
reader.

I haven’t even begun yet to get to grips with your code so this is thus far all I wanted to say, thanks
for sharing.

Regards
David

Nick May 17, 2019 at 8:05 am - Reply

Hello David, thanks for the comment. You are right. Clean code and readable code is very
important indeed. I try hard to write clean code, and I will continue to improve as time goes
by. Thanks again.

Janos May 19, 2019 at 10:13 pm - Reply

Sorry Sir but your program is full with mistakes..


The Arduino can not translate it and it can not run..
I modi ed it but I think I have to check it from the rst alphabet to the last..

educ8s.tv/ardu no-rotary-encoder-menu/ 13/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

Regards1
Janos

Duane Jardine June 29, 2019 at 1:19 am - Reply

Where in the code can I re-assign the pin4 D11 and the pin5 D13 to pin6 > D11 and pin7 >
D13?

Duane July 12, 2019 at 11:17 pm - Reply

Hi, many thanks for your video’s and projects they have been very helpful. I was wondering with
this project I want to use two NRF24L01 modules for control on the other Arduino. How would this
data in the menus be put into a data pipe to be sent across and then interpreted on the receiver
side? I have watched your other tutorial on the NRF24L01 modules but I am battling on how to
change the code for this project. If you could please help I would really appreciate it.

Leave A Comment

Comment...

Name (required) Email (required) Website

Save my name, email, and website in this browser for the next time I comment. 
educ8s.tv/ardu no-rotary-encoder-menu/ 14/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

POST COMMENT

This site uses Akismet to reduce spam. Learn how your comment data is processed.

NICK KOUMARIS RECENT POSTS RECENT TWEETS POPULAR TOPICS

 Sipeed M1 Dock Review AI Arduino Arduino 101


Tweets by @educ8s
I'm extremely passionate about  Arduino ST7920 Tutorial Arduino Game Arduino Project
electronics, making things and educ8s.tv
design. I love teaching what I know  OpenMV Screen ST7735 Tutorial
@educ8s Arduino tutorial Art Deco
and sharing my experiences with Check this out. It seems that
you. I put out new YouTube videos @sirajraval used AI to plagiarize the
Arti cial Intelligence Bluetooth
 Pixy 2 Machine Vision Module
every week as well as updating this Neural Qubit paper. He admitted on a
Button Color TFT Display
site with free tutorials. Be sure to live stream of the paid course that he is
 Pixy2 Cam – Machine Vision
sign up for my newsletter to be using the QuillBot AI service (which
DS18B20 DS3231 e-paper
made easy
noti ed of new content! paraphrases an input text) and he has a
paid subscription to it, see the attached ESP32 ESP8266 GPS GSM
screenshot.
GSM Shield ILI9341 LCD

educ8s.tv/ardu no-rotary-encoder-menu/ 15/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld

Low Power Machine Vision

Nextion Nokia 5110 OLED

OpenMV Python Raspberry Pi

Oct 24, 2019 Robot RTC SMS ST7735

TEA5767 TFT TFT display


educ8s.tv
@educ8s Thermometer Touch Screen
Γίνε #πλούσιος απαντώντας σωστά σε
16 ερωτήσεις γενικών γνώσεων. Είναι Tutorial Weather Station
εύκολο!
play.google.com/store/apps/det… Wemos WeMOS D1

Wemos D1 mini Xiaomi

Oct 16, 2019

educ8s.tv
@educ8s

The fastest machine vision board for


makers is here and it costs less than
$30! Check the detailed review I
prepared! It is the most exciting board I
have seen for some
time.youtube.com/watch?v=rASfmI…

Sep 24, 2019

Embed View on Twitter


educ8s.tv/ardu no-rotary-encoder-menu/ 16/17
26.04.2020 Ardu no Rotary Encoder Menu - educ8s.tv - Watch Learn Bu ld
Copyright 2015 educ8s.tv| All Rights Reserved     


educ8s.tv/ardu no-rotary-encoder-menu/ 17/17

You might also like