Introduction: Intro to Robotics

About: My name is DJ and I previously made electronic whatsits, 3D-printed thingamabobs, and laser-cut kajiggers for the Instructables Design Studio; now I build and repair puzzles for Particle Industries.

Robots are rapidly moving from characters and concepts only found in science fiction to part of our everyday lives. Although they might sometimes seem to be electro-mechanical mysteries, personal robotics is becoming more accessible every day! Cheaper, higher quality, and easier to use components are now just a click away, and amazing individuals around the planet are volunteering countless hours to make the software and experience of building robots fun and easy to understand. In this instructable, I'll break down the design process for building a simple robot, and the design considerations for each part and how to choose alternatives.

As any robot is a system with many different parts and concepts working together towards one goal, I recommend reading the instructable in it's entirety. I've worked to present as much information in an easily digestible format as possible, but it's a deep subject to explore. This instructable assumes some previous experience with programming, electronic components, and basic electronic assembly skills.

If you're looking for a quicker intro and just want a primer, sans the build details, check out this article I recently penned about Robotics over on Ponoko.

Step 1: What Kind of Robot Is Right for Me?

Robots come in every shape and size imaginable. There are A LOT of options when it come down to choosing what kind of robot to make. Below you'll find the most common kinds of robots broken down by their type of locomotion. I'll discuss their various advantages and disadvantages and explain the cost and complexity associated with each variation. These distinctions are by no means hard and fast, but general subsets into which many robots fall. Hopefully this should be a good starting point for choosing your first robot build!

Wheels (rovers, UGVs - unmanned ground vehicles)

Wheeled robots are some of the easiest platforms with which to get started. Many basic kits consist of two drive motors accompanied by a trailing castor wheel or bearing. With a minimum of motors, these platforms can easily be controlled by basic micro controllers. Being naturally flat and in constant contact with the ground (unless they're balancing bots), they're naturally stable platforms, which greatly simplifies their motion control programming. Unless they have rather large and rugged wheels or tank treads, many rovers are unable to clear obstacles or uneven terrain.

Pros:

-Easy to build

-Fast

-Well documented control schemes

-Many low cost platforms available

Cons:

-struggle with outdoor/uneven terrain

-unable to clear many obstacles

Professional Examples: Mars rovers, Roombas, self-driving cars

Legs (Hexapods, Bipeds, Quadrupeds, Octopods)

While nature's preferred format of locomotion, robotic legs are less commonly found in practical designs. Small legged robots are usually made with a larger number of servos. Hexapods are the most common legged platform, but due to their needing at least three servos per leg, they become costly to build very quickly. Simple waddling bipeds that lack torsos can be made simply with far fewer servos and are a fun basic introduction. More advanced mini-humanoids are available as well, however these typically require fast and strong servos to properly move that are very expensive, but very precise.

Pros:

-can travel through very uneven terrain

-able to clear large obstacles

-very interesting to watch

Cons:

-usually much slower than wheeled bots

-expensive

-shorter battery life

-require more complex programming

Interesting Variations: Zenta's MorphHex

Professional Examples: Atlas, Big Dog, ASIMO

Arms

Arms are by far the most commonly found robotic systems. Endlessly toiling away in factories around the planet, arms are great for repeated complex motions required for assembly. Outside of factories, arms can often be found paired with a wheeled base to make a remote system capable of handling hazardous materials and explosives. In the hobby setting, arms are usually distinguished by their number of degrees of freedom (DOF) with three, four, and five rotational DOF arms being the most common configurations. (Check out my artist robot arm I built last year)

Pros:

-able to manipulate a wide variety of objects

-satisfying to watch

-require fewer parts to build

Cons:

-usually fixed in place

-can require more complex programming for interesting behavior

Professional Examples: KUKA, ABB

Rotors (ROVs, UAVs, Multirotors: Quad, Hex, Tri, and Octocopters)

Spinning propellers to make your robot zip through the air or water are another attractive option. Submersible bots are trickier to design and prone to unfortunate leaks, but they're not out of reach. Multirotors, or "drones" if you prefer, are quickly becoming a very popular hobby, especially for amateur and professional film makers alike. Due to this increased consumer demand, multirotors ranging from tiny palm-size quadcopter toys up to monstrous octocopters can be had for fewer and fewer dollars. Generally, you'll have increased flight time and greater maneuverability with fewer rotors, but at the expense of stability found in systems with more rotors which is often preferable for filming.

Pros:

-very fast

-exciting to watch

-have large supportive communities of builders

-able to take exotic aerial/underwater footage

-the sky is the limit!

Cons:

-expensive

-prone to costly failures or complete losses

-subject to government regulations

-the "sky" may in fact be limited to 400ft above sea level depending on where you live

-must be under user control

Professional Examples: DJI Phantom, OpenROV

Misc

Bristlebots - fast and jittery motorized dental tools that make for a great afternoon project!

BeamBots- simple solar-powered bots that come to life with only a handful of parts!

Step 2: Autonomous or Not?

One of the biggest decisions you'll need to make prior to building a robot is choosing whether or not you want to build an autonomous, remotely controlled, or hybrid system. Let's break down why you'd choose to either (or both) as an approach.

Autonomous Systems

The name says it all, autonomous robots will run on their own without any dynamic user input. Any autonomous system will need some level of sensory input in order for it to run properly and avoid damaging itself. When choosing to build an autonomous system, decide what kind of environment in which the robot will run, what kinds of obstacles it will encounter, and how quickly it will need to react to certain events. The environment will determine what kind of locomotion is necessary for the robot to move properly and the type of chassis you'll need. The obstacles within the environment will determine the appropriate sensors, which must be capable of detecting the obstacles for the robot to react. The reaction time is based on both the robot's locomotion and the obstacles it encounters and further qualifies the right sensors. If the robot is able to detect an obstacle, but unable to react properly before damaging itself or the environment, then you'll need to adjust your build for longer range sensors or find a way to decrease the speed of your robot. Overall, fully autonomous systems require more time to build, but aren't necessarily to most complicated.

I decided to build an autonomous robot for the sake of this instructable as it provides for interesting behavior. I established that it would be in an indoor environment on flat surfaces and would only encounter human hands. With this in mind, I decided to make a wheeled rover which would be paired with a handful of IR distance sensors. The sensors would provide enough feedback for the robot to react properly and the wheel base would be sufficient for wandering around a dry and flat interior.

RC Systems

Remotely controlled robots allow for a more simplified approach to robot building. Sensors may be added to an RC system, but aren't strictly necessary since the machine will be under user control. Due to the wide variety of RC vehicles in the hobby world, you can definitely build an RC robot without writing a single line of code by using an off-the-shelf controller and receiver, attaching motors to it as you will. However, beyond the most basic robots, creating complex motions from a traditional receiver may become quite complex as not all motions relate to the motion of a joystick. When building an RC system, you'll need to think about the type of transmitter you'd like to use for the wireless link and what kind of latency between user input and robot output is acceptable. Standard wireless radio transmitters are great for control, but you'll be subject to the limitations of the transmitters inputs and RF interference from other devices. Bluetooth from a cell phone allows for fast, direct control as well and allows for any UI that can be imagined, but is commonly only reliable for shorter ranges of around 10 meters. A WiFi interface offers a very robust option for controlling robots at almost any distance, however the nature of the network interface is more complex than other radio solutions and is often more power hungry. Infrared transmitters are great, low-cost solutions for direct control and totally immune to RF interference, but require a line-of-sight connection to be of any use.

Hybrid

There are no rules for how a robot must be controlled, as many systems, like quadcopters, offer a mixed approach to robot control. With a proper wireless link and enough on-board sensors, a hybrid system can take user input and sensor input and react in a way that leverages the advantages of both. Systems with complex motion require a hybrid approach to be useful. Most multi-rotor machines offer hybrid control, with the onboard controller reacting to the state of the IMU and adjusting the motors to maintain stability without user input.

Step 3: Robotic Part Resources

Here's the list of parts I used to

Intel Edison w/ Mini Breakout

Zumo robot chassis kit

dual motor driver

(2x) micro metal gear motor

(2x) level shifter

(4x) IR distance sensors

DPDT slide switch

(2x) 1K ohm resistor

(2x) 5mm green LED

(2x) LED panel mount

(4x) AA battery

(x) 4-40 screw

(x) 4-40 standoff

(x) 2-56 screw

(x) 2-56 nut

1'x2' 1/8" black acrylic plate

Below I've linked my top sites for purchasing parts. These are a great reference for many electronic projects!

Trossen Robotics - robot kits, components, sensors, and high end servomotors

ServoCity - very broad motor inventory, modular chassis kits and motor-related breakout boards

Pololu - electronic components, breakout boards, and robot kits

Adafruit - electronic breakout boards, components, sensors, and 3D printing related parts, (Adafruit has tons of tutorials on many hardware/software projects that are very well documented)

Sparkfun - electronic breakout boards, components, sensors, (Sparkfun also has tons of tutorials on many hardware/software projects that are very well documented and hosts an annual Autonomous Vehicle Competition)

RobotShop - a wide variety of electronic parts and kits as well as commercial robots for sale

Parallax- education-focused electronic and robotic kits, sensors, and development boards! (Parallax often stocks huge inventories of all their products, making them great for bulk robot building classes etc.)

Solarbotics - electronic components, kits, and development boards

Arduino - development boards and sensors (Arduino has a huge community of tinkerers and engineers who are constantly sharing their knowledge; the forums and site are a treasure trove of software and hardware information)

SeeedStudio - development boards, sensors, and components

HobbyKing - RC platforms, motors, and batteries

Ebay - everything (old printers and electronics abound, possibly discarded robots as well)

Amazon - everything (Amazon also distributes many components and boards from the suppliers above!)

McMaster - the best website on the internet (genuinely)

Mouser - Almost any electronic component or development board your heart desires and in large quantities

DigiKey - A separate but equally awesome site as Mouser stocking very similar parts (almost any individual component can be found between the two)

Step 4: Mechanical Design

Base

The rover is designed around the Zumo platform, which is a tiny treaded rover. I chose this model because it is compact and easily expandable,. The base has many mount holes, and a built-in battery compartment in the center of the chassis, giving it a nice, low center of gravity for extra stability. The treads provide plenty of traction over a variety of surfaces and stand-out compared to other wheel bases.

Chassis Design

The Zumo is a great start for mounting other electronics. To hold everything else in place, I designed an acrylic chassis that bolts onto the Zumo base. The chassis is designed to be laser cut out of 3mm (~1/8in) acrylic and bolted together with mostly nylon 2-56 and a few metal 4-40 screws. Using plastic (i.e. non-conductive) screws for mounting the electronics reduces the chance of electrical shorts. I've attached the vector files above (if you don't have access to a laser cutter, you can use a service like Ponoko) . Acrylic is rigid and cheap as a body material, but is fairly brittle, so I rounded any edge that might come in contact with an object while the robot is in motion. The chassis is fairly open, consisting of an upper "tower" that provides slots for the mounting plates which hold the Edison, power switch, and motor driver. This design keeps everything visible and easily accessible should I need to disassemble the bot or switch out a component. The bolt-together design allows everything to stay secure, yet removable. Accessibility in design makes troubleshooting far less difficult when it needs to happen,

