Arduino Excavator

by Clever_Idiot in Circuits > Arduino

3830 Views, 3 Favorites, 0 Comments

Arduino Excavator

Overall Picture.PNG

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com).

In this project we're going to build an mini excavator using parts printed on a Crealty Ender 3 and control it with an Arduino UNO microcontroller.

For this you're going to need:

  1. (1) Arduino UNO
  2. (1) Half breadboard
  3. (1) Breadboard power supply to power the servos separately
  4. (4) Microservo 9G servo motors
  5. (2) Joysticks for Arduino
  6. Various metric laptop screws
  7. Jumper wires for breadboards, various lengths.
  8. 3D printed parts (files available with this Instructable)
  9. (1) Black plastic box as a base. We will be printing a new lid and an insert based off of the specific box, so if you're unable to get the same box, those files will need to be modified.
  10. (2) 9V batteries

Printing and Assembling

IMG_E6762.JPG
IMG_E6759.JPG

Using the STL files provided, print all the parts. This will take a long time, as most of these parts are more than 3hr prints. Best bet is to set it to print at night, check the first few layers go down well, then let it run through the night and into the next day if needed.

Once your parts are printed, you're going to assemble them with the servo motors, using the screws in the servo motor package to secure the servos, and the laptop screws to hold the excavator pieces together. You may have noticed the arms of the servo motors are not centered on the body of the servos, so pay attention to how the servos are installed in their spots in the excavator. The orientation of the servos is important because of the lengths of the control rods they actuate. If the motors are installed incorrectly, the excavator may not operate properly or in its full range. As you're looking at the faces of the pieces oriented as if the excavator were sitting on the ground as it will operate, the motor axes should be on the left. That is, they should be offset towards the back of the machine, away from the bucket. The base servo that pivots the assembly should have its rotation at the center of the circle on the bottom of the base, which would be offset towards the inside of the circle and not on the outside edge.

After securing the servos, you'll be ready to assemble the excavator pieces using the metric screws from the laptop kit, starting with the secondary boom (the one that attaches to the bucket). It's important to start at that end because of the wiring being routed through built-in recesses and how they join paths, and especially how the base unit wire routing works. If you assemble the base unit before doing the other pieces first, you're just going to have to take it apart again.

When putting the excavator pieces together, route the servo wires through the provided reliefs. The secondary boom will have its wire come up and out through the top, where it will be loose until entering the wireway along the top of the primary boom. The servo inside the primary boom (which moves the secondary boom) will have its wire join the other servo wiring in the top wireway.

At the split between the wireways (where the primary boom is bent) you will need to connect servo extension wires to the first servo's wires, since the servo wires aren't long enough to make it into the base unit. The extension wires have the same color coding as the servo wires, and the accompanying connection jacks, so just make sure the colors match from one side to the other, to avoid confusion. They should just click together. Then run the extension wires with the second servo's wires down the second wireway of the primary boom towards the base.

At the base of the primary boom, both sets of servo wires will need an extension jumper. Same deal - color to color, should click together. Then route the wires through the base unit that houses two servos.

Finally, the base unit gets assembled with all four servo wire groups going through the wireway exit in the bottom of the base unit, where they will connect with the Arduino via breadboard.

With all moving parts joined from their halves, you can install the axles that everything pivots on. The axles are sized exactly as wide as the joint they're intended for, so if it's off by a few millimeters, wrong axle. Use the metric screws to attach the caps to the axle rods (most likely M2x8).

The bucket can be done last - its linkage can be a little complicated if you're not already familiar with it. Doing it last will leave you fewer pieces to choose from for assembly. The linkage consists of four arms, one set attaching to the rear hole of the pair on the end of the secondary boom, the other set attaching to the higher holes on the bucket side. The arms on the bucket side go to the outside of the arms that attach to the boom side. The linkage requires three axles - two to attach the linkage to each part, and one in the middle to attach the linkages to each other, forming a moving triangle. That middle axle is the control axle, which has a long cylinder on one side. This control cylinder needs to be on the same side as the servo, as there will be a control arm from the servo to this axle. Notice the face of the servo and the face of the control axle are flush. If they are drastically different (more than 4mm variance) you have the wrong control axle in the linkage. The bucket pivots with a long axle that spans the entire bucket width, in the front hole of the secondary boom.

Building the Base, Wiring the Breadboard

IMG_6758.JPG
Excavator_bb.png

Next, get the box and take the lid off of it. You should see four screw holes with a slight raise from the base of the inside of the box, just inside the shafts supporting the lid screw holes. Secure the box insert to these four holes using the laptop screws. Then mount the joysticks to the two raised platforms, with the pins facing towards the more open side of the box where the Arduino, breadboard, and batteries will be mounted. Be careful to not over-tighten the screws, as the bottom of the joysticks boards have solder points sticking out of them. Over-tightening the screws will bend and possibly break the joystick circuit boards. They don't need to hang a painting or hold a tire on the car, just snug the screws enough so that the joysticks don't wiggle, and no more than that.

