Pages: [1]   Go Down
Author Topic: Detecting a motor brake for a brushed DC motor  (Read 949 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All,
I'm a newbie in the Arduino world, and generally in the electronic world. I'm mainly developer but want to open myself to the electronics
I've bought a discovering kit, and made the exercises, very interesting
So now as a first project, i wanted to create my own light kit (led of course) for an RC car, called Mini-Z from Kyosho. As you can imagine, i don't come to you to bright a led, my problem is the braking detection
The Mini-Z is a small RC car with a complete PCB for the whole electronic, so i've no access easily to signals like PWM (PPM), the car run on 4 AAA batteries, so 6v max, the motor, 130 sized will consume max, say 2A at blocking
Basically i know the motor direction can be detected by the direction of the current, and the braking can be detected by a short circuit between motor leads. So my problem is : How can i connect the motor to my arduino without burning the arduino, without interfere with the motor run, and with a chance to detect the motor behaviour?
Existing light kits have leads that connect in parallel the light kit and the motor leads, but i don't imagine what are the consequences if i make the same things to connect one lead to GND and one lead to an input (my mind says: "Don't do that, you will burn something with that current")

I hope you can help me

Thanks in advance

Sna
Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11649
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lets assume the motors generate some high voltage spikes and play safe.  Each side of the motor can go to a 2:1 resistive divider  (say two 10k resistors) to bring the 0..6V range within the reach of Arduino's analog inputs (and protect a bit against abnormally high voltages).  Then add a small capacitor to ground for each signal, perhaps 10 to 100nF to reduce high frequency noise.  To further protect the Arduino's inputs we can also have 3V9 zener diodes across the capacitor (although the 10k of the resistive divider is going to protect a lot).

So this ought to provide two safe signals to route to A0 and A1 say.  This should then provide a lot of information about the motor's speed and direction, just measure the difference in voltage:
Code:
  int speed = analogRead (1) - analogRead (0) ;

And connect grounds together of course...

Logged

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

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

Hello,

Thanks a lot for your help
I've made a try finally.
I've doubled my motor wires, to have the arduino and the motor wired parallel. 10K Resistors are connected to those wire and to A0 and GND
I didn't go further, because i'm sure connecting the 2 motor poles to 2 separate analogic inputs will need some diodes to avoid reverse current, no?
With this wiring, i can already detect the motor speed, and even the direction (arduino will not read reverse voltage). But now i'm stuck in a way i didn't imagine before
To detect the brake, i've tried to add a wiring from a digital output to the motor pole. In my code:
if analogRead (A0) == 0
   digitalWrite (12, HIGH)
But this is not a solution for some reasons
1) Current read from A0 can be current from motor running or current from the digital output to check the brake status, difficult to differenciate
2) Even without braking, the current from digitalWrite will pass trough the motor itself, and then is not a good test to know the brake status

I've checked the motor signal with an oscilloscope, it is effectively a PWM signal, but nothing in the graph can help me to detect a braking from a stop.

Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I have done this in a larger scale car using a different approach.

The PWM for the motor is the same type of signal as sent to a servo, a pulse of 1500 is center, towards 2000 is full throttle and below 1500 would indicate brake or reverse.

my cars are generally set for no reverse.

I used an interrupt connected to the throttle signal wire to measure the pulse width. I still have the code and will try to post it on my blog later today.

One project that I have in mind is to have an LED flash randomly in my tail pipe to simulate turbo overrun when I brake, I was also thinking of fading in and out some orange LEDs in the wheel hubs to show the brake discs glowing with heat under hard braking.

I am sure you will find something of interest and help on my blog -

http://rcarduino.blogspot.com/

Duane
Logged


Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I have done this in a larger scale car using a different approach.

The PWM for the motor is the same type of signal as sent to a servo, a pulse of 1500 is center, towards 2000 is full throttle and below 1500 would indicate brake or reverse.

my cars are generally set for no reverse.

I used an interrupt connected to the throttle signal wire to measure the pulse width. I still have the code and will try to post it on my blog later today.

One project that I have in mind is to have an LED flash randomly in my tail pipe to simulate turbo overrun when I brake, I was also thinking of fading in and out some orange LEDs in the wheel hubs to show the brake discs glowing with heat under hard braking.

I am sure you will find something of interest and help on my blog -

http://rcarduino.blogspot.com/

Duane

EDIT : Code added below, its not the exact code I am using but is close enough that you should be able to get it working. For the circuit, I have the arduino connected to the RC Car ground, the signal line (white) from the receiver to the servo or ESC is connected to interrupt 0, the Arduino power comes from my cars LIPO
Code:

#define NO_ERROR 0
#define SYNCH_ERROR 1
#define RANGE_ERROR 2

volatile unsigned long ulStartPeriod = 0;
volatile unsigned long ulEndPeriod = 0;
volatile unsigned long ulHighPeriod = 0;
volatile unsigned long ulLowPeriod = 0;
volatile unsigned long ulErrorReading = 0;
volatile int nInput = 0;
volatile int nError = NO_ERROR;

#define MONITOR_PIN 13

Servo myServo;

void setup()
{
  Serial.begin(9600);
  Serial.println("finished setup");

  attachInterrupt(0,calcInput,CHANGE);
 
  pinMode(MONITOR_PIN,OUTPUT);

  myServo.attach(9);
  myServo.writeMicroseconds(1500);
 
  Serial.println("finished setup");
}

void loop()

  if(ulHighPeriod > 1000 && ulHighPeriod < 2000)
  {
    // if ulHighPeriod < 1500 your brakes are on
    // its probably better to use a neutral area of 100 or 200
    // i.e. if ulHigherPeriod < 1300 your brakes are definitley on
  }
}

void calcInput()
{
  // read the PIN, figure out if we are starting HIGH or ending LOW
  if(digitalRead(2) == HIGH)
  {
    // NEW PULSE
    ulStartPeriod = micros();
    ulEndPeriod = 0;
  }
  else
  {
    if(ulEndPeriod != 0)
    {
      nError = SYNCH_ERROR;
    }
    else
    {
      // not a new pulse so must be the end of an existing pulse - now we can calculate the pulse duration
      ulEndPeriod = micros();
      ulHighPeriod = ulEndPeriod - ulStartPeriod;
      // test that the reading is within the expected range, if not
      // handle the error in some way
      if(ulHighPeriod < 800 || ulHighPeriod > 2200)
      {
        nError++;
        ulErrorReading = ulHighPeriod;       
      }
    }
  }
}
Logged


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

Hello,

Thanks a lot for the code, it will be interesting on my larger scale RC's i'm sure smiley

For the moment, i've found a difference in measurement of the resistance of the controller/motor couple when running forward, backward, braking and still. So i'm digging in this direction for the moment with a resistor bridge to "see" the resistance in the arduino and interpret it.
About the turbo overrun, interesting idea, but we need to know the conditions where this can be observed to reproduce it, i don't like to randomize. Maybe trigger the "flame" at the beginning of acceleration (from still to movement), at the release of the accelerator, and if braking some random trigger (we are not braking so much time smiley-wink) until stop. This can be as tricky as the brake light smiley

Your blog is in my favorites, interesting ideas smiley-wink
Logged

Pages: [1]   Go Up
Jump to: