BattleBot, my Stupid Pet Trick!
Destroyer of all, unless you have opposable thumbs and are stronger than an average cardboard box.
Initially, my idea was to create a friendly robot that would be wrapped in a capacitive sensor and require the user to essentially tickle the robot to illicit a reaction of some sort. But after working on it after some time, I found a more realistic and appealing idea. I instead decided to make a robot that would switch between two states, peaceful and battle mode!
Fig 1: Toggle Switch
Battle mode is activated when the toggle sw
itch is switched to on.
I wanted the robot to seem friendly when in peaceful mode, so I decided to make its eyes a nice cool blue when the toggle switch was turned off. But I also wanted the user to see a significant difference when switched to battle mode. I considered using two RGB LEDs, but that would use up 3 pins for each eye. So I essentially hardcoded two colors in each eye by placing two LEDs, a blue one and a red one. An eye would be made of a ping pong ball with both LEDs resting inside.
Figure 2: Ping pong ball and LEDs
Although noticeable, I felt this switch between the modes was not meaningful enough. Therefore, I blinked the LEDs 3 times whenever switching modes, seeming as if it’s booting up.
In order to implicitly tell the user that this robot is indeed intended for mass destruction, I armed the BattleBot with two arms made of tabasco boxes that would consistently move up and down no
nstop when in battle mode.
Figure 3: Tabasco box
In order to make the arms move fast and support the weight of the boxes, I used 2 5V servos.
Figure 4: 5v Servo
The entire body of the BattleBot is composed of a mixed honey roasted nuts container (I brought from home)
and the head was made of a popcorn box (bought from the convenience store) and neck made out of a toothpaste box. A speaker was placed inside the head and serves to play a chime when first turning on the robot and switching between modes.
Figure 5: Toothpaste box used for neck
So initially this was all there was going to be to my BattleBot, but fortunately Scott came along and inspired me to go a but further. He offered a bunch of suggestions, but I ended up doing something I made up. I added a potentiometer directly into the lid which added endless possibilities.
I decided to make the potentiometer blink the LED eyes between blue and red and as you turned the meter, the blink rate would increase. In battlemode, the BattleBot will attempt to protect itself and swing its arms covering the potentiometer. If you successfully turn it enough, its eyes turn purple and music will play, signifying that you won.
Video:
Edit: Updated video
Circuit Diagram:
Code:
#include <Servo.h> #include "pitches.h" int bluePinLeft = 2; int bluePinRight = 3; int redPinLeft = 5; int redPinRight = 6; int switchButtonPin = 7; int selfDestructPin = A0; boolean battleModeOn = false; boolean firstTime = true; boolean previous = false; boolean defeated = false; Servo myServoLeft; Servo myServoRight; // notes in the melody: int melody[] = { NOTE_C4, NOTE_G3, NOTE_E2, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; void setup() { // put your setup code here, to run once: pinMode(bluePinLeft, OUTPUT); pinMode(bluePinRight, OUTPUT); pinMode(redPinLeft, OUTPUT); pinMode(redPinRight, OUTPUT); pinMode(switchButtonPin, INPUT); pinMode(selfDestructPin, INPUT); pinMode(4, OUTPUT); digitalWrite(4, HIGH); myServoLeft.attach(10); myServoLeft.write(0); myServoRight.attach(11); myServoRight.write(45); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: if (firstTime) { for (int i = 3; i > 0; i--) { digitalWrite(bluePinLeft, HIGH); digitalWrite(bluePinRight, HIGH); tone(8, melody[i], 100); delay(50); digitalWrite(bluePinLeft, LOW); digitalWrite(bluePinRight, LOW); delay(50); } firstTime = false; } Serial.print("Battle Mode: "); Serial.println(battleModeOn); Serial.print("Previous: " ); Serial.println(previous); if (battleModeOn) { if (digitalRead(selfDestructPin) == HIGH) { Serial.println("SELF DESTRUCT"); //tone(8, melody[random(0,7)], 100); digitalWrite(redPinLeft, HIGH); digitalWrite(redPinRight, HIGH); digitalWrite(bluePinLeft, HIGH); digitalWrite(bluePinRight, HIGH); if (!defeated) { tone(8, melody[0], 100); delay(200); tone(8, melody[1], 100); delay(200); tone(8, melody[2], 100); delay(200); tone(8, melody[0], 100); delay(500); //myServoLeft.write(180); //myServoRight.write(0); digitalWrite(redPinLeft, LOW); digitalWrite(redPinRight, LOW); digitalWrite(bluePinLeft, LOW); digitalWrite(bluePinRight, LOW); for (int i = 0; i < 3; i++) { digitalWrite(bluePinLeft, HIGH); digitalWrite(bluePinRight, HIGH); tone(8, melody[i], 100); delay(50); digitalWrite(bluePinLeft, LOW); digitalWrite(bluePinRight, LOW); delay(50); } exit(0); } } else { digitalWrite(redPinLeft, HIGH); digitalWrite(redPinRight, HIGH); digitalWrite(bluePinLeft, LOW); digitalWrite(bluePinRight, LOW); myServoLeft.write(45); myServoRight.write(45); //tone(8, melody[NOTE_C4], 50); delay(200); myServoLeft.write(0); myServoRight.write(0); //tone(8, melody[random(0,7)], 100); delay(200); } } else { Serial.print("potent: "); int reading = analogRead(selfDestructPin); Serial.println(reading); if (reading > 256) { //myServoLeft.write(0); //myServoRight.write(0); //delay(200); Serial.println("SELF DESTRUCT"); //tone(8, melody[random(0,7)], 100); digitalWrite(redPinLeft, HIGH); digitalWrite(redPinRight, HIGH); digitalWrite(bluePinLeft, LOW); digitalWrite(bluePinRight, LOW); tone(8, melody[3], 100); delay(1024 - reading); digitalWrite(redPinLeft, LOW); digitalWrite(redPinRight, LOW); digitalWrite(bluePinLeft, HIGH); digitalWrite(bluePinRight, HIGH); tone(8, melody[1], 100); delay(1024 - reading); //reading = map(reading, 0, 1023, 0, 180); //myServoLeft.write(reading); //myServoRight.write(reading); //delay(200); //exit(0); } else { digitalWrite(redPinLeft, LOW); digitalWrite(redPinRight, LOW); digitalWrite(bluePinLeft, HIGH); digitalWrite(bluePinRight, HIGH); noTone(8); //delay(100); } } if (digitalRead(switchButtonPin) == HIGH) { if (!previous) { digitalWrite(bluePinLeft, LOW); digitalWrite(bluePinRight, LOW); for (int i = 0; i < 3; i++) { digitalWrite(redPinLeft, HIGH); digitalWrite(redPinRight, HIGH); tone(8, melody[i], 100); delay(50); digitalWrite(redPinLeft, LOW); digitalWrite(redPinRight, LOW); delay(50); } digitalWrite(redPinLeft, HIGH); digitalWrite(redPinRight, HIGH); /*for (int thisNote = 0; thisNote < 8; thisNote++) { // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000 / noteDurations[thisNote]; tone(8, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(8); }*/ } battleModeOn = true; } else { if (previous) { digitalWrite(redPinLeft, LOW); digitalWrite(redPinRight, LOW); digitalWrite(bluePinLeft, HIGH); digitalWrite(bluePinRight, HIGH); for (int i = 3; i > 0; i--) { digitalWrite(bluePinLeft, HIGH); digitalWrite(bluePinRight, HIGH); tone(8, melody[i], 100); delay(50); digitalWrite(bluePinLeft, LOW); digitalWrite(bluePinRight, LOW); delay(50); } // myServoLeft.write(0); // myServoRight.write(0); // delay(100); // myServoLeft.write(45); // myServoRight.write(45); // delay(100); } battleModeOn = false; } previous = battleModeOn; }