Step 5: Mechanical Assembly

Above you can see how the chassis goes together sans electronics. This build process is pretty straightforward.

Zumo Assembly - Pololu provides very thorough instructions for building the Zumo base.

Baseplate - mounts to the Zumo base with two 2-56 screws and nuts. Four 4-40 standoffs mount towards the edges.

Sensor Plates - slot into the base. Each sensor pops into a rectangular hole and is secured with a single 2-56 screw.

Upper Base - attaches to the lower base with four 4-40 screws and locks the sensor plates in place.

Motor Driver - mounts with two 2-56 screws with the terminal blocks for the motors facing down. This plate slots into the rear of the one of the tower side plates.

Edison - mounts with four 2-56 with the micro USB ports facing up. This plate slots into the front the tower side plate.

Switch Cover - slots into place at the top of the tower side plate and provides a secure place for the power switch and LEDs.

Step 6: Electrical Design

Above is a hybrid schematic/block diagram for wiring the robot. I've also attached the pin labels for mapping and identifying the proper connections on the Edison breakout board.

Power Supply

The Rover has two separate power supplies, one for logic and the other for motor power. While the AA batteries provide plenty of current to power both the motors and the other electronics, the 6 volt output is too high to power the Edison directly and too low to be regulated by the power circuitry on board. Despite this, having separate power supplies proves to be beneficial as this reduces electrical noise from the EMF generated by the motors. The Edison has built-in lithium-polymer charging circuitry, so this makes powering the logic easy. The Edison converts the 3.7V nominal voltage from the battery to its necessary system voltages and provides a clean 3.3V and 1.8V power supply for the other components. Two green LEDs connect to the separate power supplies and allow quick confirmation that everything has plenty of juice.

