Use the value from sensor to trigger Pin output

Hello,

I want to make an automatic load cut off when the load reach > 3A.

The load is 12V DC Motor. I have tested the current of the motor is in between 1A - 2A, when it's running normal load. The current is increasing when it gets heavy load. I don't want to burn the motor, so I want to set the maximum current load at 3A to stop running. I'm thinking to use arduino with Hall Current Sensor Module ACS712 30A module to control it.

Is it possible to do?

Thanks.

From a brief look at the details of that device it seems possible to do what you want.
Do you have a question on how to do it ?

Oh sound great...

Do you have a question on how to do it ?

Yes please... I just don't know how to make the programming.

I made a simple wiring diagram that. Please review it if it's right or wrong.

Thanks.

Wonderful picture!

From the hardware point of view it is basically correct (perhaps there are a free wheel diode and a a couple of resistors missing; nothing important for the moment).

A question and a hint:

Question: is it going to work on a bike or car?

Hint: I would start by doing a "subprogram" (i.e.: first reading the external switch to make the 13 pin diode to siwitch). Then another to open/close the realy and so on.

Would be great too having a scheme (sketch) of the hardware, but, for the moment, the (wonderful) picture does.

Regards

I just don't know how to make the programming.

Before you start on the actual project, work your way through the examples in the Arduino IDE and get comfortable with the programming environment, setting the mode of pins to read or write digitally and using the analogue inputs and PWM outputs.

Only then will you be ready to embark on your project.

@vffgaston

Wonderful picture!

From the hardware point of view it is basically correct (perhaps there are a free wheel diode and a a couple of resistors missing; nothing important for the moment).

Thank you!
It was just a quick wiring diagram for my self (actually) to keep my self on track of what I'm doing. Sorry I didn't put resistors and else on it. I'll make sure to draw more detail next time when I share it to others. Thank you for remain me this. :slight_smile:

Question: is it going to work on a bike or car?

I came up with this idea from "daily use car safety operation", such as automatic custom window shutter, motorized object, and so on. I don't want my kids or anyone else in my car gets injured by unexpected custom electrical operations of my custom car. So, safety first. :slight_smile:

For a bike, I don't know... it could be.. yes, if you create something that involving the electrical things and you want it safety uses.

I hope it gives you little idea for your project too.


@UKHeliBob

Before you start on the actual project, work your way through the examples in the Arduino IDE and get comfortable with the programming environment, setting the mode of pins to read or write digitally and using the analogue inputs and PWM outputs.

I'm familiar with arduino programming for basic environment as well as hardware basic for digital and analog pins.

So far, I made the sketch as below. It hasn't been tested yet, because I'm still waiting for my Hall Current Sensor Module ACS712 30A arrived. Also, I haven't tested the value of normal load and max heavy load operation of the motor by using the sensor. I should do that first, so I know what's the value of 3A in sensor readings (3A is the max heavy load to cut off), then set it in actual project as the maximum limit.

/*
Current Sensor Project
Target : Current Over Load Cut Off
Using Arduino ProMini and Hall Current Sensor Module ACS712 30A
*/

const int motor = 2; // Output Pin to trigger the motor
const int sensorPin = A0; // Input sense from Current Sensor
int btnSW = 3; // Input button switch
int sensorVal = 0; // variable to store the value coming from the sensor
int limitAmp = 700; // Don't know the exact value yet!!!

void setup(){
  pinMode(motor, OUTPUT);
  pinMode(btnSW, INPUT);
  Serial.begin(9600); // use the serial port
}

void loop(){
  sensorVal = analogRead(sensorPin);
  if(digitalRead(btnSW) == HIGH)
    if(sensorVal < limitAmp){
      digitalWrite(motor, HIGH);
    }
  else{
    if(sensorVal > limitAmp){
      digitalWrite(motor, LOW);
    }
  }
}

The sketch shows that the push button act as a trigger to Pin 2 (motor) to become HIGH, when the button is pressed once. The rest of the action leaves the A0 to decide either Pin 2 keeps HIGH or LOW, depend on the reading sensor. That's it.

Please advice.

Thank you.

That will make a lot of noise. Possibly smoke and flames too.

The logic starts out okay - if current > limit, then turn off the relay. But now what is the current? Zero! So it will immediately switch on again.

You will also find that the starting current for your DC motor is very high. You probably don't want the relay to trip every time it starts to move. Think about putting in a delay, so it only cuts the power if it has seen 3A consistently for more than 100ms.

And don't use the delay() function. Look at how the Blink_Without_Delay example works.

Thanks MorganS,

The logic starts out okay - if current > limit, then turn off the relay. But now what is the current? Zero! So it will immediately switch on again.

I thought after

else{
if(sensorVal > limitAmp){
digitalWrite(motor, LOW);
}
the loop will start back from the beginning and waiting for the button press again, won't it?

Don't use multi-line IF statements without { }

I missed the fact that it's all inside that IF.

hmmm... alright then, what about this:

void loop(){
sensorVal = analogRead(sensorPin);
if(digitalRead(btnSW) == HIGH){
if(sensorVal < limitAmp){
digitalWrite(motor, HIGH);
}
}
else{
if(sensorVal > limitAmp){
digitalWrite(motor, LOW);
}
}
}

oh other thing, about the delay, it makes sense too.

so I should put delay(100) after the motor gets HIGH.

void loop(){
sensorVal = analogRead(sensorPin);
if(digitalRead(btnSW) == HIGH){
if(sensorVal < limitAmp){
digitalWrite(motor, HIGH);
delay(100);
}
}
else{
if(sensorVal > limitAmp){
digitalWrite(motor, LOW);
}
}
}

I would go for something like this. Each button press starts/stops the motor. and if the current limit is reached, the motor is stopped as well. It does not automatically restart, but can be restarted with another button press.

int motorValue

void loop() {
  if(digitalRead(btnSW) == HIGH){
    if (motorValue==HIGH) motorValue = LOW;
    else motorValue = HIGH;
  }

  sensorVal = analogRead(sensorPin);
  if(sensorVal > limitAmp) motorValue = LOW;

  digitalWrite(motor, motorValue);

  delay(100);
}

Thank you, riesens. I appreciate it.

And thank you to all of you who spare your time to help me and give me good suggestion.

Finally, my project work as I wanted. The wiring is exactly as on the diagram I've made. Before I set the current limit, I tested the current flow first by using the current module to see the value on Serial Monitor when the motor is running with both normal load and heavy load. Then I set the limit value when its reach on heavy load in to my actual project. That's it.

It is a simple project but useful to prevent my motor from getting burn.

Thanks once again.

||GoZee||