Is there a way to check if a Motor is connected with Arduino? (Check the circuit

Hello everybody! :slight_smile:
I have a single DC motor that is connected and working with this simple code:

int motorPin = 3;

void setup() {

}

void loop() {
   digitalWrite(motorPin, HIGH);
}

Sometimes wire is disconected by mistake.

Let’s say (for educational reasons) that I don’t focus on the motor’s connection…
I want to know if there is a method to check if the motor is still wired or not and get a response to Arduino.
Is that possible?
(I searched but didn’t find anything relevant or don’t know how to search)

Thanks in advance,
Bobby

Solder or crimp your wires ;).

charavge83: I want to know if there is a method to check if the motor is still wired or not and get a response to Arduino.

There is no simple way.

First of all, the Arduino is not connected to the motor, only to the motor driver. Second, the communication from the Arduino to the motor driver is one way.

You could put a rotary encoder on the motor shaft and the Arduino could monitor the pulses from the motor but that would not tell you if the motor is disconnected at a time when the motor is intended to be stationary.

Or you could monitor the current flowing into the motor but that would have the same logical weakness.

As @larryd said, just make robust connections.

...R

Robin2: There is no simple way.

First of all, the Arduino is not connected to the motor, only to the motor driver. Second, the communication from the Arduino to the motor driver is one way.

You could put a rotary encoder on the motor shaft and the Arduino could monitor the pulses from the motor but that would not tell you if the motor is disconnected at a time when the motor is intended to be stationary.

Or you could monitor the current flowing into the motor but that would have the same logical weakness.

As @larryd said, just make robust connections.

...R

Well, I don't really care about the motor's connection. I am sorry I didn't clarify that. It is more a practical problem. How do you check a circuit if it is closed? Isn't there a method for this?

I will give another example. Suppose I have 2 motors but I don't know which one is connected: Motor A or Motor B. How can I find which one is connected? Is there a method for that? That is what i am looking for. (I use motors because it is simple circuit).

“ How do you check a circuit if it is closed?”

The above is not easily deciphered.

If you mean can you read an output pin on the Arduino to see if it is HIGH or LOW, yes you can.

pinLevel = digitalRead(myOutputPin);


“ How can I find which one is connected?”

You can also set a variable when you turn ‘ON’ the motor, reset the variable when you turn ‘OFF’ the motor; examining this variable yields your answer.

charavge83: Well, I don't really care about the motor's connection. I am sorry I didn't clarify that. It is more a practical problem. How do you check a circuit if it is closed? Isn't there a method for this?

I don't know what you have in mind.

If this has nothing to do with a motor, why did you mention a motor in your Original Post?

If you provide an overall description the project you are trying to create it will be much easier to give useful advice. At the moment this is a typical XY problem.

...R

Sorry, it seems difficult to explain something so simple in my mind. Sorry for maybe misleading explanation.

I do have a motor.
The code (from circuit.io) is this:

// Include Libraries
#include "Arduino.h"
#include "DCMotor.h"


// Pin Definitions
#define DCMOTOR_PIN_COIL1	5



// Global variables and defines

// object initialization
DCMotor dcMotor(DCMOTOR_PIN_COIL1);


void setup() 
{
    
}

void loop() 
{
    
    dcMotor.on(200);                        // 1. turns on
    delay(4000);                             // 2. waits 4000 milliseconds (4 sec). change the value in the brackets (4000) for a longer or shorter delay.
    dcMotor.off();                       // 3. turns off
    delay(4000);                             // 4. waits 4000 milliseconds (4 sec). change the value in the brackets (4000) for a longer or shorter delay.
}

So. This is my Motor. I want CODE to do the following:

  1. Check if Motor Available
    2 If Motor Available: Run Motor
  2. If Motor NOT Availalbe: Print Error

So we take as granted that everything is working well!
But maybe in time there is some damage in wires (for example) or a disconnection in power wire.

In step 1 I want to check if there is any wiring damage and Motor is not responding.

My question is “How can I do this check?”. In case some wires are damaged how can I know it (without physical presence)? Just from coding or maybe with some extra wiring.
I hope this time it is more helpfull.

charavge83: My question is "How can I do this check?". In case some wires are damaged how can I know it (without physical presence)? Just from coding or maybe with some extra wiring. I hope this time it is more helpfull.

Have you considered carefully what I said in Reply #2?

You still have not described the complete project - you are just talking a small piece of it.

Unless it has some peculiar characteristics that you have not told us the wiring will be a very reliable part of the project if it is done correctly. What are the sorts of things that, in your mind, might cause it to fail?

...R

Put a current sensor between motor power supply and motor controller, apply a short pulse to the controller start pin, not long enough to move the motor if connected. At the same time, test for a current pulse. If current pulse detected, motor is connected, start it. If not, error.

JCA34F: Put a current sensor between motor power supply and motor controller, apply a short pulse to the controller start pin, not long enough to move the motor if connected. At the same time, test for a current pulse. If current pulse detected, motor is connected, start it. If not, error.

Thank you. I think this might be the answer I was looking. I will try it.

Robin2: Have you considered carefully what I said in Reply #2?

You still have not described the complete project - you are just talking a small piece of it.

Unless it has some peculiar characteristics that you have not told us the wiring will be a very reliable part of the project if it is done correctly. What are the sorts of things that, in your mind, might cause it to fail?

...R

Hello Robin. No there is nothing more to say about the project. The project itself is to find a way to check this I described. I was thinking that in case I want to make a circuit (i.e. an IoT application) where you don't need physical presence there might be something wrong so you must have a way to check some things from distance. I think this is a good example to check if a simple circuit is OK or not.

Yes I read the answer but only now I saw the line you describe: "Or you could monitor the current flowing into the motor but that would have the same logical weakness." So I guess you would also recoomend such as JCA34F, using a current sensor to monitor the current flowing.

I am now watching some tutorials to check how I can use it.

Sounds a bit like a useless box to me. :)

I don't know how this ever worked without declaring the mode of the GPIO.

Add this to the void setup.

void setup(){
pinMode(motorPin,OUTPUT);
}

@rah1775; I would think this call to the DCMotor library would do it.

// object initialization
DCMotor dcMotor(DCMOTOR_PIN_COIL1);

charavge83:
So I guess you would also recoomend such as JCA34F, using a current sensor to monitor the current flowing.

That might be a solution.

Personally I don’t think the risk of failure of a properly made connection to a motor is high enough to be worth the trouble of monitoring it.

What are you going to do if the motor works fine but your monitoring system fails?

…R