With the two booms and base unit assembled with their servo motors, servo wiring running out the bottom of the base unit, and the box insert installed with the joysticks, it's time to wire the Arduino.

First, the Fritzing diagram shows a 9V battery attached directly to the breadboard, but that is wrong. Don't do that. Fritzing didn't have the breadboard power supply in its library. The breadboard will use its own 9V battery that will connect to the breadboard power supply linked in the materials list at the beginning. This is to provide a dedicated power source to the servo motors, because the Arduino doesn't provide enough current to drive them properly. Trying to power the servos from the Arduino 5V source generated very sporadic behavior in the servos. However, since the power supply connects to both power rails of the breadboard, you're going to have to arrange the jumper bars so that the servo side gets 5V and the other side is off. The servos and joysticks both take 5V, but the Arduino provides the 5V to the joysticks for analog inputs. You need to set the joystick power rail to 'off' from the breadboard power supply so there isn't any backfeeding or weird voltages going on. It might be fine, but why push it? That said, you do want to connect the two (-) rails together so there's a shared common.

Second, the joysticks in the Fritzing diagram are also the wrong joysticks - again because they didn't have the proper ones in their library. Ignore the pin designations on the joystick graphics, and wire it according to pin order. In other words, the ground of the joystick is all the way on the right if you're looking at it in the same orientation as in the Fritzing diagram. Next pin to the left is 5V power, then the analog signal returning for the movement along the X-axis of the joystick, then the same for the Y-axis. The last pin is for the pushbutton feature (clicking down on the whole joystick) which isn't used in this build.

Other than the two exceptions listed, wire the breadboard and the Arduino as shown in the diagram. To clarify the labeling, the servos from left to right are the rotational servo (mounted bottom of base and rotates the assembly), the primary boom raising servo (the second servo in the base unit that has two servos mounted in it), the secondary boom control servo, and the bucket control servo.

Programming the Arduino

The code is very simple, as far as coding goes. Essentially it reads the analog value from the joysticks and translates that into increasing or decreasing the position of a particular servo. First you'll need to make sure you have the servo library from Arduino installed. See Arduino's page here for more information and how to install it.

With the servo library installed, the sketch provided should be able to be run as-is.

The sketch uses the library functions to create four servo objects and assign them to pins. Servos work on pulse-width-modulation (PWM) so it's imperative to connect the servos to the PWM output pins of the Arduino. Again, follow the wiring diagram and use the sketch as-is and it should be good.

The sketch creates position variables for each servo, then uses those to control the servos with the library command "ServoName.write(position)". Variables are also created for the X and Y analog read values of each joystick, which are essentially bi-directional potentiometers. The voltage of each axis varies from 0-5V, and is read by the analog input.

So all the sketch really has to do is read the analog value from each joystick axis and adjust servo position accordingly, using simple 'if' statements with ranges for the voltages. If the joystick axis voltage is over or under a certain value, it's been moved far enough in one direction to either increase or decrease the servo position (which is defined as degrees of rotation). Which direction the stick moves dictates whether the voltage increases or decreases, and that direction corresponds to a piece's specific movement direction. To keep the position from increasing or decreasing to infinity, there are limits in the 'if' loops that won't allow the position to be changed beyond certain values. The values that are programmed in the sketch are based on the physical limitations of the servo motors, the excavator pieces, and their associated control rods.

Testing and Verifying Before Final Assembly

Now that most pieces are assembled and wired, it's good to verify operation before buttoning everything up.

The sketch is written so that the controls mimic the controls of a real-world excavator. The right joystick controls the bucket and the secondary boom that connects to the bucket. The left joystick controls the primary boom moving up and down and the whole assembly rotating. On the right joystick, moving it to the left will make the bucket curl inward toward the booms, moving it right will make it extend away from the booms. Moving the right joystick up will move the secondary boom out and away from the assembly, and moving it down will move the boom back towards the assembly and primary boom. For the left joystick, up and down will raise and lower the main boom, and left and right will rotate the assembly in that direction.

If everything is working properly, we can move on to final assembly.

Control Rod Assembly

IMG_6760.JPG
IMG_6759.JPG
IMG_E6757.JPG

First you're going to need to attach the control arms to the servo motors and the associated control points of the excavator. With my build, a wire hanger was used to attach the control rod to the excavator, and a paper clip was used to attach to the servo arms. Feel free to use any method you like as long as it spins freely and is rigid enough to not bend with the motion of the motors.

