Introduction: Motor + LCD + Arduino: Motor Speed Controller With Speed Display
Hello World!
It's Unicorn Clockworks back at it again with another project for makers! Here, we will make a motor driver with a variable speed controller and speed display using the LCD screen. This can be used when you want to monitor and control the speed of the wheels of your robots.
It's also transferrable to other micro controllers that have an Arduino core compatibility like the ESP8266 and NodeMCU.
Step 1: Materials
- Arduino or Arduino compatible micro controller
- DC Motor
- LCD Screen
- 2 Potentiometer
- NPN Transistor
- 100Ω Resistor
- Diode
- Jumper Wires
- Breadboard (or Perf Board + Solder)
Step 2: LCD Connections
You can follow the steps on how to connect the LCD from my last posthere: https://www.instructables.com/id/Temp-1/
The connections are labeled in the picture and the wires corresponding to the images are noted below.
1a
- Connect the Brown wire (pin 16) to the GND pin on the Arduino
- Connect the Red wire (pin 15) to the 3.3V VCC pin on the Arduino
- Connect the Orange, Yellow, Green, Blue (pins 14-11) to pins 2 to 5 on the Arduino
2
- Connect the White wire (pin 1 on the LCD) to the common ground (pin 16)
- Connect the Grey wire (pin 2 on the LCD) to the common VCC source (pin 15)
- Connect the Purple wire to the signal pin of the potentiometer (pin 2 on the potentiometer)
3
- Connect the Purple wire (pin 1 on the potentiometer) to the common ground (pin 16)
- Connect the Grey wire (pin 3 on the potentiometer) to the common VCC source (pin 15)
4
- Connect the Yellow wire (pin 4 on the LCD) to pin 12 on the Arduino
- Connect the Black wire (pin 5 on the LCD) to the common ground (pin 1 on the potentiometer or pin 16 on the LCD, either works)
- Connect the Green wire (pin 6 on the LCD) to pin 11 on the Arduino
Step 3: Motor Connections
5
- Connect the emitter pin of the transistor to the positive pin of the diode
- Connect the collector pin of the transistor to a common VCC source (pin 1 or pin 16 of the LCD)
- Connect the negative terminal of the diode to 5V on the Arduino.
6a
- Connect the base of the transistor to a 100Ω resistor
- Connect this Yellow wire from the free end of the resistor to pin 9 on the Arduino
7
- Connect the Red wire from one of the motor pins to the negative terminal of the diode
- Connect the Black wire from the other motor pin to the positive terminal of the diode.
8: Connecting another potentiometer
- Connect the Black wire (pin 1 on the potentiometer) to the common ground (pin 16, pin 1, or GND on Arduino)
- Connect the Orange wire (pin 3 on the potentiometer) to the common VCC source (pin 15)
- Connect the Blue wire (signal pin of the potentiometer -- pin 2) to pin A0 on the Arduino.
Step 4: Coding
// built in arduino library<br>#include <liquidcrystal.h> LiquidCrystal lcd(12,11,5,4,3,2);</liquidcrystal.h>
const int motorPin = 9;
void setup() { pinMode (motorPin, OUTPUT); // make pin 9 an output pin lcd.begin(16, 2); // clear old screen data lcd.clear(); // text to be dispalyed on the screen lcd.print("UnicornClockworks"); }
void loop() {
lcd.begin(16, 2); // clear old screen data lcd.clear(); // text to be dispalyed on the screen lcd.print("UnicornClockworks"); int speed = map(analogRead(A0), 0, 1024, 0, 255); // map the potentiometer to the range of the motor speed analogWrite (motorPin, speed); int voltage = speed/255*4.5; float motorSpeed = voltage*140/4.5; // calculating motor speed, 140 rpm for 4.5V // (column 0) of the second line (line 1): lcd.setCursor(0,1); lcd.print ("Speed is:");
char myStg[10]; sprintf(myStg, "%d", motorSpeed); for(int i=0; i<strlen(mystg); i++)="" ="" {="" lcd.print(mystg[i]);="" } <="" p=""></strlen(mystg);>
lcd.setCursor (13,1); lcd.print ("RPM");
delay(100); }
Step 5: It Works!
Upload the code and control the speed by rotating the potentiometer knob.
Have fun making this project!
Unicorn Clockworks Out!

Participated in the
Makerspace Contest 2017
13 Comments
1 year ago
the code is not working at all
Question 5 years ago on Step 4
Arduino:1.8.5 (Windows 10), Kort:"Arduino Nano, ATmega328P"
Build options changed, rebuilding all
C:\Users\robin\Documents\Arduino\vibrator_matare\vibrator_matare.ino:2:45: fatal error: liquidcrystal.h: No such file or directory
#include
^
compilation terminated.
exit status 1
Error compiling for board Arduino Nano.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Answer 1 year ago
install the library first and then change the spelling to have a capital L and a capital C
the library can be found under the Tools and then Manage Libraries.
#include <LiquidCrystal.h>
Question 5 years ago on Step 4
code is showing error while compiling what to do?
the error is:
C:\Users\prashant\Desktop\first\first.ino:1:27: fatal error: liquidcrystal.h: No such file or directory
#include
^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
Answer 1 year ago
install the library first and then change the spelling to have a capital L and a capital C
the library can be found under the Tools and then Manage Libraries.
#include <LiquidCrystal.h>
Answer 5 years ago
use #include
Question 4 years ago on Step 4
ERROR: 'mystg' was not declared in this scope
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
const int motorPin = 9;
void setup()
{
pinMode (motorPin, OUTPUT); // make pin 9 an output pin
lcd.begin(16, 2);
// clear old screen data
lcd.clear();
// text to be dispalyed on the screen
lcd.print("UnicornClockworks");
}
void loop()
{
lcd.begin(16, 2);
// clear old screen data
lcd.clear();
// text to be dispalyed on the screen
lcd.print("UnicornClockworks");
int speed = map(analogRead(A0), 0, 1024, 0, 255); // map the potentiometer to the range of the motor speed
analogWrite (motorPin, speed);
int voltage = speed/255*4.5;
float motorSpeed = voltage*140/4.5; // calculating motor speed, 140 rpm for 4.5V
// (column 0) of the second line (line 1):
lcd.setCursor(0,1);
lcd.print ("Speed is:");
char myStg[10];
sprintf(myStg, "%d", motorSpeed);
for(int i=0; i<strlen(mystg); i++)
{
Lcd.print(mystg[i]);
}
lcd.setCursor (13,1);
lcd.print ("RPM");
delay(100);
}
Answer 1 year ago
Try capitalizing the S
myStg
3 years ago
Somethings wrong with the code its not working
shows mystg not declared
Reply 1 year ago
Try capitalizing the S
myStg
3 years ago
did connections as it is, LCD Shows light, But no output at all. even the motor doesnt move at all.
3 years ago on Step 4
Nice tutorial. Can this be done for stepper motor? I am looking to control stepper motor speed with potentiometer and need stepper motor speed(rpm) displayed on lcd.
Question 4 years ago
can i use 12 volt dc motor ?