Arduino Coffeebots

Arduino Coffeebots

Michael Shiloh

Judy Castro

Contact: teachers@teachmetomake.com

This page can be reached at: bit.ly/coffeebot

Basic Robot

Robot with two light sensors and two motors:

dual_schem

/*
This program makes your robot either seek light or avoid light, depending on how it is wired up.
Try this program first, and then start modifying it to give your robot the personality you desire.
Shine a flashlight, or hold your hand over a light sensor, to change the behaviour.
*/

void setup()
{
  // Set the mode of the digital pins to outputs to drive the motors
  // (the analog inputs are automatically inputs and so don’t need to be set)
  pinMode( 3, OUTPUT ); // motor
  pinMode( 5, OUTPUT ); // motor
}

void loop()
{
  // Compare the two light sensors
  if ( analogRead( 0 ) > analogRead( 2 )  ) // If one light sensor has more light than the other ...
  {
    digitalWrite( 3, LOW ); // turn this motor off ...
    digitalWrite( 5, HIGH ); // and this motor on to turn in one direction
  }

  if ( analogRead( 0 ) < analogRead( 2 )  ) // If the other
  {
    digitalWrite( 3, HIGH ); // turn this motor on
    digitalWrite( 5, LOW ); // and this motor off to turn in the other direction
  }

}

Add an LED

As an example of how to add things to your coffeebot, let’s attach an LED to pin 9.
Remember to use a resistor so that the LED doesn’t burn out:

dualWithLED_schem

And here is how we might use that LED in a program:

/*
This program makes your robot either seek light or avoid light, depending on how it is wired up.
Try this program first, and then start modifying it to give your robot the personality you desire.
Shine a flashlight, or hold your hand over a light sensor, to change the behaviour.

An LED is connected to pin 9; whenever the sensors measure unequal brightness this LED is turned on
*/
void setup()
{
  // Set the mode of the digital pins to outputs to drive the motors
  // (the analog inputs are automatically inputs and so don’t need to be set)
  pinMode( 3, OUTPUT ); // motor
  pinMode( 5, OUTPUT ); // motor
  pinMode( 9, OUTPUT ); // LED
}

void loop()
{
  // Compare the two light sensors
  if ( analogRead( 0 ) > analogRead( 2 )  ) // If one light sensor has more light than the other ...
  {
    digitalWrite( 3, LOW ); // turn this motor off ...
    digitalWrite( 5, HIGH ); // and this motor on to turn in one direction
    digitalWrite( 9, LOW ); // turn off the LED
  }

  if ( analogRead( 0 ) < analogRead( 2 )  ) // If the other
  {
    digitalWrite( 3, HIGH ); // turn this motor on
    digitalWrite( 5, LOW ); // and this motor off to turn in the other direction
    digitalWrite( 9, LOW ); // turn off the LED
  }

if ( analogRead( 0 ) == analogRead( 2 )  ) // If they read the same value
  {
    digitalWrite( 3, HIGH ); // turn this motor on
    digitalWrite( 5, HIGH ); // and this motor too, to go straight
    digitalWrite( 9, HIGH ); // turn on the LED
  }
}

Add an ultrasonic distance measuring sensor

The HC-SR04 is a popular ultrasonic distance measuring sensor. The sensor has two controlling pins: a trigger and an echo.  You can read more about it here. In this example we use the sensor to avoid obstacles in a very simple manner:

const int trigPin = 8;
const int echoPin = 7;
const int leftMotor = 5;
const int rightMotor = 6;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(leftMotor, OUTPUT);
  pinMode(rightMotor, OUTPUT);

  digitalWrite(leftMotor, LOW); // Turn the motors off right away so it doesn't start moving
  digitalWrite(rightMotor, LOW);
}

void loop() {
  long duration, distance;

  // In order to measure a distance, we first send a trigger
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // After sending the trigger, wait for the echo
  duration = pulseIn(echoPin, HIGH);

  // The distance in CM is related to the time until the echo arrived
  distance = (duration/2) / 29.1;

  // Distances of more than 2M or less than zero might be an error; ignore them
  if ( (distance > 200) || (distance < 0))
  {
    digitalWrite(leftMotor, HIGH);
    digitalWrite(rightMotor, HIGH);
  }

  // If the nearest obstacle is closer than 1M away, turn
  else if  (distance < 100)
  {
    digitalWrite(leftMotor, LOW);
    digitalWrite(rightMotor, HIGH);
  }

  // once we've decided what to do, keep doing it for a little while
  delay(200);
}

Add a Text to Speech module and let your Coffeebot speak

Here is an example using the Emic 2 Text-To-Speech module from Parallax (also available at Spark Fun). The module is connected to Arduino digital outputs 2 and 3, and is programmed using the software serial library:

 /*
    Coffeebot using Emic 2 Text-to-Speech Module
*/

// include the SoftwareSerial library 
// so we can use it to talk to the Emic 2 module
#include <SoftwareSerial.h>

const int rxPin = 2;    // Serial input (connects to Emic 2 SOUT)
const int txPin = 3;    // Serial output (connects to Emic 2 SIN)

// set up a software serial port
SoftwareSerial emicSerial =  SoftwareSerial(rxPin, txPin);

