Introduction: Valentines Box

We share Valentine's at my office for team building. Everyone decorates a bag or box to collect the Valentines. Mine was a bit over the top. Shows blue eyes at baseline. Uses IR LED and sensor ( to determine when a card is put through the slot. When that occurs the motor comes on and the card is pulled into the slot by the wheels.

Step 1: Red Eyes

Eyes turn red when card is inserted into slot and motor turns on. The LCD display increments the count of valentines received. 

The bag is the one given to each employee to decorate. I used an Android robot toy from Google. The head comes off. I drilled out the eyes and inserted tri-color LEDs from Radio Shack ( 

There is a ribbon cable  with  going through a hole in the bag and a hole in the lid to connect to the prototype board connected to the Arduino (see next step). The cable as made using a ribbon cable (, and then the LEDs soldered in after stripping one end of the ribbon cables and attaching bare female connectors (, with some shrink tubing used to keep the wires from shorting.

Code is below:

Motor shield

Function pins per Ch. A pins per Ch. B
Direction                D12             D13
PWM                       D3               D11
Brake                      D9               D8
Current Sensing   A0               A1

lcd code from
LCD is 20x4

for Leonardo need to use Serial1 class

const int IRthreshold = 180;
const int IRPin = 3;    // Read IR value on analog 3
const int SignalPin = A2; // send signal to sound Arduino
const int RedPin = A4;
const int BluePin = A5;
boolean cardsensed = false;
boolean LEDflag = false;
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long timestamp = 0;  // used to keep track of how long IR sensor blocked
const long MotorDelay = 500;    // keep motor going for half a second after IR sensor clears
const long LEDdelay = 4000;
int val = 0;
int count = 0;

void setup()
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin
  pinMode(SignalPin, OUTPUT);
  digitalWrite(SignalPin, LOW);
  pinMode(RedPin, OUTPUT);
  pinMode(BluePin, OUTPUT);
  delay(1000); // time to settle in, just in case
  Serial1.print("Happy Valentines Day");
  Serial1.print("        CCE!");
  Serial1.print("I now have:");
  blueLED(); // blue at baseline

void loop()
  val = analogRead(IRPin);
  if (val > IRthreshold)  // path blocked
    cardsensed = true;
    LEDflag = true;
    timestamp = millis();
    //forward @ full speed
    digitalWrite(12, HIGH); //Establishes forward direction of Channel A
    digitalWrite(9, LOW);   //Disengage the Brake for Channel A
    analogWrite(3, 255);   //Spins the motor on Channel A at full speed
    redLED(); // red when it's gotten a card
  if(val < IRthreshold)
      if ((millis()-timestamp) >= MotorDelay)
        cardsensed = false;
        analogWrite(3,0); // turn off motor, but let it coast so no brake
        Serial1.print(" Valentines");
        digitalWrite(SignalPin, HIGH);
        digitalWrite(SignalPin, LOW);
      if ((millis()-timestamp) >= LEDdelay)
        LEDflag = false;
        blueLED(); // back to being sad and blue

///////////////////////////// FUNCTIONS ////////////////////////////////

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial1.write(0xFE);   //command flag
   Serial1.write(128);    //position
void selectLineTwo(){  //puts the cursor at line 2 char 0.
   Serial1.write(0xFE);   //command flag
   Serial1.write(192);    //position
void selectLineThree(){  //puts the cursor at line 3 char 0.
   Serial1.write(0xFE);   //command flag
   Serial1.write(148);    //position
void selectLineFour(){  //puts the cursor at line 4 char 0.
   Serial1.write(0xFE);   //command flag
   Serial1.write(212);    //position
void goTo(int position) { //position = line 1: 0-19, line 2: 20-39, etc, 79+ defaults back to 0
if (position<20){ Serial1.write(0xFE);   //command flag
              Serial1.write((position+128));    //position
}else if (position<40){Serial1.write(0xFE);   //command flag
              Serial1.write((position+128+64-20));    //position
}else if (position<60){Serial1.write(0xFE);   //command flag
              Serial1.write((position+128+20-40));    //position
}else if (position<80){Serial1.write(0xFE);   //command flag
              Serial1.write((position+128+84-60));    //position             
} else { goTo(0); }
void clearLCD(){
   Serial1.write(0xFE);   //command flag
   Serial1.write(0x01);   //clear command.
void backlightOn(){  //turns on the backlight
    Serial1.write(0x7C);   //command flag for backlight stuff
    Serial1.write(157);    //light level.
void backlightOff(){  //turns off the backlight
    Serial1.write(0x7C);   //command flag for backlight stuff
    Serial1.write(128);     //light level for off.
void backlight50(){  //sets the backlight at 50% brightness
    Serial1.write(0x7C);   //command flag for backlight stuff
    Serial1.write(143);     //light level for off.
void serCommand(){   //a general function to call the command flag for issuing all other commands  

void blueLED(){
  digitalWrite(BluePin, LOW); // reverse of usual since common
  digitalWrite(RedPin, HIGH); // anode

void redLED(){
  digitalWrite(BluePin, HIGH);
  digitalWrite(RedPin, LOW);

Step 2: Electronics

Most of circuit (motor, LED, LCD display) is run off of an Arduino Leonardo with an Arduino motor shield. See previous step for code.

The box says "Thank you very much" - it uses an Arduino Duemilanove with a  Sparkfun VoiceBox shield (

Uses a simple signal (raises a pin high on the primary Arduino - senses the signal on the ViceBox Arduino)

has 3 random beeps before and after thank you - sounds a bit like R2D2

code is below

Valentines thank you

     Voice Box part based on code written by Ryan Owens, SparkFun Electronics

//Soft serial library used to send serial commands on pin 2 instead of regular serial pin.
#include <SoftwareSerial.h>

const int UnusedPin = 4; // unused analog pin used to get random input for seed
const int SignalPin = A0; // to get signal from main Arduino
int signal;

//Define the Pin Numbers for the Voice Box part
#define E0  5
#define E1  6
#define E2  7
#define E3  8
#define E4  9
#define E5  10
#define E6  11
#define E7  12
#define RDY  13
#define RES  3
#define SPK  4
#define txPin  2

//Create a SoftSerial Objet
SoftwareSerial speakjet = SoftwareSerial(0, txPin);

char speakjetsetup[] = {20, 96, 21, 114, 22, 88, 23, 5, 0}; // for whatever reason Voice Box only seems to
                                                            // work correctly if lines end in 0

                                  //thank                                you            very                             much
char thankyou[] = {169, 8, 130, 142, 196, 6, 8, 160, 6, 166, 150, 7, 128, 6, 140, 134, 15, 8, 182, 0};

char pause[] = {5, 0}; // 5 = 60ms pause; 0 to end line

////////////////////////// SET UP ////////////////////////////////////////////
void setup() {
  pinMode(SignalPin, INPUT);

  //Configure the pins for the SpeakJet module
  pinMode(txPin, OUTPUT);
  pinMode(SPK, INPUT);
  //Set up a serial port to talk from Arduino to the SpeakJet module on pin 3.
  //Configure the Ready pin as an input
  pinMode(RDY, INPUT);
  //Configure Reset line as an output
  pinMode(RES, OUTPUT);
  //Configure all of the Event pins as outputs from Arduino, and set them Low.
  for(int i=E0; i<=E7; i++)
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  //All I/O pins are configured. Reset the SpeakJet module
  digitalWrite(RES, LOW);
  digitalWrite(RES, HIGH);
  //send setup commands to SpeakJet
  delay(5000); // allow things to settle down

////////////////////////// LOOP ////////////////////////////////////////////
void loop()
  signal = digitalRead(SignalPin);
  if (signal == HIGH)
    // redLED();
    // delay(3000);
    // blueLED();
} // end of loop

///////////////////////////// FUNCTIONS ////////////////////////////////

void randombeeps(int beeps)
  for (int k=0; k<beeps; k++) // generate number of beeps
    int rndnum = random(220, 230); // maps to  beep sounds on voicebox, 220-229
    char rndchar = char(rndnum);

void blueLED(){
  digitalWrite(BluePin, HIGH);
  digitalWrite(RedPin, LOW);

void redLED(){
  digitalWrite(BluePin, LOW);
  digitalWrite(RedPin, HIGH);

Step 3: Gearing

Tricky part was the gears. I used Vex parts that I had on hand. in order to get both top and bottom wheels to spin I had to angle the gears. Note that the large gears are on a beam that is angles to engage the gears on the wheel axles. 

The Vex motor works fine with the Arduino motor shield.

Step 4:

For power I used a 9V regulated power supply. Even though the Vex motor is nominally 7V it worked OK (it was only on for brief periods). I used an Adafruit jack ( and some wire to bring the power to the Vin and ground terminal blocks (center positive). 

The whole thing is contained in a plastic storage box I got on sale at Office Depot. 


About This Instructable




Bio: Favorites enjoy robotics, python, Raspberry Pi, Arduino, and making in general.
More by kwoeltje:AdaBox004 Music PlayerRobot Test StandYAAR - Yet Another Autonomous Robot
Add instructable to: