Application of Timer in Brushed DC Motor Control using Arduino

Hi there I am new to arduino and proteus, we're working on a project using Arduino to control a DC motor with timers. We're having some trouble designing the circuit schematic in Proteus. My problem is there is no feedback on the lcd. Please hellp me

I using this coe:
#include <LiquidCrystal.h> // Include LCD library

// Define pins
const int motorPin = 9;
const int potentiometerPin = A0; // Assuming a potentiometer for speed control
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // LCD pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int speed = 100; // Initial speed
unsigned long startTime = 0;
const int timerInterval = 1000; // milliseconds

void setup() {
pinMode(motorPin, OUTPUT);
lcd.begin(16, 2); // Initialize LCD
Serial.begin(9600); // Optional for debugging
}

void loop() {
// Read potentiometer value for speed control
int potValue = analogRead(potentiometerPin);
speed = map(potValue, 0, 1023, 0, 255); // Map potentiometer value to PWM range

unsigned long currentTime = millis();
if (currentTime - startTime >= timerInterval) {
startTime = currentTime;

// Update motor speed
analogWrite(motorPin, speed);

// Display motor speed on LCD
lcd.clear();
lcd.print("Motor Speed: ");
lcd.print(speed);

}
}

  • Does the IDE example LCD sketch work ?

  • You can draw a simple schematic on paper for us to review.

  • Good images of the actual circuit wiring is a must see.

  • Use code tags when adding a sketch to your posts.

I work on the LCD and Potentio first and heres the result. The potentio is not adjusting.

The code:
#include <LiquidCrystal.h>

// Define LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // RS, E, D4, D5, D6, D7

void setup() {
lcd.begin(20, 4);
lcd.setCursor(0,0);
lcd.print("Motor Control");
lcd.setCursor(0,1);
lcd.print(" Application of");
lcd.setCursor(0,2);
lcd.print(" Timers");
}

void loop() {
lcd.setCursor(0,3);
lcd.print("POT: ");
int timer = analogRead(A0);
lcd.print(timer);
}

Hi @aojos ,

please follow the advice of @LarryD and copy your code between code tags

image

it makes reading and copying code much easier.

The (formatted) result looks like this

#include <LiquidCrystal.h>

// Define LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // RS, E, D4, D5, D6, D7

void setup() {
  lcd.begin(20, 4);
  lcd.setCursor(0, 0);
  lcd.print("Motor Control");
  lcd.setCursor(0, 1);
  lcd.print(" Application of");
  lcd.setCursor(0, 2);
  lcd.print(" Timers");
}

void loop() {
  lcd.setCursor(0, 3);
  lcd.print("POT: ");
  int timer = analogRead(A0);
  lcd.print(timer);
}

I ported your code to Wokwi and it works there (just with a small flaw; the data line is not cleared so that you'll find remainders of past measurements):
See https://wokwi.com/projects/391958617180107777

Here a sketch that has a simple way to remove old data before printing new ones:

Improved Printing
/*
  Forum: https://forum.arduino.cc/t/application-of-timer-in-brushed-dc-motor-control-using-arduino/1233664/3
  Wokwi: https://wokwi.com/projects/391958932731248641

*/

#include <LiquidCrystal.h>

// Define LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // RS, E, D4, D5, D6, D7

const byte potPin = A0;
int prevValue = -1;

void setup() {
  lcd.begin(20, 4);
  lcd.setCursor(0, 0);
  lcd.print("Motor Control");
  lcd.setCursor(0, 1);
  lcd.print(" Application of");
  lcd.setCursor(0, 2);
  lcd.print(" Timers");
}

void loop() {
  int value = analogRead(potPin);
  if (value != prevValue) {
    prevValue = value;
    lcd.setCursor(0, 3);
    lcd.print("POT:        ");
    lcd.setCursor(6, 3);
    lcd.print(value);
  }
}

to be tested on Wokwi https://wokwi.com/projects/391958932731248641

I also reconstructed your sketch from post #1 and copied it to Wokwi for testing:
https://wokwi.com/projects/391959385017752577
where it is working ... (I used an led instead of the motor)

There might be an issue with the wiring in proteus ...

Good luck!
ec2021

how about this sir, the problem on application of timers is this whitout any feedback from the motor it shows only 0. Here's the components that I used: 1. Arduino Uno
2. DC motor
3. Motor driver (L298)
4. LCD display (LM044L)
5. Potentiometer (for LCD contrast adjustment)
6. Pushbuttons (for controlling motor direction or speed)
7. Resistors and capacitors (as needed)

THE CODE:
#include <LiquidCrystal.h>

// Define LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Define motor control pins
const int motorPin1 = 9; // PWM pin for motor speed control
const int motorPin2 = 10; // Direction pin for motor control
const int buttonPin1 = 6; // Button pin for increasing speed
const int buttonPin2 = 7; // Button pin for decreasing speed

int motorSpeed = 0; // Motor speed (0 to 255)

void setup() {
// Set motor pins as output
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);

// Set button pins as input
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);

// Initialize LCD
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Motor Speed: ");
lcd.setCursor(0, 1);
lcd.print("0");
}

void loop() {
// Increase motor speed
if (digitalRead(buttonPin1) == LOW && motorSpeed < 255) {
motorSpeed++;
}

// Decrease motor speed
if (digitalRead(buttonPin2) == LOW && motorSpeed > 0) {
motorSpeed--;
}

// Update motor speed
analogWrite(motorPin1, motorSpeed);

// Display motor speed on LCD
lcd.setCursor(13, 0);
lcd.print(" "); // Clear previous speed
lcd.setCursor(13, 0);
lcd.print(motorSpeed);

delay(100); // Delay for button debouncing
}

Your topic does not seem to indicate a problem with IDE 1.x and therefore has been moved.

Please edit your posts that contain code, select all code and click the <CODE/> button; next save. It makes it easier to read, easier to copy and the forum software will display it properly.

Sorry, I was not at home for a couple of hours ... :wink:

Please put your code in code tags!

Press this button
image

and copy the code between the two lines that appear in the post editor:

image

Regarding your post #5:

  • Check the wiring of pins and buttons
    • 6 and 7 are supposed to connect to the buttons but are connected to the motor driver instead
    • The buttons are connected to pin 2 and 4 which in parallel are connected to Data5 and Data7 pin of the LCD

This way you only switch LCD data lines to GND but do not control the pins which are used to change the motorSpeed variable ...

See my post #4 "There might be an issue with the wiring in proteus" :wink:

See your sketch from post #5 on Wokwi: https://wokwi.com/projects/391986735398421505

If the wiring is ok, the sketch works as programmed ...

I suggest that you also have a look at the "improved printing" from post #4 . Once you understand the principle how to print only when necessary it might make things easier ...

ec2021

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.