I am in a need of help i have a project that consist of controlling a DC motor speed with a potentiometer and a L298D . I made it only that far, now i'm stuck to how to add a display that shows the speed . I have no idea how to write it's code nor how to wire it.
Do you mean the actual speed in rpm, or the value of your variable "motor_speed".
In either case you need to give details of your LCD: they aren't all the same, and imo the easiest to use is an I2C version. It's easy once you install the appropriate library and look at the library's examples of how to display a variable.
If you need the actual speed in rpm, that's more complicated and you will need a sensor like an encoder or a Hall effect sensor.
I am in a need of help i have a project that consist of controlling a DC motor speed with a potentiometer and a L298D . I made it only that far, now i'm stuck to how to add a display that shows the speed . I have no idea how to write it's code nor how to wire it. Can some one please write me the code?
The easiest way would be to just print the speed out to the Serial Monitor as a start. To do that, you need to use the Serial library. There are examples in the IDE.
After you accomplish that, you will need to connect some sort of display. The easiest are the displays that use the i2c protocol (two wire or TWI) which you can purchase and install very easily. They take care of driving all the pins required to control a display. You will use commands very similar to the Serial library to write to the display, just like writing to the serial monitor.
Your title does not let people know what you need help with. If you edit your Original Post you can change it. To my mind something like "Help to display RPM on a display" or "Help choose a display to show RPM" would be more suitable. - I'm not sure more accurately describes your need.
I am in a need of help i have a project that consist of controlling a DC motor speed with a potentiometer and a L298D . I made it only that far, now i'm stuck to how to add a display that shows the speed . I have no idea how to write it's code.Please i really need help.
The code:
// Arduino DC motor speed and direction control
#define button 8
#define pot 0
#define pwm1 9
#define pwm2 10
boolean motor_dir = 0;
int motor_speed;
void setup() {
pinMode(button, INPUT_PULLUP);
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
}
void loop() {
motor_speed = analogRead(pot) / 4;
if(motor_dir)
analogWrite(pwm1, motor_speed);
else
analogWrite(pwm2, motor_speed);
if(!digitalRead(button)){ // If direction button is pressed
while(!digitalRead(button)); // Wait until direction button released
motor_dir = !motor_dir; // Toggle direction variable
if(motor_dir)
digitalWrite(pwm2, 0);
else
digitalWrite(pwm1, 0);
}
}
Use the enable pin for PWM and connect IN1 and IN2 to digital outputs. Saves a PWM pin and you get nicer motor movement and less heat.
DON'T call something what it does on the Arduino, call it something useful like what you do with it. Aka, not 'pwm1' but 'motor_in1_pin' (or more common in the Arduino world: '. 'motorIn1Pin')
And once you start numbering variables, most of the time it's time to use arrays. Although here it's not to bad.
Use something smarter for the button with proper debounce etc. I like the Bounce2 library for that.
If you refer to an analog pin, use 'A0' instead of '0'. That way you can never confuse digital pin 0 and analog pin 0 with each other.
DON'T use macros (#define) for pins. Yes, a lot of tutorials do and yes, it works. But C++ (which the Arduino IDE uses) has a much nicer alternative and that's the 'const' keyword. In case something goes wrong, the compiler will output wayyyyyy more readable errors
[quote author=Coding Badly link=msg=3721750 date=1525680734]
You pretty much barfed all over the forum.[/quote]
Holy! Indeed!
@accountsays, I2C is just a bus, not a type of display. It's a bit like saying you drive petrol when we ask what car you drive. Post at least a link to the screen you bought.