void setup()  // Set up code called once on start-up
{
  // define pin modes
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  // set the data rate for the SoftwareSerial port
  emicSerial.begin(9600);

  /*
    When the Emic 2 powers on, it takes about 3 seconds for it to successfully
    initialize. It then sends a ":" character to indicate it's ready to accept
    commands. If the Emic 2 is already initialized, a CR will also cause it
    to send a ":"
  */
  emicSerial.print('\n');             // Send a CR in case the system is already up
  while (emicSerial.read() != ':');   // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
  delay(10);                          // Short delay
  emicSerial.flush();                 // Flush the receive buffer
}

void loop()  // Main code, to run repeatedly
{
  // Speak some text
  emicSerial.print('S');
  emicSerial.print("Hello. This Coffeebot can talk!");  // Send the desired string to convert to speech
  emicSerial.print('\n');

  // Wait until the Emic 2 responds with a ":" 
  // indicating it's ready to accept the next command
  while (emicSerial.read() != ':');   

  // Since we are in loop(), this will speak repeatedly. Delay a bit between utterances.
  delay(5000);
}

Links that might be useful or interesting:

  1. Really nice set of robot tutorials at Robotshop.
  2. I really like mailing lists, and there are plenty on the subjects of robots. Two of my favorites are the Dallas Personal Robotics Group and the Portland Area Robotics Society

Parts List

Robot Chassis Parts List

  1. Coffee can or other suitable container for body
  2. Craft sticks or other suitable materials for structural elements and decoration
  3. Wine corks or other suitable items for front and back caster mounts
  4. Water bottle caps or other suitable items for casters
  5. Zip ties for attaching Arduino to chassis

Robot Electronics Parts List

  • N-chanel logic level MOSFET 12N10L
    Jameco Part no. 1071214
    quantity: 2
  • Gear motor and wheel, Solarbotics GM8 with GMPW wheel deal

    http://www.solarbotics.com/product/gmpw_deal/

    quantity: 2

  • LED (any type)
    e.g. Jameco Part no. 2152112
    quantity: 2
  • Resistor for LED, 330 Ohm or so
    Jameco Part no. 690742
    quantity: 2
  • Photoresistor
    Jameco Part no. 120299
    quantity: 2
  • 150K Ohm Resistor for Photoresistor
    Jameco Part no. 691382
    quantity: 2
  • Arduino Uno or Leonardo, or compatible
  • Battery holder with switch and coax power connector
    Maker Shed MSBAT1
  • 9 Volt Battery

Class Consumables Parts List

  • Wire (all the different colors
  • Solder
  • It is often cheaper to buy some parts such as LEDs, resistors, and photoresistors in bulk

Tools

Here are the basic tools that we find useful when constructing CoffeeBots:

1. A soldering iron. A fine tip is essential. Note the pencil size for comparison:

SAMSUNG

SAMSUNG

You can spend well over $100, but this particular model ($17 at Parts Express) is adequate.

2. Third hand:

SAMSUNG

This device has a pair of alligator clips on flexible arms. While not critical, it is extremely useful for holding things while you solder, for example holding the motor while you solder the wires to the motor terminals:

SAMSUNG

3. Hot melt glue gun:

SAMSUNG

4. Wire cutter, wire stripper, and needle nose pliers:

SAMSUNG

Most importantly, you want the wire cutters to have a small, fine tip, for cutting wires that are close to other wires:

SAMSUNG

That’s about it – it is useful to have other tools on hand but these are the only tools necessary

10 Responses to “Arduino Coffeebots”

  1. MAKE | Mini Maker Faire Action: Coffeebots in Jerusalem Says:

    [...] is getting underway at the Bloomfield Science Museum. California artists and maker teacher team Teach Me to Make (Michael Shiloh and Judy Castro) traveled to Jerusalem as guests and Maker Faire emissaries and [...]

  2. Mini Maker Faire Action: Coffeebots in Jerusalem - IT Clips Says:

    [...] is getting underway at the Bloomfield Science Museum. California artists and maker teacher team Teach Me to Make (Michael Shiloh and Judy Castro) traveled to Jerusalem as guests and Maker Faire emissaries and [...]

  3. - Kosher Tech Salad Says:

    [...] of the things at the Maker Faire was CoffeeBots, small robots which use Arduino based electronics for easy modification and which were being [...]

  4. The Amazing Jerusalem Mini Maker Faire 2013 - Kosher Tech Salad Says:

    [...] of the things at the Maker Faire was CoffeeBots, small robots which use Arduino based electronics for easy modification and which were being [...]

  5. Bob Stanfield Says:

    Augh! This line in the ultrasonic code is a problem. “// Distances of more than 2M or less than zero might be an error; ignore them
    if ( (distance > 200) || (distance 100)”

    It needs to be this way ….. if ((distance > 200) || (distance < 100))

    Great fun!

    • michaelshiloh Says:

      Indeed true. Thanks for catching that! In fact, to agree with the comment, it should be if ((distance > 200) || (distance < 0))

      If you built a Coffeebot please send pictures!

  6. zakakflemvridvika Says:

    great work!
    I’ve written a bluetooth activated version, you can check it out and use it freely if you like:
    http://pastebin.com/gHuaqaPB

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: