Introduction: Remote Controled Rubberband Gun

Haven't you ever wanted to be able to press a button to ward away unwanted intruders? Well now you can with just a few  simple steps, but first you'll need some supplies.

You will need:
- An Arduino board (any model should work)
- A rubber band gun (I just made one out of some wood scraps and a cloth-line clip used as a light trigger)
- A battery pack (at least 9 volts)
- An infrared remote and reciever
- A small servo motor
- Rubber bands
- And tape

Submitted by Powell Middle School for the Instructables Sponsorship Program.

Step 1: Wiring Up the Arduino

1st- hook up the 9g Servo motor to the number 9 pin.
2nd- hook up the infrared receiver to the number 11 pin.
3rd- feel semi-accomplished and make sure it looks something like this..

Step 2: Programming the Arduino

1st-You will need to include the IR library in Arduino (Here is a link)

2nd- Put in the code (Attached)

3rd- Use the #1 button to open the servo and the #2 button to close it


Here is the code-

#include <Servo.h>
#include <Ultrasonic.h>
#include "IRremote.h"

#define TRIGGER_PIN  12 // Ultrasonic sensor TRIGGER
#define ECHO_PIN     13 // Ultrasonic sensor ECHO
#define DISTANCE 20   // in Centimeters
#define WAITING 5000 // in milliseconds so this is 5 second.
#define SERVO_PIN 9
#define CLOSE_POS 90 // servo in CLOSE/UP position
#define OPEN_POS 180 // servo in OPEN/BACK position

  /*-----( Declare Constants )-----*/
  int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11

  /*-----( Declare objects )-----*/
  IRrecv irrecv(receiver);           // create instance of 'irrecv'
  decode_results results;            // create instance of 'decode_results'
  /*-----( Declare Variables )-----*/


//Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);
Servo myservo;  // create servo object to control the PEZ servo

void setup()
{
  Serial.begin(9600);
  myservo.attach(SERVO_PIN);  // attaches the servo to pin
  myservo.write(CLOSE_POS);   // turn servo to CLOSE/UP position
    Serial.println("IR Receiver Raw Data + Button Decode Test");
    irrecv.enableIRIn(); // Start the receiver
}

void loop()
{

   if (irrecv.decode(&results)) // have we received an IR signal?

  {
//    Serial.println(results.value, HEX);  UN Comment to see raw values
    translateIR();
    irrecv.resume(); // receive the next value
  } 
}
//  float cmMsec, inMsec;
//  long microsec = ultrasonic.timing();
//
//  cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
//  inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
//
//// this is for debugging
//  Serial.print("MS: ");
//  Serial.print(microsec);
//  Serial.print(", CM: ");
//  Serial.print(cmMsec);
//  Serial.print(", IN: ");
//  Serial.println(inMsec);
//  delay(1000);
//



//  void setup()   /*----( SETUP: RUNS ONCE )----*/
//
//    //Serial.begin(9600);
//    Serial.println("IR Receiver Raw Data + Button Decode Test");
//    irrecv.enableIRIn(); // Start the receiver
// 
//  }/*--(end setup )---*/
// 

//  void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
//  {
//  if (irrecv.decode(&results)) // have we received an IR signal?
//
//  {
////    Serial.println(results.value, HEX);  UN Comment to see raw values
//    translateIR();
//    irrecv.resume(); // receive the next value
//  } 
//}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
void translateIR() // takes action based on IR code received

// describing Car MP3 IR codes

{

  switch(results.value)

  {

  case 0xFF30CF: 
    Serial.println(" 1              ");
    myservo.write(OPEN_POS);              // tell servo to go to OPEN/BACK
    break;

  case 0xFF18E7: 
    Serial.println(" 2              ");
    myservo.write(CLOSE_POS);              // tell servo to go to CLOSE/UP
    break;

  default:
    Serial.println(" other button   ");

  }

  delay(500);
}

//    myservo.write(CLOSE_POS);              // tell servo to go to CLOSE/UP
//    delay(15);             // waits 15ms for the servo to reach the position
// 
//
//
//    myservo.write(OPEN_POS);              // tell servo to go to OPEN/BACK
//    delay(WAITING);                       // waits sometime to allow grabbing of candy pellet
// 
//
//}

Step 3: Hooking Up the Gun

1st-  Tape the servo to the top of the gun so that the arm moves up when the 1 button is pressed.

2nd- tie/tape a string to the servo arm and gun trigger

3rd- Attach the Arduino and the battery pack to the side of the gun it should look somewhat nice, like this...

Step 4: Test!

Test it! I will attach a video of it operating.