Controller

The Edison runs the show for this robot. It's fast, small, and has mounds upon mounds of memory for endless configuration. While I'm using it mostly as a microcontroller, it's really a full-fledged embedded x86 Linux computer! The Edison breakout has plenty of GPIO for connecting to the components as well.

Sensors

Four IR distance sensors provide input for the robot. Each outputs a logic LOW signal when object is detected at 5cm or less. I chose these because they're simple, tiny, and cheap!

Motor Control

The motors are each controlled by a full featured MC33926 which is a rather snazzy H-bridge. These are rated for much more current than the motors can draw, which means it will never run hot and can be used to driver larger motors in the future. You can use a smaller, cheaper driver for these motors, but be wary of running them at their limits!

Motors

Two micro-metal gear motors drive the wheel base. These are relatively low voltage yet provide enough torque to get the robot running quite fast. These are hooked up directly to the motor driver board.

Logic Level Shifters

The Edison's GPIO run at a 1.8V logic level, whereas the sensors and motor driver need at least 3.3V. These shifters take care of translating the Edison's logic to the rest of the board. The 1.8V and 3.3V sources are supplied directly from the breakout board via headers.

Step 7: Electrical Assembly

I began the electronic assembly by soldering male headers to the Edison breakout board, motor driver, sensors, and shifters. A main protoboard with female headers provides a mounting point for the shifters and a power bus for the sensors and motor driver. I extended the wires of the LiPo battery by six inches to enable it to reach the Edison. The connections between the components and the protoboard are all male to female jumper wires, which allows for quick rewiring and testing. You can read more about the jumpers on the motor driver board by following the link on the previous page as it is somewhat complicated.

Step 8: ​Software Design

The rover is an obstacle avoiding robot that will gradually turn to avoid a nearby obstacle and freeze if it's completely unable to move, which should prevent damage.The software for the robot is a basic state-machine, which makes for clear and simple control. After initializing the GPIO directions, the Edison will continuously sense, process, and react endlessly. In this case, the robot's only output is a change in motor direction. The IR sensors have clean digital outputs that are either HIGH or LOW, which makes converting them into simple events that can easily be stored as a boolean state. Due to the short range nature of the sensors, the robot's software is merely reactive to external events. If equipped with a IR or Ultrasonic rangefinder, the robot would be able to proactively determine a path, which would make for more interesting behavior. When starting out, I suggest working with a single type of sensor and learning how well you can process the data from it. Once you're comfortable working with a single kind of input, slowly add more sensors and test them along the way. This approach is much more methodical, but will save you the headache of trying to integrate many different sensors simultaneously, which can be difficult to debug.

//INTEL Intro To Robotics Demo

