Blow Up Doll High Five with Arduino and a Relay

We wanted to make a “high five” bot at work, because…

This was my first test, basically, an arduino runs a sonar range finder, when it detects an object within a certain distance, it activates a relay which allows current to flow into an air pump resulting in the blow up arm extending for a high five!

Here’s the code:

const int pump = 11;
const int pingPin = 7;

long in;

void setup() {
  Serial.begin(9600);
  pinMode(pump, OUTPUT);
}

void loop() {
  in = ping();
  
  if(in < 7) {
    digitalWrite(pump, HIGH);
    // fill the arm
    delay(2000);
  }
 
  digitalWrite(pump, LOW);
  delay(100);

}

long ping() {
  long duration, inches, cm;
  
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  
  inches = microsecondsToInches(duration);
//  cm = microsecondsToCentimeters(duration);
  
  Serial.print(inches);
  Serial.print("in, ");
//  Serial.print(cm);
//  Serial.print("cm");
  Serial.println();
  
//  delay(100);
  
  return inches;
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

If you don’t know how to wire a relay, refer here: http://iwearshorts.com/blog/how-to-wirecontrol-a-relay-with-arduino-or-raspberry-pi/

I used:

  • a JZC-11F relay (5V vcc and 120V rating up to 5 Amps)
  • air pump from amazon
  • ping sonar finder
  • arduino
  • diode
  • leds (for effect)

Leave a Reply

Your email address will not be published. Required fields are marked *