/*
PWM Motor Test
pwm_motortest.ino
Uses LCD Keypad module
Modified from Cytron example code
DroneBot Workshop 2019
https://dronebotworkshop.com
*/
// Include libraries for LCD Display
#include <LiquidCrystal.h>
#include <LCD_Key.h>
// Define keycodes
#define None 0
#define Select 1
#define Left 2
#define Up 3
#define Down 4
#define Right 5
// Pin for analog keypad
#define diy_pwm A0
// PWM output pin
#define pwm 3
// Motor direction pin
#define dir 2
// Define LCD display connections
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Setup LCD Keypad object
LCD_Key keypad;
// Variable to represent PWM value
int pwm_value = 0;
// Variable to represent Keypad value
int localKey;
void setup(){
// Setup LCD
lcd.begin(16, 2);
lcd.clear();
// Define Pins
pinMode(pwm,OUTPUT);
pinMode(dir,OUTPUT);
}
void loop()
{
while(1)
{
// Scan keypad to determine which button was pressed
localKey = keypad.getKey();
// Toggle motor direction if LEFT button pressed
if(localKey==Left){
digitalWrite(dir,!digitalRead(dir));
delay(200);}
// Increase motor speed if UP button pressed
if(localKey==Up){
pwm_value++;
delay(200);
lcd.clear();}
// Decrease motor speed if DOWN button pressed
else if(localKey==Down){
pwm_value--;
delay(200);
lcd.clear();}
// Ensure PWM value ranges from 0 to 255
if(pwm_value>255)
pwm_value= 255;
else if(pwm_value<0)
pwm_value= 0;
// Send PWM to output pin
analogWrite(pwm,pwm_value);
// Display results on LCD
lcd.setCursor(0,0);
lcd.print("PWM:");
lcd.print(pwm_value);
lcd.setCursor(0,1);
lcd.print("DIR:");
lcd.print(digitalRead(dir));
}
}
Electronics are:
Arduino UNO
DFROBOT LCD Shield 1.1
Cytron MDD10A
It seems that I can't get to work no matter what I do. Whenever I push the buttons on the LCD shield, nothing happens. What am I doing wrong? Does anyone have any ideas?
I was just hoping that maybe someone saw an obvious error in code or the circuit, that maybe they could help me.
Obviously people shouldn't believe everything that's on the internet. I'm not too sure how your comment helps though. Are you just trying to be rude to me for no reason?
Are you just trying to be rude to me for no reason?
Just pulling your leg.
OK, it seems you did get that spurious code from the video, not the reference in #3. Suffice to say that is speaks poorly of the competence of the presenter in the video.
I have never done anything like this before, as I'm beyond new. So it's hard for me to vet content on the internet.
I might as well just say what I'm trying to do. I need to gradually increase the speed of the 775 DC motor I'm using, and I wanted to utilize the keypad to do that.
The goal is to find the correct speeds I need for different applications, and then create a program that initiates those exact speeds.
The first step in my mind was doing the initial step of testing speeds using the keypad, but I don't really know how to do that other than what I saw on that video.
No, the LCD lights up and displays the words "PWM", "DIR", but when I push the buttons to increase the speed of the motor, nothing displays on the LCD and the DC motor doesn't initiate.
I'm using a 775 DC motor that I got off Amazon:
shorturl.at/bkyP4
I'm powering the MDD10A using a DeWalt 20v battery.
Have you tried to example code that came with the libary as I pointed out in reply #3? It will report when a button is pressed. You could also put a Serial.print() statement in multiple places to report the button press as well.
If you are seeing the words "PWM" and "DIR" on the display you surely are seeing values right after them as well?
It could likely be that your power supply is not sufficient to power your motor
I'm going to use the sample code this afternoon when I have some time to troubleshoot.
That's what's odd, there are just the words "PWM" and "DIR", but no values after those words appear when a button is pressed.
There is a test button on the MDD10A, and when I push it the DC motor starts, so I know the battery can power the DC motor.
It's as though there is a disconnect between the LCD shield and the MDD10A, which is either due to code or the circuit itself. I'll try the test code after though!
Clearly, a picture is worth 1000 words. Your video shows the contents of the screen as "PWM:0" and "DIR:0" which is NOT the same as your previous description.
Also, it appears that you do not have the battery negative connected to the arduino ground, All of your grounds need to be tied together so there is a common reference for "0V".
You can also put in some Serial.print() statements to announce your key presses on the Serial Monitor to help debugging