#define PIN_MOTOR1IN1 4
#define PIN_MOTOR1IN2 5
#define PIN_MOTOR1PWM 6
#define PIN_MOTOR2IN1 7
#define PIN_MOTOR2IN2 8
#define PIN_MOTOR2PWM 9
#define PIN_SENSOR_FRONT_L 0 // front left
#define PIN_SENSOR_FRONT_R 1
#define PIN_SENSOR_REAR_L  2 // rear left
#define PIN_SENSOR_REAR_R  3

#define STATE_TURNING_L 0
#define STATE_TURNING_R 1
#define STATE_FORWARD   2
#define STATE_REVERSE   3
#define STATE_IDLE      4

boolean sensorFrontLActive = false;
boolean sensorFrontRActive = false;
boolean sensorRearLActive = false;
boolean sensorRearRActive = false;

// int driveTime = 4000; // milliseconds

unsigned long curTime = 0;
unsigned long lastTime = 0;
int currentState = STATE_FORWARD;
int lastState = STATE_IDLE;
byte motorSpeed = 64; // max is 255

void setup(){

  pinMode(PIN_MOTOR1IN1, OUTPUT);
  pinMode(PIN_MOTOR1IN2, OUTPUT);
  pinMode(PIN_MOTOR2IN1, OUTPUT);
  pinMode(PIN_MOTOR2IN2, OUTPUT);
  pinMode(PIN_SENSOR_FRONT_L, INPUT);
  pinMode(PIN_SENSOR_FRONT_R, INPUT);
  pinMode(PIN_SENSOR_REAR_L, INPUT);
  pinMode(PIN_SENSOR_REAR_R, INPUT);
  
} // END SETUP ROUTINE

void loop(){
  
  getSensorInput(); // record the raw status of the IR detectors
  currentState = processSensorData(); // decide which state to enter

 /*curTime = millis(); // tiny test routine to run through the states
 if (curTime - lastTime > driveTime){
   lastTime = curTime;
   currentState++;
   if (currentState > 4){
     currentState = 0;
   }
 }*/
 
 if (currentState != lastState){ // only update the driver if something has changed
  lastState = currentState; 
  switch (currentState){
    case STATE_FORWARD:
      moveForward();
    break;
    case STATE_REVERSE:
      moveReverse();
    break;
    case STATE_IDLE:
      idle();
    break;
    case STATE_TURNING_L:
      moveLeft();
    break;
    case STATE_TURNING_R:
      moveRight();
    break;
    default: // idle if processSensorData() made a mistake
      idle();
    break;
  } // END SWITCHCASE  
 } // END IF currentState
 
} // END MAIN LOOP

void getSensorInput(){
 
  sensorFrontLActive = !digitalRead(PIN_SENSOR_FRONT_L); // save the logical NOT state of the digitalRead() because the sensors are active LOW
  sensorFrontRActive = !digitalRead(PIN_SENSOR_FRONT_R);
  sensorRearLActive = !digitalRead(PIN_SENSOR_REAR_L);
  sensorRearRActive = !digitalRead(PIN_SENSOR_REAR_R);
  
} // END FUNCTION getSensorInput()

int processSensorData(){

  //If there is no input, just move forward
  if (!sensorFrontLActive && !sensorFrontRActive && !sensorRearLActive && !sensorRearRActive){
    return STATE_FORWARD;
  }
  // If something is in front of the robot, reverse
  if (sensorFrontLActive && sensorFrontRActive){
    return STATE_REVERSE;
  }
  //If something is on the right while moving forward, turn left
  if (currentState == STATE_FORWARD && sensorFrontRActive){
    return STATE_TURNING_L;
  }
  //If something is on the left while moving forward, turn right
  if (currentState == STATE_FORWARD && sensorFrontLActive){
    return STATE_TURNING_R;
  }
  //If something is on the right while moving in reverse, turn right
  if (currentState == STATE_REVERSE && sensorFrontLActive){
    return STATE_TURNING_R;
  }
  //If something is only on the left while moving in reverse, turn left
  if (currentState == STATE_REVERSE && sensorFrontLActive){
    return STATE_TURNING_L;
  }
  //If all sensors are active, idle in place
  if (sensorFrontLActive && sensorFrontRActive && sensorRearLActive && sensorRearRActive){
    return STATE_IDLE;
  }
/*
(not implemented) 
Accelerate if no obstacles are detected, default to a slow speed if something is detected!
If something is in front of the robot while reversing, speed up!
If something is detected behind the robot, speed up! 
*/<br>

} // END FUNCTION processSensorData()