To begin, attach the servo actuator arms to one end of the control rods (the servo actuators are plastic arms with multiple holes that should come with the servos, and haven't been attached to the servo motors yet). Pay attention to the orientation of the servo arms, because they only go on the servo motor one way - there are gear teeth on one side only, and the other side has a washer face for the head of the screw that attaches the actuator arm to the servo.

In a real-world excavator hydraulics are used and there's a much larger degree of freedom, but with the model there are necessary trade-offs. Hence the necessity of a specific installation. To properly install the control arms, you're going to want to attach to the excavator side first, because the servo motor side is adjustable in its installation (remember the gear teeth?). After the rod is attached to the excavator side, rotate each servo to its extreme position - which direction will vary by servo. The bucket servo should be rotated to be as far forward as possible, since it's most important to be able to scoop with the bucket vs extending all the way out. The servo that controls the secondary boom should be rotate all the way backward, so the boom can reach as far as possible. Finally, the primary raise/lower servo should be rotated all as far down as it can go, since it has a base box that the arm could run into.

With the control rod attached to the excavator side and the servos in their appropriate extreme positions, rotate the boom/bucket pieces until the servo actuator arm lines up with the servo in a position that corresponds to motor position. For example, if the servo is all the way towards the back like the secondary boom control servo, the actuator arm should reflect that, with the end of the arm behind the axis of servo rotation and angled in such a way that when the servo rotates it will move the piece without binding up the linkage.

For the bottom rotational servo, the attachment is a little different. There is a C-shaped bar that is printed with the new lid, and the rotational servo attaches to this. Again, on my build a bent paperclip was used to connect the two pieces. The C-bar screws into the lid from the top of the lid, and has slightly recessed holes for the screw heads. Before you mess with the C-bar though, you'll need to attach the whole assembly to the printed lid using the rotational collar. We're going to use super glue for this. Before getting to that it would be good to do a couple of test fits first to make sure there wasn't some variation in the printing that needs to be corrected.

Setting the excavator assembly so that the base is facing up (upside down so you can see the ring recess in the base around the rotational servo), have the rotational collar and the lid ready, and all wires from the excavator booms disconnected from anything else. Should just have the four servo wire sets poking out of the base with no connection to anything else. Verify the lid orientation with the screw recesses to be on the same face that the excavator base assembly is attaching to. Then, carefully apply a few drops/beads of superglue into the recessed circle on the bottom of the base. Too much and it will squeeze out and glue the lid to the base, never allowing it to rotate. Too little and it won't hold onto the rotational collar and just fall over. Give it the Goldilocks treatment. With the glue laid in, double-check the lid orientation, then lay it over the base (remember the base is upside down) and set the rotational collar through the large hole in the lid that's the same size and into the base recessed circle. Hold it with pressure according to super glue directions. Once it's set, you should have the whole excavator boom/base/bucket assembly attached to the printed lid with the rotational collar glue in place, and the lid should spin freely. If the lid doesn't spin freely... whoops. Get the hammer.

With the upper assembly almost complete, next we set up the rotational servo and attach it to its control point. It is recommended that you first ensure that the servo is in a proper middle position. The sketch has it set for my installation but servos vary so it may need to be adjusted in the code. First put the cross-bar servo actuator on the servo without screwing it on. It should stay enough for our purposes with a screw. Since the servo ranges from 0-180degrees, 90 is a good starting point. Set it to 90, and see if that corresponds to the actuator fitting the gear teeth and actually being at the middle position. If it isn't, use the Serial Monitor to watch the value of the motor as you adjust it with a joystick and put it in the proper middle. For mine that ended up being 85 degrees, hence that is the initial position for that motor. With the motor position properly set, you're going to want to attach the servo actuator to the C-bar, then screw the C-bar in place. The servo actuator should not be attached to the servo yet; only test-fitting. Once again it's important to pay attention to the orientation of the servo actuator - gear teeth are only on one side. With the servo actuator attached to the C-bar, test fit with the C-bar lightly screwed to the lid to verify there isn't undo tension on the bar or actuator once the actuator is mounted on the servo. If there is tension, unscrew the C-bar from the lid and mount to a different hole in the actuator. Once everything is aligned and not under tension, attach the actuator to the servo with the supplied screw.

Once all three control rods are attached, and the rotational servo is attached to the C-bar screwed to the lid, test the controls again to verify nothing is binding and everything is moving as it should. If not, troubleshoot.

Final Assembly

IMG_E6755.JPG

At this point, the entire excavator upper assembly should be together, with servos, control rods, axles, and all moving properly. Wiring should be complete as well, since the controls were just verified after attaching all control rods. Joysticks should be mounted to their platforms, code loaded into the Arduino, and the entire project should be in two major pieces with the Arduino and breadboard with two 9V batteries between them and connected by what probably looks like jumper wire spaghetti.

With everything connected and verified operational, the last step is to put the batteries, breadboard, Arduino, and wiring into the base box and screw the printed lid on, with the excavator assembly on top, making sure the batteries are plugged in and the breadboard power supply is turned on to power up the servos.

Good luck.