Wiper Motor and Arduino Mega Servo

20,885

95

16

Introduction: Wiper Motor and Arduino Mega Servo

This story is about how to turn a wiper motor into a huge servo and how to control it from an Arduino. Although this specific servo was created from a Volkswagen Lupo wiper motor, any strong DC motor will do. The attached Arduino sketch wraps the associated code into a class (rather appropriately dubbed MegaServo) to allow for the servo be used as an object in a sketch. To make using the MegaServo objects really easy-peasy-lemon-squeezy, the class can be installed as a library in the Arduino IDE.

Step 1: Parts Needed

Just a few parts are needed to create this big boy, although some parts require a bit of modification before they fit the design. This will be covered in the next section. First, the parts list:

  • Arduino (Uno, Nano, ..., doesn't really matter)
  • Windshield wiper motor (or any other strong DC motor)
  • Potentiometer (I used a 50K one, but that doesn't really matter)
  • Motor controller (such as the Sparkfun Monster Moto shield, or any other high current H-bridge)
  • Wire
  • 2 L-brackets
  • Couple of inches of brass or aluminium tube
  • Potentiometer dial knob


Although of course any type of electrical wire will do, a wiper motor under any serious load will draw a reasonable amount of current. Make sure to do some calculations before selecting the wire, for instance using this tool: http://wiresizecalculator.net. The wire should be capable of carrying the stall-current of the motor at the motor's operating voltage.

For the same reason, the H-bridge may require a heatsink mounted on top of the chips. See the appropriate datasheet for specifics.

Step 2: Construction

The key to controlling any servo is for the controller to know at any moment what the position of the horn is. In our case, this is achieved by mounting a potentiometer to the shaft of the motor. By reading the value of the potentiometer, we will know the rotation of the motor. This is done by using two opposing brackets, one holding the motor, the other holding the potentiometer.

The brackets will require some work before they will fit the motor resp. the potentiometer; I had to cut a large hole into the motor bracket to fit the shaft and I drilled an extra hole to be able to fit all the mounting screws of the motor.

The potentiometer bracket required two holes be drilled: one to fit the potentiometer shaft, the other to hold the potentiometer peg to prevent it from turning along with the motor. The main challenge in this proved to be to drill the potentiometer shaft hole at the exact height so it would align perfectly with the motor axle.

I mounted both brackets on some length of 4040 aluminium profile. Although this turned out rather well for sliding both brackets together in the next step, I could have fixed the brackets just as wel on any surface.

I took a small end of 8mm aluminium tube, thread-tapped it to fit the motor axle and screwed it on the thread on the axle. To fix the potentiometer on the other end I cut up a dial knob and pushed it topsy-turvy on its shaft. I then used lots of hot glue to fix both ends together.

Step 3: Electronics

The electronics part of our giant servo is composed of an Arduino, an H-bridge and the potentiometer we just glued onto the motor shaft. In this case I used an Arduino Uno, but any type will do actually. The H-bridged in case is a Monster Moto shield. Since it is a shield it can be mounted on top of the Uno, but I choose to place it alongside of the Arduino, making it easier to use the other availble Arduino pins for other purposes.

The Monster Moto uses the following pins:

  • D4 - Clockwise M2
  • D5 - Enabler M1
  • D6 - Enabler M2
  • D7 - Clockwise M1
  • D8 - Counter clockwise M1
  • D9 - Counter clockwise M2
  • A2 - Current sensor M1
  • A3 - Current sensor M2

Because there's only one motor connected in this case only half of the double H-bridge pins are used. The Monster Moto shield provides feedback on the current the motors are drawing through analog pins A2 and A3. Those are not used in this example.

The potentiometers outer pins are connected to resp. GND and +5V, the wiper goes to an analog Arduino pin. In the example code attached this pin is A4 (this can be changed easily, see the next section).

Step 4: Code - Library and Demo Sketch

The attached code contains the MegaServo library and a simple demo sketch. The library supports two servos by default, but this may be extended by setting the value of de MAX_SERVOS define.

The MegaServo object has a couple of public members, the following of which are most important:

  • void attach(...) - attaches the servo to the specified pins and registers the servo with the timer callback routine. An overload allows for specifying a potentiometer value offset.
  • write(int degrees) - tells the servo to set its horn at the specified angle.
  • void update() - this one needs to be a public member since it is called by the timer callback routine. No need to bother with this one in the sketch.
  • servo_status read() - return the current servo status, i.e. current angle, destination angle and speed.
  • bool active - sets the servo's active or inactive state.

The attach method is probably the most important. Its parameters are:

  • CW: the Arduino pin going high to turn the motor in clockwise direction.
  • CCW: the Arduino pin going high to turn the motor in counter clockwise direction.
  • Enabler: the Arduino pin (pwm) setting the motor speed.
  • Sensor: the analog Arduino pin the potentiometer wiper is connected to.
  • Optional offset: difference between actual 90 degrees potentiometer value and 512, the value used in the library.

The MegaServo class has a private member int tolerance. This is an important value because it deals with the stopping distance of the motor: if this distance is larger than twice the tolerance-value the motor will turn to a stop overshooting the "braking zone", so the servo is told to turn back, and again will overshoot, causing the horn to jitter back and forth over the requested position. If this is the case, simply set the tolerance to a larger value in the MegaServo constructor. If possible, setting this value to a smaller size will of course render a more accurate servo positioning, so it highly preferable to set this value as small as possible.

The MegaServoDemo project attaches the servo and tells it to turn to center position (90 degrees). It then accepts any value between 10 and 170 (angle in degrees) through the serial input screen (the parseInt method reads until it times out or a non-digit value is encountered, so it may appear to perform poorly. This is intended) and sets the servo horn at the requested angle.

Arduino Contest 2016

Participated in the
Arduino Contest 2016

Epilog Contest 8

Participated in the
Epilog Contest 8

Be the First to Share

    Recommendations

    • The 1000th Contest

      The 1000th Contest
    • Battery Powered Contest

      Battery Powered Contest
    • Hand Tools Only Challenge

      Hand Tools Only Challenge

    16 Discussions

    0
    Mariano44
    Mariano44

    7 weeks ago

    when i put any degree the wiper rotate to the angle and after that it return to 0. Why?

    0
    Woodford60
    Woodford60

    Question 4 months ago on Step 4

    Hi, I wonder if you can help? I am trying to make a RC Servo with a 12v wiper motor, 10K potentiometer, BTS7960 H Bridge and Arduino Uno. However, when the potentiometer and the motor reaches its full rotation, the motor doesn't stop. I am not sure whether it is not reading the potentiometer or the Remote Control signals properly? I haven't much experience with things like this and copied a code from someone who was doing similar. However, it appears something isn't going quite right. If anyone can help I would be very appreciative. Please note that very technical information may need to be broken down for me as I am still learning. Thank you.

    0
    NeilRG
    NeilRG

    Answer 2 months ago

    If in your learning process the motor did not stop, and the pot was connected to the motor shaft, the potentiometer is destroyed. I suggest wiring the circuit including a new pot, but dont connect the pot PHYSICALLY to the motor. Instead turn it by hand , until your code works as expected.

    0
    3CarrotsOnAStick
    3CarrotsOnAStick

    Answer 3 months ago

    You can use the serial monitor in the Arduino IDE to see what value the potmeter is giving. That might give you wome hints as to what is wrong. Just send the potmeter value to the serial port using the serial.println() function. Then open the serial monitor from the IDE menu while the code is running.

    0
    Snake00012
    Snake00012

    3 months ago

    very nice topic hoever i asking if i can use l298n as a H bidge
    thnx

    0
    3CarrotsOnAStick
    3CarrotsOnAStick

    Reply 3 months ago

    No, that would never work with a wiper motor; even without any load, the motor would pull so much current the h-bridge would be fried instantly. The data sheet of any h-bridge will tell you the current it can safely support.

    0
    Snake00012
    Snake00012

    Reply 3 months ago

    Thnx so much for the answer
    So better to do with BTS7960 to work properly?

    0
    3CarrotsOnAStick
    3CarrotsOnAStick

    Reply 3 months ago

    I don't know what motor you'll be using and what its stall-current is, but this h bridge can handle up yo 43 amps. Guess that should be sufficient for a regular wiper motor.

    0
    alidotgul
    alidotgul

    5 months ago

    in zip folder no code can u share the code

    1
    3CarrotsOnAStick
    3CarrotsOnAStick

    Reply 5 months ago

    If you open the zip using 7zip you'll find the three files.

    0
    monadeux
    monadeux

    1 year ago

    Nice work! Why not use PID, any specific reason? May help reduce the oscillation.

    0
    3CarrotsOnAStick
    3CarrotsOnAStick

    Reply 1 year ago

    Thanks!

    I'm using this setup in my motion sim racing simulator. Using PID would require to continuously update the Setpoint, which would wreck the D and the I.

    0
    etmh
    etmh

    3 years ago

    Very interesting instructable. Do you happen to know what torque you can achieve with this particular motor?

    0
    skynet35
    skynet35

    3 years ago

    Hi,

    really good project ;)

    jut one question, if I want ad button, to have only 2 positions (not push 0° and push 90°), where i must change caracteristics on .ino?

    thanks

    0
    3CarrotsOnAStick
    3CarrotsOnAStick

    Reply 3 years ago

    Hi there, and thanks!

    That would require two changes: first, you have to find the pot value for 0 degrees and set the MIN_POT_VALUE in the header file (MegaServo.h) to that value and second, you have to set MIN_ANGLE in the same file (two lines below) to 0. Make sure the adapted header file is the one that is actually used by the Arduino IDE compiler!