Trying to read current using ACS712 attached to a relay

Hello Everyone,

I am trying to read the current value of my linear actuator. I am using 12V relays to make the actuator go back and forth. I have the ACS712 attached in series with the actuator and the relay.
Here is a link to how I have it setup:

Problem is, the current reading show no increase when the actuator is in motion(I have attached a 5kg weight to it so some force is exerted on the motor). Not only this, the reading should range from +ve to -ve , depending on the direction. There is never a -ve value shown and the current remains constant no matter what I do.

This was not an issue when I was running the actuators usings the L298D motor driver and had attached the ACS712 to it in a similar manner. With the L298, it was showing proper values.

I am not sure whats going on. The actuator goes back and forth using the relay. Shouldn’t the current sensor give +ve and -ve values for it as well?

Any pointers would greatly help!

Best regards,
Uber

Here is a link to how I have it setup:

No, this is a link to a setup that acted as a template for your setup. In the linked setup there is no current sensor integrated. So please post a wiring diagram of your setup.

Problem is, the current reading show no increase when the actuator is in motion(I have attached a 5kg weight to it so some force is exerted on the motor). Not only this, the reading should range from +ve to -ve , depending on the direction. There is never a -ve value shown and the current remains constant no matter what I do.

So you have the same current measured when the relays are all off or when one of them is turned on? In this case the wiring is probably wrong.

I am not sure whats going on. The actuator goes back and forth using the relay. Shouldn't the current sensor give +ve and -ve values for it as well?

This depends on how you show the measured value (you didn't provide your code so we are forced to guess). If you connect the output of the ACS712 to an analog input of the Arduino you only read positive values from analogRead().

Thanks for the quick reply!

I have attached a picture of my circuit(sorry its hard to see the wires).

So the actuator is attached exactly the way its shown in the example setup link I posted earlier. Only difference is, I have the current sensor in series.

So sorry, about the wire mess.

Also, the ACS712 absolutely does give a +ve or -ve reading depending on which direction im moving the actuator. I know this by looking at the data sheet of the sensor and also practically testing the same config with the L298D motor driver.

here is the code:

#include <Wire.h>

const int analogIn = A0;
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500; 
double Voltage = 0;
double Amps = 0;
int actuatorRuntime=0;
char messageType;

const int forwards = 7;
const int backwards = 8;



void setup() {

Serial.begin(9600);
pinMode(forwards, OUTPUT);//set relay as an output
pinMode(backwards, OUTPUT);//set relay as an output
            
}

void loop() {
 
                 RawValue = analogRead(analogIn);
                 Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
                 Amps = ((Voltage - ACSoffset) / mVperAmp);      
                 
                 digitalWrite(backwards, HIGH);
                 digitalWrite(forwards, LOW);//start forward motion
                 delay(1000);

               /* digitalWrite(forwards, HIGH);
                digitalWrite(backwards, LOW);//start backwards motion
                delay(30000);  */

         
}

Why do you include Wire.h?

You don't print out your value so how do you know it doesn't change?

With that sketch is shouldn't change as the direction is always the same.

What values do you get?

Hey sorry. I forgot to put in the print statement in the posted code(I do have print statement in my code though)

My overall code is way too long. Wire.h is used for a different purpose, so just ignore that.

I am testing this one direction at a time. If you notice, I have the other direction commented out.

I just get a constant reading between 0.3 to 0.9 amps when its idol and also while its running…

Perhaps a better question to ask would be, how should I be wiring this if I want to read the current?
I’d imagine the actuator wouldn’t work at all, or worst yet, short something if I had wired this incorrectly. Is that a reasonable assumption?

I just realized i should explain a little bit more about the code...

So I am sending the command to run the actuator in a direction from an UNO and then reading the current on a Nano. So what I posted before, please consider it as psuedo code. I am doing this because I realized that you cant read the current and run the actuator at the same time using a delay...

The uno is the one that actually tells the actuator to move either back or forth, the nano just constantly monitors the output of the ACS712 sensor.

I am not a 100% sure, but I think I realized my mistake.

This is a 12V relay and I am using an external 12v power supply for it. The +ve of the power supply is connected to the JD-VCC of the relay and the -ve is connected to the ground. I may be need to connect 2 separate current sensors in series from each one of those ports.

Thoughts?

Please post a wiring diagram (may be hand drawn) as I cannot see the connections on the photos. And please post the code you’re experimenting with. Remove the code that does other stuff, just use the relevant code for this problem. Once you have solved it you can still re-include the other parts.

I don’t think that the 12V should impose a problem but I have to see the wiring diagram first.