Moving Your DIY Robot using Arduino and Servos

Sumobot Bot JR

Interested in building your own Arduino robot? For me, it has been a fun project to do with my kids. We built our first the robot using the PiBot robotics kit. Additional iterations utilized Legos, Sumobot Jr, cardboard, and other materials around the house. It’s fun to invent your own chassis and designs. Using some of the ideas from this blog post,
you’ll be able to build your own DIY robot. Hope you enjoy the journey.

In future blog posts, we’ll show ways to control your robot using a Wifi connection, Raspberry Pi, Droidscript and Android. This blog post will focus on controlling the wheels of the robot using continuous rotation servos and
a simple communication protocol.

Here’s a components that you’ll need to get started:

This post will focus on programming the servo’s with Arduino’s programming environment. For sample instructions on building a Sumo Bot Jr, check out the following video. In this post, we’ll assume that you have put together your robot chassis and your servos, breadboard, battery pack and Arduino have been connected to your chassis.

Servo Robot

  1. Connect the GND pin on the Arduino to the ground line of the bread board. The ground line is marked with a blue stripe.
  2. Connect the black wires of the servos to the ground line.
  3. Connect the red wires of the servos to the voltage line of the bread board. The voltage line is marked with a red stripe.
  4. Connect the white wire of the left servo to pin 9 of the Arduino. This wire will act as a signal wire between the servo and the Arduino.
  5. Connect the white wire of the right servo to pin 10 of the Arduino.
  6. Connect the black wire of the battery pack to the ground line.
  7. Connect the red wire of the battery pack to the voltage line.
  8. Install 4 AA batteries into the battery pack.

At this point, we’re ready to install some Arduino code into the Arduino. Copy the following Arduino sketch and upload into your Arduino. To learn more about uploading sketches using the Arduino IDE, check out the following video:

Here’s another tutorial on setting up your Arduino and uploading sketches:
https://www.arduino.cc/en/Main/Howto


#include

Servo leftServo;
Servo rightServo;

int LEFT_FORWARD_VALUE = 180;
int LEFT_BACK_VALUE = 0;
int STOP_VALUE = 90;
int RIGHT_FORWARD_VALUE = 0;
int RIGHT_BACK_VALUE = 180;
int LEFT_SERVO_PIN = 9;
int RIGHT_SERVO_PIN = 10;

void setup()
{
Serial.begin(9600);
leftServo.attach(LEFT_SERVO_PIN);
rightServo.attach(RIGHT_SERVO_PIN);
stop();
}
//================================================================================
void forward()
{
leftServo.write(LEFT_FORWARD_VALUE);
rightServo.write(RIGHT_FORWARD_VALUE);
}
//================================================================================
void stop()
{
leftServo.write(STOP_VALUE);
rightServo.write(STOP_VALUE);
}
//================================================================================
void back()
{
leftServo.write(LEFT_BACK_VALUE);
rightServo.write(RIGHT_BACK_VALUE);
}
//================================================================================
void left()
{
leftServo.write(LEFT_BACK_VALUE);
rightServo.write(RIGHT_FORWARD_VALUE);
}
//================================================================================
void right()
{
leftServo.write(LEFT_FORWARD_VALUE);
rightServo.write(RIGHT_BACK_VALUE);
}
//================================================================================
void loop()
{
if (Serial.available() > 0) {
int inByte = Serial.read();

switch (inByte) {
case 'w': forward(); break;
case 's': back(); break;
case 'a': left(); break;
case 'd': right(); break;
case ' ': stop(); break;
}
}
}

How does this code work?

We start by importing the “Servo” header and declaring the left and right
servos.


#include

Servo leftServo;
Servo rightServo;

The continuous rotation servo has a simple protocol for controlling rotational
motion using the frequency of voltage pulses. In the Arduino framework, the following
code stops the rotation of the servo.

leftServo.write(90);

To make the servo spin forward, use the following code:

leftServo.write(180);

To make the servo spin backward, use the following code:

leftServo.write(0);

With these ideas in mind, we define the following constants for the left and right servos.


int LEFT_FORWARD_VALUE = 180;
int LEFT_BACK_VALUE = 0;
int STOP_VALUE = 90;
int RIGHT_FORWARD_VALUE = 0;
int RIGHT_BACK_VALUE = 180;

We also define the constants for the Arduino digital pins.

int LEFT_SERVO_PIN = 9;
int RIGHT_SERVO_PIN = 10;

In the following code, we setup the serial port, attach the left and right servos,
and send the stop command.


void setup()
{
Serial.begin(9600);
leftServo.attach(LEFT_SERVO_PIN);
rightServo.attach(RIGHT_SERVO_PIN);
stop();
}

The following functions are used to move the robot forward, backward, left, and right.
There’s also a function to stop movement.


//================================================================================
void forward()
{
leftServo.write(LEFT_FORWARD_VALUE);
rightServo.write(RIGHT_FORWARD_VALUE);
}
//================================================================================
void stop()
{
leftServo.write(STOP_VALUE);
rightServo.write(STOP_VALUE);
}
//================================================================================
void back()
{
leftServo.write(LEFT_BACK_VALUE);
rightServo.write(RIGHT_BACK_VALUE);
}
//================================================================================
void left()
{
leftServo.write(LEFT_BACK_VALUE);
rightServo.write(RIGHT_FORWARD_VALUE);
}
//================================================================================
void right()
{
leftServo.write(LEFT_FORWARD_VALUE);
rightServo.write(RIGHT_BACK_VALUE);
}

