Ryan’s Switch

My code is from the button example, I tweaked it a little bit by adding a second LED. So that one LED is on when there is a connection and the other LED turns on when there is no connection.

created 2005

by DojoDave <http://www.0j0.org&gt;

modified 30 Aug 2011

by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button

*/

// constants won’t change.

const int buttonPin = 2;     

const int ledPin =  13;     

const int ledPin2 = 11;

// variables will change:

int buttonState = 0;         

void setup() {

 // initialize the LED pin as an output:

 pinMode(ledPin, OUTPUT);

 pinMode(ledPin2, OUTPUT);

 // initialize the pushbutton pin as an input:

 pinMode(buttonPin, INPUT);

}

void loop() {

 // read the state of the pushbutton value:

 buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.

 // if it is, the buttonState is HIGH:

 if (buttonState == HIGH) {

   // turn LED on:

   digitalWrite(ledPin, HIGH);

   digitalWrite(ledPin2, LOW);

 } else {

   // turn LED off:

   digitalWrite(ledPin2, HIGH);

   digitalWrite(ledPin, LOW);

 }

}

Here I have my circuit set up. I have pin 11 and 13 setup to the LED’s. And pin 2 is where the UNO receives its signal of connection.

My switch is a conductive material. I have alligator clips connected to each side. When it’s stretched, the material forms a direct connection and lights up the other LED.

Here I have a water bottle that creates the direct connection with its own weight. As you can see from the pictures above, when the water bottle is on the ground the other LED lights up.

img_2288img_2289img_2294img_2295

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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