Pages: [1]   Go Down
Author Topic: using Arduino motorshield's current sense capability  (Read 1661 times)
0 Members and 1 Guest are viewing this topic.
Vermont
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Greetings Everyone,
I’m posting this question because I haven’t been able to find a good explanation of how to use the current sense pins (A0,A1) on the Arduino’s motor shield.  I am a beginner in using the Arduino hardware and in general with development boards.  I have a Mega 2560 along with the motor shield and am using them to drive a single 9V dc motor, with 8 1.2V Ni-MH batteries as the source.  My sketch drives the motor first in one direction, speeding it up while taking readings from the current sense pin, then slowing it down, then repeating in the other direction.  Here is the portion for going in one direction:
int dirA = 12;
int speedA = 3;
int brakePin = 9;
int currentA = 0;
int val = 0;

void setup()
{
  Serial.begin(9600);  //  open serial port
  pinMode (dirA, OUTPUT);
  pinMode (speedA, OUTPUT);
  pinMode (brakePin, OUTPUT);
  }

void loop()
{
  // move the motor A to one direction increasing speed
  digitalWrite (dirA, HIGH);
  for (int j = 0; j < 255; j += 10)
  {
    analogWrite (speedA, j);
    val = analogRead(currentA); //  read the current sense pin
    Serial.println(val); // send the value to the serial port
    delay (250);
  }
 
  delay(1000); // keep the motor rolling for one second

  // move the motor A to one direction decreasing speed
  digitalWrite (dirA, HIGH);
  for (int j = 255; j >= 50; j -= 10)
  {
    analogWrite (speedA, j);
    val = analogRead(currentA); //  read the current sense pin
    Serial.println(val); // send the value to the serial port
    delay (250); 

This is what I’m reading from the serial monitor for current:
100ms delay   250ms delay   500ms delay
15   15   15
15   15   15
15   278   508
227   298   15
475   48   15
15   15   342
15   255   15
79   186   15
279   181   190
383   15   426
15   307   15
16   228   63
262   179   345
309   175   215
297   186   15
15   191   339
171   201   324
244   119   15
238   15   233
159   261   354
231   239   172
153   178   148
257   15   229
53   335   89
232   303   448
253   228   236
204   15   15
15   15   302
33   419   322
210   55   16
385   15   34
15   15   316
15    433   429

I tried it at three different delay intervals since the 100ms delay seemed erratic.  Is the current sense pin calibrated to output actual current readings rather than a number between 0 and 1023?  The no-load max current for my little hobby motor is 380mA so these numbers seem reasonable.  What I notice for observing the current readings over a longer period than shown here is that at low speeds, corresponding to small PWM value, there tends to be a single large current reading surrounded by 15’s—essentially 0 current—readings.  As the speed picks up there are more frequent ‘injections’ of smaller current values corresponding to a higher average current to drive the motor faster.  Could someone tell me if I’m interpreting this right? 
For a project I’m working on, I would like to drive two 12V linear actuators or a linear actuator and slewing drive to operate a solar tracker.  I would very much like to make use of this current sense reading to monitor the power consumption of the motors throughout the day but would like it to be more accurate than it seems to be in my current experiments.  Could anyone suggest how I might do this?

Thanks in advance for your help.

TonyL
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12062
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The current's fluctuating with the PWM because its slow PWM I think...  So you see current spikes and gaps between the spikes.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: