Raynor/ Soft Switch

I made a switch to toggle different lights whenever the circuit was open or closed. When I closed the circuit, a blue light is illuminated. When the circuit is broken, the red light becomes illuminated.img_2413Here is the code for the project:

const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 12; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(11, 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 == LOW) {
// turn RED on:
digitalWrite(ledPin, HIGH);
digitalWrite(11, LOW);
} else {
// turn BLUE off:
digitalWrite(ledPin, LOW);
digitalWrite(11, HIGH);


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