Introduction: SainSmart Upright Rover "Trust Fall Bot"
The SainSmart InstaBot Self-Balancing Robot is a very good introduction to controlling a robot using Arduino, and this Instructable's main goal is to aid you in setting up your robot and showing you a very simple program I coded in Arduino that gives you a tiny glimpse into the possibilities of Arduino-based robotics.
First of all, these instructions pertain solely to the Instabot V2 available at Amazon:
They may be easily translatable to the later versions, as the principles should be the same, but there could be minor changes from version to version.
What You Will Need:
- SainSmart Instabot V2 kit (see link)
- 2 9 V batteries
- Insulated copper wires
- extra pin connectors
- 2 LED lights
- Arduino IDE
You can usually do a quick Google search to find any extra components you may need for pretty cheap.
A short demonstration of the robot is available in the .mp4 file below.
So if you've got everything, let's get started!
Step 1: Step 1: Building Your Robot From the Sainsmart Instabot Kit
First thing's first: remove all components for the robot itself from the box (don’t worry
about the remote for this project, but you may want to do something with that later).
It may help to knoll the items (which is a fancy word for organizing all of your components), but that is entirely a personal choice.
Begin assembling the robot according the picture above (or you can see how the pieces fit together in the .mp4 file below). I will not go over the details of which part goes where for the body of the robot, as mylemonjuice has created a very helpful Instructable on the actual assembly of the robot.(https://www.instructables.com/id/InstaBots-Upright... )
Now, you will need to solder a few pieces in order to build this robot, so if you are unfamiliar with how to solder, I suggest checking out noahw's Instructuable (https://www.instructables.com/id/How-to-solder/ ); it is extremely thorough and very informative. The first things you will have to solder are the two resistors and wires, which you will attach to each of the motors, as shown in the first picture.
Next assemble the T-connector (shown in the second image), and connect the black wire to the GND port on the L298N (the board that
sends information to the motors), and the red wire to the port labeled VCC. Note that this usually uses an 11.1 V Li-Po battery, but you can substitute that for a 9 V battery, using a second set of wires. Wrap the copper around the prongs of the T-connector, and then around the corresponding positive (+) and negative (-) parts of the battery. Be sure to wrap the exposed wires in electrical tape for security and safety!
Step 2: Step 2: Connecting the Wires
Connect the two wires from each of the motors as follows:
Motor1 → OUT1 and OUT2
Motor2 → OUT3 and OUT4
On the board that powers the motors, connect female part of
female-male wire to pins labeled IN1, IN2, IN3, IN4, ENA and ENB. Run wires through holes provided on the white boards. Connect wires on the smart shield as follows:
IN1 → D4
IN2 → D3
IN3 → D5
IN4 → D6
ENA → D9
ENB → D10
(Optional) Insert the three potentiometers provided in the ports A0, A1 and A2 on the sensor shield.
Solder the provided gyroscopic accelerometer on the port named MPU6050 on the smart shield as shown in the second image.
Lastly, you will need your LED lights. Notice that on the LEDs, one pin should be shorter than the other. This one is the ground pin, so you need to put that in a GND port. For one LED, you can put it in pin 13, with the GND port adjacent to it, but you may have to use an extra pin connector for your second LED. I put mine in pin 12 and ran a wire connecting the ground to the GND port on the opposite side of the sensor shield.
Now the real fun begins!
Step 3: Step 3: Coding
Here is a link to the relevant manufacturer-provided material (source code, etc.):
If you plan on using the remote control at all, you will need the code provided in that file; otherwise, you can just use my codes, which are provided at the bottom of this step.
First, it is important to note that your robot may not balance right away (mine certainly didn't). However, it should at least be trying to keep itself upright. The Balance.ino file is essentially the source code but stripped down to the basics of the balancing program. In this code, however, the potentiometers are unnecessary because the values from them are inputted manually (these are the kp, ki, and kd values you can see in the image above).
If your robot is jerky or unstable, first try playing around with these values; they can usually fix a lot of problems. Additionally, you may want to see what changes the variables defined at the top have (see other image). For my robot, I had to adjust the angle offset and the RMotor offset, but yours may be different.
Once you have your robot balancing effectively, download the Trust_Fall.ino file and adjust all the variables according to your robot. Look at the flow chart below to get an idea of what the code is doing. Essentially, it will balance normally for 9000ms before turning on both LEDs. After 1000ms more have passed, the lights will flash, and the robot will fall down (try to catch it!). When you pick it back up, it will just balance normally indefinitely. If you want to do the trust fall again, just press the reset button and wait a second.
Step 4: Step 4: Have Fun With It!
I hope you found this Instructable helpful, and I hope you enjoy running the Trust Fall code. But more importantly, I wanted to demonstrate something simple you could do with an Arduino-controlled robot. You can look into doing something like adding an IR sensor and controlling the bot with a remote control, you can add buttons that add some functionality to the robot, or you can play around with the controller provided. The possibilities are nearly endless, so just have fun with it!