I am working on a DC motor control and am using a hall sensor to measure the current.
For this project I am using an Arduino Uno with a moto shield. This works completely fine. Now i want the motor to stop when the current rises above a certain threshold. For that I intended to use the hall sensor.
I configured the sensor according to the manufacturer's instructions and integrated like depicted in the attachment (sorry, paint) into the circuit.
void loop() {
if (Serial.available()) {
switch (Serial.read()) {
case '0':
analogWrite(pwm_a, 0);
break;
case '1':
digitalWrite(dir_a, LOW);
analogWrite(pwm_a, 255);
break;
case '2':
digitalWrite(dir_a, HIGH);
analogWrite(pwm_a, 255);
break;
case '3':
reset();
break;
case '4':
pull_test();
break;
case '5':
insertion();
break;
}
}
Serial.println(analogRead(hall_sensor)); //read signal from hall sensor and send to pc
}
Now for case 1 and 2 if I use them I get the same input signal. If I use case 3 the following code gets executed.
void reset() {
digitalWrite(dir_a, LOW); //set direction
analogWrite(pwm_a, 250); //start motor
while(analogRead(hall_sensor) > 265) {
);}
analogWrite(pwm_a, 0); //stopp motor again
digitalWrite(dir_a, HIGH); //setback direction
}
But this strangely drops the value of the signal permanently, although the current does not rise. I have really no idea why this happens and how to fix it.
What I already tried it to have a flexible threshold, but it looks like with the changing of the threshold also the interval changes .
If anybody of you has an idea or a clue why this happens and how it could be fixed, I'd really appreciate some help.Thank you in advance.
Can you provide a link to the datasheet for the Hall sensor? What output does it produce when no current flows though its sense pins?
Most hall current sensors output around half the supply voltage when no current is sensed. This would correspond to a value of about 512 from analogRead(). The output rises or falls from this level depending on the direction of the current sensed.
Datasheet
The LTSR 6-NP, I set it up to use two primary turns.
I did some further experiments to find out the reason, and I had some peculiar findings..
First I measured without any current flow as suggested. I got a value of ~'315' from my analogRead. Running the DC motor with no load resulted in the same analogRead. So far it looks OK to me.
But now the strange thing, when I deliberately stalled the motor, the analogRead did not change although my power source did show a rise in the current as one would expect. And the only change so far I could produce when calling the code for void reset(). And that is unrelated to used speed of the motor.
No I am wondering if the sensor is defect or I am something completely wrong when I'm trying to use this sensor.
315 is not a sensible reading when there is no current. The output should be about 2.5v, which would give an analogRead value around 512 assuming you are using the default 5v supply for the analog reference. How do you have the LTSR 6-NP connected? What voltage do you measure on its output and Vref pins?
I connected the Hall sensor like this to the Arduino
The connection for the current which I want to measure are connected as 6-5-3 and 1-2.
When I turn of my external power supply i can measure between V_out and GND 2.50035 V, and between V+ and V_out 3.49963 V.
With a turned on power supply in a "no load" mode I can measure between V_out and GND 2.51xxx V, and between V+ and V_out 2.48xxx V.
If I stall it and have a current of 1 A, I can measure between V+ and V_out 2.40xxx V.
I tried to vary the resistance of the potentiometer to get a bigger voltage change between "load" and "no load" mode, but then the current flowing through the DC motor when it does nothing grows significantly.
OK, if the supply is 5v and you are getting 2.5v on the analog input pin, then analogRead() on that pin should be returning close to 512. Are you sure you are reading the right pin, and you have a good connection between the sensor and the pin?
I use the LEM 6NP hall sensor regular, really good quality sensor that can have its sensitivity increased a lot with the through hole
Any way can I ask what does the potentiometer do? its not something I have ever even seen never mind used? as far as I can tell the output will be dragged down low as you are seeing
Lose the pot and make sure the hall sensor is supplied from the same source as the Arduino, I believe the hall sensor uses a bit too much to be supplied via a USB through the Arduino if thats the way you powered it