Controlling DC Water pump from browser using Arduino uno

We have seen how to control servo angle from browser using esp32 here. In this post we will learn how to control DC motor speed/DC Water pump from browser using arduino uno.

What you need

  • Arduino IDE
  • Arduino UNO
  • DC motor or DC water pump
  • L298N motor driver breakout board

L298N is a Dual Full bridge (H-bridge) driver. We can control both direction and speed (PWM control) of the DC motor with this driver.

L298N pin diagram


Connections

Vs is motor supply voltage and Vss is logic voltage. Since arduino uno uses 5v we can connect 5v to Vss (some breakout boards come with internal 5v regulators, if your breakout has this, then leave this unconnected). Connect both motor supply ground and arduino supply ground together.

Connect motor + terminal to OUTPUT 1 (A+) and – terminal to OUTPUT2 (A-). We will only be controlling the speed in forward direction.

Connect arduino pin 5,6 to INPUT 1 and INPUT2.

Connect arduino pin 3 to EN A ( remove if there are any jumpers in the breakout on this pin)

L298N motor driver connections to arduino uno


Code

In the setup block set all the pin direction to output and put the motor in forward direction with default speed.

In loop block, monitor for serial commands. If a command is available parse it and scale it to the analogwrite range. The slider produces values between 0-180, we need to scale it to 0-255 which is the analogwrite range.


Sending serial commands

The command is a newline terminated, colon prefixed slider position.

:{slider_position}\n

To test the code, load the sketch and open serial monitor. Send :180 from the serial monitor (you need to select newline terminating character). Motor will run at full speed.

Alternatively you can send command using following widget. Connect UNO to computer and click on open button, then select the appropriate COM port from the presented list. Then move the slider to change the speed of the motor ( you need to close the arduino serial monitor before trying connect from the browser )

Add a Comment

Your email address will not be published. Required fields are marked *