2

A DC motor is operated using an L298n driver and Arduino UNO. How can I get to know whether the Motor is ON or OFF? Using a code in Arduino.

4
  • You control the motor via the Arduino. Thus you already know if it is on or not. Or do you want to find out, whether it actually turns? – chrisl Nov 11 '20 at 11:54
  • There's nothing on the L298N that returns that status there's nothing you can read. So you have to assume if your code correctly sets the enable pin that the motor is running. – Dougie Nov 11 '20 at 11:56
  • 1
    Like @chrisl said. If you're trying to detect a stall condition, you can put that into the question. – timemage Nov 11 '20 at 13:26
  • 1
    use a sensor to detect the motor shaft rotation – jsotola Nov 11 '20 at 17:38
1

Unfortunately, the L298N does not return a status, so you are going to have to add sensors to detect motor movement.

Here are a few options you can try:

  • Current sense. Add a small resistor to the output of the L298N and measure the voltage differential across that resistor. If there is current being supplied to the motor then you will have a voltage differential.
  • Rotation sensor. This can be in the form of a quadrature encoder wheel, tooth sensor or Hall effect sensor detecting a magnet on the shaft. If you see pulses from the sensor then you know the motor is spinning.
  • Optical sensor. A camera system or other optical sensor to detect motor movement. Probably too complex for a simple application. There are however off the shelf sensors that will turn on an output if they see movement in their field of view. Alternatively you could use a PIR sensor from a home alarm system if the movement is course enough.
0

This may be too simple, but for completeness: You can read back the state of the output bit, in case your code doesn't save its current state. That will tell you if the motor is literally "on" or "off". Not rotating despite being "on" is another matter; an error.

If you need error detection then you need additional hardware support. Some possibilities:

  • Sense rotation with a cam and a micro-switch or an optical sensor and a slotted disk;
  • Sense the motor current - a stalled motor will draw a high current;
  • Sense vibration in the motor platform;
  • (apply imagination here... ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.