void moveForward(){ // left = forward, right = reverse
  digitalWrite(PIN_MOTOR1IN1, HIGH);
  digitalWrite(PIN_MOTOR1IN2, LOW);
  analogWrite(PIN_MOTOR1PWM, motorSpeed);
  
  digitalWrite(PIN_MOTOR2IN1, HIGH);
  digitalWrite(PIN_MOTOR2IN2, LOW);
  analogWrite(PIN_MOTOR2PWM, motorSpeed);
}

void moveReverse(){ // left = reverse, right = forward
  digitalWrite(PIN_MOTOR1IN1, LOW);
  digitalWrite(PIN_MOTOR1IN2, HIGH);
  analogWrite(PIN_MOTOR1PWM, motorSpeed);  
  digitalWrite(PIN_MOTOR2IN1, LOW);
  digitalWrite(PIN_MOTOR2IN2, HIGH);
  analogWrite(PIN_MOTOR2PWM, motorSpeed);
}

void moveLeft(){ // left = reverse, right = reverse
  digitalWrite(PIN_MOTOR1IN1, LOW);
  digitalWrite(PIN_MOTOR1IN2, HIGH);
  analogWrite(PIN_MOTOR1PWM, motorSpeed);
  digitalWrite(PIN_MOTOR2IN1, HIGH);
  digitalWrite(PIN_MOTOR2IN2, LOW);
  analogWrite(PIN_MOTOR2PWM, motorSpeed);
}

void moveRight(){ // left = forward, right = forward
  digitalWrite(PIN_MOTOR1IN1, HIGH);
  digitalWrite(PIN_MOTOR1IN2, LOW);
  analogWrite(PIN_MOTOR1PWM, motorSpeed);
  digitalWrite(PIN_MOTOR2IN1, LOW);
  digitalWrite(PIN_MOTOR2IN2, HIGH);
  analogWrite(PIN_MOTOR2PWM, motorSpeed);
}

void idle(){ // motor inputs LOW
  digitalWrite(PIN_MOTOR1IN1, HIGH);
  digitalWrite(PIN_MOTOR1IN2, LOW);
  digitalWrite(PIN_MOTOR1PWM, LOW); 
  digitalWrite(PIN_MOTOR2IN1, HIGH);
  digitalWrite(PIN_MOTOR2IN2, LOW);
  digitalWrite(PIN_MOTOR2PWM, LOW);
}

Step 9: Software Implementation

You'll need the latest version of the Intel Arduino IDE, which you can download here. The code uses no libraries and only basic GPIO, so it should be portable to nearly any Arduino compatible board. The full sketch is attached above. As mentioned in the previous step, the code is fairly basic, but should make for a stable base upon which to add many other behaviors. If you read through, you'll notice a few unimplemented routines in the processSensorData() function. See if you can implement them or experiment to make your own! Once you're keen on creating your own routines, why not try something more advanced by building an obstacle course or maze for your robot and adding pathfindingcapabilities (these are software examples, but can be extended to robots as well).

Step 10: Operation+

I hope you've enjoyed reading this Instructable as I've been thrilled to write it. Robotics as a hobby is only getting easier and more affordable by the day. Robotics as a study incorporates knowledge from many different disciplines, incorporating electrical and mechanical engineering, physics, maths, art, and computer science and is a great practical exercise in each! Check out more robotic projects on the robot section of the Instructables website, or the community of Let's Make Robots, which has tons of detailed articles and countless great members.