And maybe most importantly, we have derpbot going straight for a bit before turning in place:
#include <Servo.h>
#define Rservo 2
#define Lservo 3
Servo Rwheel;
Servo Lwheel;
int neutral = 1500;
int forward = 2500;
int backward = 1000;
void setup()
{
pinMode (Rservo, OUTPUT);
pinMode (Lservo, OUTPUT);
Rwheel.attach(Rservo);
Lwheel.attach(Lservo);
Rwheel.writeMicroseconds(neutral);
Lwheel.writeMicroseconds(neutral);
}
void loop()
{
int x = 0;
while(x < 10) {
Rwheel.writeMicroseconds(backward);
Lwheel.writeMicroseconds(forward);
delay(200);
x++; }
while(x > -10) {
Rwheel.writeMicroseconds(forward);
Lwheel.writeMicroseconds(forward);
delay(200);
x—; }
}
So it appears I’ll have to tweak the amount of time spent turning, but I consider this a whole hearted success. And I had never even heard of a while loop before last night.
Next up, I’m trying to get it to run in a straight line, since it turns out setting both servos to “forward” causes them to do just that, which is in opposite directions on the actual robot. So here’s my attempt to fix that:
#include <Servo.h>
#define Rservo 2
#define Lservo 3
Servo Rwheel;
Servo Lwheel;
int neutral = 1500;
int forward = 2500;
int backward = 1000;
void setup()
{
pinMode (Rservo, OUTPUT);
pinMode (Lservo, OUTPUT);
Rwheel.attach(Rservo);
Lwheel.attach(Lservo);
Rwheel.writeMicroseconds(neutral);
Lwheel.writeMicroseconds(neutral);
}
void loop()
{
Rwheel.writeMicroseconds(backward);
delay(200);
Lwheel.writeMicroseconds(forward);
delay(200);
}
This is a much cleaner code using Arduino’s servo libraries and some different commands, all of which is documented on their website when it’s not down.
For my first attempt, I tried to write my own code from scratch:
/*
First attempt at motor control
*/
int lwheel = 3; //sets the left wheel to D03 (D3I on my board)
int rwheel = 2; //sets the right wheel to D02 (D2I on my board)
int led = 13;
void setup() {
pinMode(lwheel, OUTPUT); //sets the left servo be powered
pinMode(rwheel, OUTPUT); //sets the right servo be powered
}
void loop() {
digitalWrite(lwheel, HIGH); // turns the left servo on
digitalWrite(rwheel, HIGH); // turns the right servo on
delay(1);
digitalWrite(lwheel, LOW);
digitalWrite(rwheel, LOW);
delay(20);
}
And as the above video indicates, I was able to get it to actually go. Yay! This code went through a few iterations, but basically once I learned that RC servos are controlled by pulse signals, I was able to fumble through this.
Learning Arduino from scratch
So for 2.007, we have the chance to learn how to use Arduino and make our robot run autonomously for part of the contest. Since I figured that this is a major way to earn points, and I have absolutely no idea how to use Arduino, I decided to take my things home and start trying to learn.


That’s the robot I have right now, which we will lovingly refer to as “derpbot”. It’s powered by 2 SpringRC continuous rotation servo motors. It’s made from 1/4” ABS plastic that has been bent to accommodate the servos. It also has 2 servo wheels, a caster, and a plastic take out tray for all the electronics, which consists of an Arduino Nano v3.0 and a carrier board. And also a 9V battery and connector I had lying around.
Remote controlled mini car thing that we built in our first 2.007 lab. And it actually works!
The main panel is a sheet of ABS that I cut, drilled some holes, and then bent the extrusions to 90° angles. Then I screwed in some servos, attached the wheels to that, added the caster in front, and viola! Add in the remote, receiver, and a battery pack and then you have a mini RC car.
It’s that time when I start blogging and documenting “the design process” once again. This time instead of making jewelry, I will be building a robot for MIT’s 2.007 Design and Manufacturing I class.