High-5

145

2

2

Published

Introduction: High-5

Project Description

My project is to build an entertaining automated machine, using the Arduino Uno, that will give the user a high-five. For conciseness, the machine will simply be called High-5. Essentially, it will be a placed upon a base behind the 3D printed object. This object of my design is mounted with two sets of red and green LEDs, an LCD screen, and an ultrasonic sensor. On top of the base, attached to a servo motor, is a hollowed plastic rod in which is running a microswitch wire connected to Arduino and breadboard. Perched on top of the plastic rod is a cut-out foam hand embedded with a microswitch to register if contact was made or not. The motor will rotate towards the user, and that will consequentially move the rod towards him in a minor arc motion. Once contact has been made and the microswitch pressed, the High-5 will light up green LEDs, display a positive message, and play a jingle. If the microswitch is not pressed within a delay of time, High-5 will return in the starting position, and display a negative message while lighting up red LEDs.

Step 1: Fit a Microswitch Inside a Foam Hand, and Hook It Up to the Arduino.

Take a square foam and cut it to resemble a hand. In the middle, place a microswitch that has been soldered to long wires, which can be placed through a hollowed plastic rod. The idea is that the motor will move once the ultrasonic sensor detects an object in front of the device.

Step 2: Prepare Two Sets of LED Light

As an amateur, I bunched together a set of red and green LEDs. Each LED has their own pin on the Arduino.

Step 3: LEDs & LCD in Place for Feedback to Your Face.

Install the LEDs and LCD in such a way that when the microswitch is pressed, green LEDs will light up and display a message. Oppositely, if the microswitch is not pressed, it will light up the red LEDs and display a different message.

Step 4: Mount the Arm

Rather self-explanatory. Make sure that the arm is fastened to a servo motor, and that the whole is docked well enough that it can take a light tap, or move the arm, without falling over.

Step 5: Sound Can Be a Feedback Too

Might as well add a Piezo speaker so that when the microswitch is pressed, it will play a nice, encouraging jingle.

Step 6: Device Schematic

The High-5 sure looks like a mess, but it does work. The following schematic should help in viewing what goes to which pin.

Step 7: Software Code.

#include <Servo.h>

Servo myServo;

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Pins used for the LCD

const int trigPin = 9; // pin detects when to start measurements

const int echoPin = 10; // delivers and receives the sonic pulse

const int handSwitch = 13; // microswitch embedded in the hand

long duration;

int distance;

const int greenLED1 = A0; // green LEDs from pin A0 to A2

const int greenLED2 = A1;

const int greenLED3 = A2;

const int redLED1 = A3; // red LEDs from pin A3 to A5

const int redLED2 = A4;

const int redLED3 = A5;

int handSwitchStatus = 0; // When microswitch is open

long t = 0;

int firstSetup = 0; // High-5 in starting position

int speakerPin = 7; // pin used for Piezo speaker

char notes[] = "azbC"; // this code is sourced by ianklatzco @ www.gist.github.com

int length = sizeof(notes); and plays a four-note jingle.

int beats[] = { 2, 3, 3, 16};

int tempo = 75;

void playTone(int tone, int duration) {

for (long i = 0; i < duration * 1000L; i += tone * 2) {

digitalWrite(speakerPin, HIGH);

delayMicroseconds(tone);

digitalWrite(speakerPin, LOW);

delayMicroseconds(tone);

}

}

void playNote(char note, int duration) {

char names[] = { 'c', 'd', 'e', 'f', 'g', 'x', 'a', 'z', 'b', 'C', 'y', 'D', 'w', 'E', 'F', 'q', 'G', 'i' };

// c=C4, C = C5. These values have been tuned.

int tones[] = { 1898, 1690, 1500, 1420, 1265, 1194, 1126, 1063, 1001, 947, 893, 843, 795, 749, 710, 668, 630, 594 };

// play the tone corresponding to the note name

for (int i = 0; i < 18; i++) {

if (names[i] == note) {

playTone(tones[i], duration);

} // end of referred source code

}

}

void setup() {

pinMode(trigPin, OUTPUT); // setup for the ultrasonic sensor, piezo, servo

pinMode(echoPin, INPUT); motor, LCD, microswitch, and LEDs.

pinMode(speakerPin, OUTPUT);

pinMode(greenLED1, OUTPUT);

pinMode(greenLED2, OUTPUT);

pinMode(greenLED3, OUTPUT);

pinMode(redLED1, OUTPUT);

pinMode(redLED2, OUTPUT);

pinMode(redLED3, OUTPUT);

Serial.begin(9600);

myServo.attach(6); // Servo motor on digital pin 6

lcd.begin(16, 2); // activate LCD

pinMode(handSwitch, INPUT); // setup microswitch as input

myServo.write(0); // initial motor position

}

void loop() {

digitalWrite(trigPin, LOW); // ultrasonic sensor deactivated

delayMicroseconds(2);

digitalWrite(trigPin, HIGH); // ultrasonic sensor activated

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH); // reflected pulse and distance traveled

distance = duration * 0.034 / 2; // distance travelled by speed of sound

lcd.clear(); divided in half for the length in one-way

lcd.print("Hey there!"); // initial greeting on LCD

lcd.setCursor(0, 1);

lcd.print("High five?"); // print message on LCD

if (distance < 30) { // distance perimeter that activates High-5

lcd.clear();

lcd.print("Get some!!"); // changes display message

myServo.write(40); // motor goes from 0° to 40°

t = millis();

while ((t + 6000 > millis()) && (firstSetup == 0)) { // initial loop

handSwitchStatus = digitalRead(handSwitch);

if (handSwitchStatus == HIGH) // switch is pressed

firstSetup = 1; // change loop

}

if (firstSetup == 1 ) { // starts positive feedback

lcd.clear();

lcd.print("Atta Boy!"); // positive message

digitalWrite(greenLED1, HIGH); // light green LEDs

digitalWrite(greenLED2, HIGH);

digitalWrite(greenLED3, HIGH);

for (int i = 0; i < length; i++) { // play jingle

if (notes[i] == ' ') {

delay(beats[i] * tempo); // rest

} else {

playNote(notes[i], beats[i] * tempo);

}

}

delay(3000);

myServo.write(0); // return to standby mode

firstSetup = 0; and close LEDs

digitalWrite(greenLED1, LOW);

digitalWrite(greenLED2, LOW);

digitalWrite(greenLED3, LOW);

}

else { // negative feedback (message + lights)

lcd.clear();

lcd.print("Fine, ingrate.");

digitalWrite(redLED1, HIGH);

digitalWrite(redLED2, HIGH);

digitalWrite(redLED3, HIGH);

myServo.write(0); // return to standby mode and close LEDs

delay(6000);

digitalWrite(redLED1, LOW);

digitalWrite(redLED2, LOW);

digitalWrite(redLED3, LOW);

}

}

}

Step 8: A Quick Example (minus the Jingle)

Copyrights and all...

Step 9: Have Fun High Fiving!

Share

    Recommendations

    • Casting Contest

      Casting Contest
    • Woodworking Contest

      Woodworking Contest
    • Oil Contest

      Oil Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    2 Comments

    Had a lot of fun with it in class!

    That's a fun idea! The video link in step 8 is broken but the project looks neat. :)