loading

Hello!

In this tutorial I will be explaining how I made my gun controlled lamp. The lamp is controlled by an IR remote. You can watch this tutorial on Youtube at:

https://www.youtube.com/channel/UCkURR2CLd5iDc0B11...

Parts List:

- Arduino Uno

- 2.1mm plug with a 9V battery clip - 5V relay module

http://www.ebay.ca/itm/5V-One-1-Channel-Relay-Modu...

- High torque servo motor (I used a Hitec HS-5755MG) - IR sensor and remote

http://www.ebay.ca/itm/1Pc-New-Infrared-IR-Wirele...

- Switched 6V battery pack

- 2 L brackets

- Light socket with power chord

- Light bulb - 1 1/2 PVC pipe

- 1 1/2 trap adapter

- Project box

- Lamp shade

- Toy gun

- Hardware/tools

Step 1: Arduino Code

The IRremote library can be downloaded from the following link if you do not already have it.

https://brainy-bits.com/tutorials/ir-remote-arduin...

Also, depending on which IR remote you are using you may have to insert different code values for the buttons on your remote. For example, in the code posted below the value for the OK button on my remote was "0xFF02FD". If you are going to use a different remote than what I used you will need to figure out the proper values for its buttons. You may be able to figure this out by doing some research on google, or you can download an IR decoder sketch. There are many tutorials out there on how to do this.

If you are having troubles with any of this "FoamboardRC" has an excellent instructable on using IR remotes with Arduino. Here is the link to his instructable:

http://www.instructables.com/id/The-Easiest-Way-to...

Code:

//Gun Lamp
//By: austiwawa
#include <Servo.h> 
#include <IRremote.h>
unsigned long Value1 = 0xFF02FD; // where XXXXXXXX is on our your remote's values (OK button)
int relay_pin = 13;
int recv_pin = 11;
int actual_state = LOW;
// Postions for even, odd clicks
const byte oddPosition = 84;
const byte evenPostion =  40;
int clickCount = 0; // # of clicks
IRrecv irrecv(recv_pin);
decode_results results;
Servo servo1;
void setup() {
  pinMode(relay_pin, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo1.attach(9); // attach servo to digital pin 9
}
void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    if (results.value == Value1) { //  button
      actual_state = (actual_state == LOW) ? HIGH : LOW;
      digitalWrite(relay_pin, actual_state);
    }
    irrecv.resume(); // Receive the next value
    if(results.value == Value1) {
      // increment click count
      clickCount++;
      // move to even or odd position based on click count
      servo1.write( (clickCount % 2) ? oddPosition : evenPostion);
    }
  } 
}
<p>Great idea! It would be even better if the IR remote would be in the gun and the button press would be the trigger of the gun. But You just got yourself a new follower. Keep on making things like this!</p>
<p>I was actually planning on doing that when I thought this project up. But things didnt go as planned. Thank you very much, I appreciate it!</p>
<p>I have two questions: You have two #include statements but no referenced libraries. Is that a typo? Also, How did you derive the remote's value for the OK button?</p>
<p>Thank you for asking. I should have included this. I downloaded the library as well as got a list of the remotes button values from the following link. I will add this into my tutorial. </p><p><a href="https://brainy-bits.com/tutorials/ir-remote-arduino/" rel="nofollow">https://brainy-bits.com/tutorials/ir-remote-arduin...</a></p>
<p>I will also fix the type in the code. Thanks for pointing that out!</p>
<p>I really love the combination of the lamp being turned off and it tipping over. Just perfect :)</p>
<p>Thank you very much :) I am happy to hear that you enjoyed it!</p>

About This Instructable

1,253views

31favorites

License:

Bio: Hello and welcome! My name is Austin. I enjoy creating interesting projects and sharing my projects and ideas with all of you. Please feel free ... More »
More by austiwawa:Burning Words Into Wood With Electricity Make your own Rocket Cannon - Shoot 3D Printed Rockets over 100 FEET!  Making Lichtenberg Figures in Wood 
Add instructable to: