Exercise 01 – Electric Magic Hat

Switch exercise

I hacked into a wireless light switch from As Seen on TV, and controlled it with Arduino

Construction:

Switch –> Arduino –> Relay –> Wireless Light Switch (parent)

Wireless Light Switch (child) –> Christmas Lights

Arduino code:

————————————————————————————–

int ledPin = 13; //relay-control pin
int inPin = 2; //read-in pin
int val = 0;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT);
}

void loop()
{
val = digitalRead(inPin);  //read pin 7

delay(100);
if (val == 0)  //if pressed -> randomized flahing
{
digitalWrite(ledPin, HIGH);  //Light On
int TIME = random(50, 300);
delay(TIME);
digitalWrite(ledPin, LOW);  //Light Off
}
else
{
digitalWrite(ledPin, LOW);  //Light Off
}
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s