//================================================================================

In the loop function which is called repeatedly, the Arduino waits for a character
from the serial port. If the Arduino receives a “w”, the program sends a forward command.
If the Arduino receives a “s”, the program sends a backward command.
If the Arduino receives a space, the program sends a stop command.


void loop()
{
if (Serial.available() > 0) {
int inByte = Serial.read();

switch (inByte) {
case 'w': forward(); break;
case 's': back(); break;
case 'a': left(); break;
case 'd': right(); break;
case ' ': stop(); break;
}
}
}

In the Arduino IDE, press CTRL+SHIFT+M to open the serial port monitor. This window is used to send bytes to the Arduino. Try typing “w” and press enter. The robot should move forward. Try typing space and press enter. The robot should stop.

Congrads! You’ve built your first Arduino robot!

Top Stories on InspiredToEducate.NET

Learning To Code

 

Sumobot Jr: Fun Open Source Robot Kit using Arduino and JavaScript

Sumobot Bot JR

Looking for a fun weekend project? The Sumobot junior is a fun open source robot kit using Arduino and JavaScript. If you already own an Arduino, this kit can be an inexpensive way to tinker with robot building. (i.e. about $50)   Since the plans for the chassis are open source, you can customize the robot as you see fit.  The design can be completed using a laser cutter or a 3D printer.    You might extend the base of the robot so that you can have room for a bread board or anything else you like! You can find complete instructions for building your Sumo Bot JR at http://sumobotkit.com/.   The design uses continuous rotation servo’s which are pretty easy to program and re-use in other robot projects.  You can purchase the servo’s here: https://www.parallax.com/product/900-00008

While researching this blog post, I found another cool post detailing the process of building a NodeBot Jr.
http://www.tattdcodemonkey.com/blog/2014/7/26/nodebots

You can find the build plans and code here: https://github.com/makenai/sumobot-jr

 

 

Top Stories on InspiredToEducate.NET

Learning To Code

 

Image from https://github.com/makenai/sumobot-jr

Civic Hacking: Why does it matter?

Hack for change picuture

Civic hacking has become a potent movement for engaging coders, designers, and technology professionals in challenges that matter to the community.   Computer hacking tends to have a negative connotation.  Some call civic hacking “hacking gone good” since it’s really about community service and place making.

I had the good fortune to participate in the National Day of Civic hacking on June 6th at SparkMacon MakerSpace.  I want to give a shout out to the organizations that made the event possible: TAG Middle Georgia, LBA Ware, Infinity Network Solutions and Spinen.   I especially want to thank the team that organized the event for their investment of time in organizing challenge mentors, making people feel welcome, and supporting our makers.

Hack For Change

Some argue that civic hackathons have little value since it’s rare to find apps that find their way into full implementation and  achieve impact.  I, however, feel that civic hackathons offer our communities a number of benefits.

  • Building a tribe change makers: It’s great to meet like mind technologists who care about making a positive impact in their community.  Hackathons enable you to meet new people, make connections, and learn about the deeper needs of your area.  Through the experience, you learn about new tools, practices, and strategies for doing rapid prototyping.
  • Local Data, Local Impact: Democracy only works when citizens are engaged.   I appreciate that the civic hacking movement helps us to learn about local concerns and empowers us to do something about it.  Being a geek about data, it’s also fascinating to learn about the open government API’s and data sources that can support civic apps.
  • Voting with your code: It’s interesting to see what problems makers care about.   In a typical hackathon, there’s a broad range of issues, data and topics to choose.  The team tends to select projects based on skill level, their engagement in the topic, and challenge difficulty.
  • Building a community of support: During our hackathon event, it was cool to see how different teams mentored and supported each other.  Everyone has different strengths in terms of design or technology.   I can honestly say that everyone learned from each other.   In our hackathon in Macon, it was nice to see the experienced hackers mentoring the new developers and helping them feel welcome.

In our hackathon in Macon, GA, one team created an mobile app serving Peace corp team members to help them to know about safety and security alerts as they travel to various countries.   Another team of hackers helped propose and prototype applications that would help high school students with learning vocabulary for SAT/ACT .

We had some important discussions on the real impact of hackathons.   In general, how do we care, feed, market, and grow various hackathon ideas?  How do you care for the hacks from a software maintenance point of view?  How do you intentionally organize the challenge ideas and data sets?  The team from Spinen made some strong arguments for making a home for these concerns.  I’m interested in seeing how this idea can grow.

Are you interested in contributing a challenge problem for future hackathons for SparkMacon Makerspace?  Feel free to contribute your ideas here:

Submit a hackathon challenge idea to SparkMacon

To help contribute to this conversation locally for Middle Georgia, I have compiled most of the challenge problems, data, resources, and links from previous SparkMacon hackathons and HackForChange events.  At a minimum, it would be cool to create a backlog of challenge ideas that can be used in future Middle Georgia hackathons and SparkMacon Open Make events.

Middle Georgia Civic Hacking Projects and Resources

To close, here’s some links sharing the impact of civic hacking in communities.   I think it’s work that matters.   I believe it’s a cool way to innovate our communities and create engagement.   What do you think?

 

Top Stories on InspiredToEducate.NET

Learning To Code