Pages: [1]   Go Down
Author Topic: understanding amp check code  (Read 373 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I was reading over this instructable:http://www.instructables.com/id/Tankbot-Internet-Controlled-Tank-Robot/step4/Tank-Load-Code/
and came across this code: http://www.instructables.com/files/orig/FLU/K0YM/H0K52XTJ/FLUK0YMH0K52XTJ.ino

I don't quite understand how he is measure the amount of current the motors are pulling. The code is below, but I don't understand how it is working, nor do I understand what sensA and sensB would be connected to. Can someone please clarify?



Code:
void ampCheck() { //Check to see how much power we are pulling, shut down if we pull more than 2A
  ampA=0;
  ampB=0;
  for (int i=0; i < 25; i++) {
    ampA=ampA + analogRead(sensA);
    ampB=ampB + analogRead(sensB);
    delay(5);
  }
  ampA=(ampA/25);
  ampB=(ampB/25);
  if (ampA > 1000 || ampB > 1000) {
    analogWrite(motorA, 0);
    analogWrite(motorB, 0);
    delay(1000);
  }
}
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's using the Arduino motor shield - http://arduino.cc/en/Main/ArduinoMotorShieldR3. It provides current sensing output.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 237
Posts: 24278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Main/ArduinoMotorShieldR3


Why have ampA and ampB both got global scope?
« Last Edit: July 03, 2012, 03:22:43 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh wow, I had assumed it was in the shield and had looked, but I guess I was looking at the wrong motor shield.
Any idea on how I could do something similar for my arbitary high speed/amp/voltage motor? I'd love to get a reading of how much current is being pulled.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 237
Posts: 24278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you look at the schematic, there's a couple of 150mOhm resistors  (R1 & R2).
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: