How to Make a Gun Controlled Lamp

by austiwawa in Circuits > Arduino

3641 Views, 37 Favorites, 0 Comments

How to Make a Gun Controlled Lamp

569ed44115be4df54a0001c9.jpeg

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

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:

https://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);
    }
  } 
}