Happy Hack Light Switch

81

Posted

Introduction: Happy Hack Light Switch

For the last 2 weeks we have worked on a school project called "Happy hacking". With this project we tried to make a "Happy hack" for a public space. Well, what is a "Happy hack"? In our case we needed to make something positive based on a frustration. The use of Arduino was required for this project. The "Happy hack" we decided to make was an installation to remotely flip the light switch.

Step 1: Materials:

1x Arduino Uno

1x Breadboard

2x servo

1x infrared sensor

11x wire

1x infrared sender (tv remove)

tape

Step 2: How to Connect:

Put an Arduino infrared receiver into the breadboard; assuming the front side of the receiver is the side with the sphere on it:

  • Connect one wire from the most left ‘leg’ to the Arduino uno port ‘6’.
  • Connect one wire from the middle ‘leg’ to the ‘-’ row in the breadboard.
  • Connect one wire from the most right ‘leg’ to the ‘+’ row in the breadboard.

Make sure a wire is between the ‘-’ row in the breadboard and a ‘ground’ port on the Arduino uno and make sure a wire is between the ‘+’ row in the breadboard and the ‘5V’ port on the Arduino uno.

Now connect the 2 servos,

  • Both with a wire from the darkest wire on the servo to the ‘-’ row on the breadboard.
  • Both with a wire from the middle wire on the servo to the ‘+’ row on the breadboard.

Now, for one of the servos connect the remaining servo wire to the Arduino uno port ‘9’ and connect the other servo to the Arduino uno port ‘10’.

Step 3: Code:

#include<IRremote.h> //

#include<IRremoteInt.h> //

#include<Servo.h> //

IRrecv irrecv(6);

decode_results results;

Servo theServo1;

Servo theServo2;

bool lightOn = false;

bool disco = false;

void setup(){

theServo1.attach(10);

theServo2.attach(9);

pinMode(6,INPUT);

Serial.begin(9600);

irrecv.enableIRIn(); // Start the receiver

irrecv.blink13(true);

}

void loop(){

if (irrecv.decode(&results)) {

Serial.println(results.value); // You get a different result for every button. So check in the serial monitor what your buttons value is.

if (results.value == 3772793023){ // This is our power button result (3772793023). This is probably different with your remote.

lightOn = !lightOn;

if(lightOn){

theServo1.write(65);

theServo2.write(15);

}

if(!lightOn){

theServo1.write(95);

theServo2.write(95);

}

delay(1000);

}

if (results.value == 3772839943){ // This is our info button result (37728).

disco = !disco;

delay(1000);

}

Serial.println(results.value);

irrecv.resume(); // Receive the next value

}

if(disco){

lightOn = !lightOn;

if(lightOn){

theServo1.write(65);

theServo2.write(15);

}

if(!lightOn){

theServo1.write(95);

theServo2.write(90);

}

delay(2000);

}

}

Share

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Paper Contest 2018

    Paper Contest 2018
  • Gluten Free Challenge

    Gluten Free Challenge
user

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

Tips

Questions

Comments