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!