Soft Switch – Landon Austill

My soft switch program uses a lamp to toggle the two led’s. My circuit was giving me a few problems with the resistors I was using, so I ended up removing one and replacing it with the open switch. Below is a video of me using the lamp to finish the circuit. It isn’t a great connection and it causes the power to go in and out. Halfway through I just touch the two ends to show how it could be.

Code:

const int buttonPin = 5;
const int ledPin = 10;
const int led_Pin = 9;

int buttonState = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(led_Pin, OUTPUT);

pinMode(buttonPin, INPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
digitalWrite(led_Pin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
digitalWrite(led_Pin, LOW);
}
}

IMG_0076.JPG

The objective of my code is to show red LED on when I open the BB cushion.  The green LED is turned on when I press the pad. This motion refers to refill function for the makeup. Screen Shot 2018-01-17 at 0.19.21

 

/*

Button

 

Turns on and off a light emitting diode(LED) connected to digital pin 13,

when pressing a pushbutton attached to pin 2.

 

The circuit:

– LED attached from pin 13 to ground

– pushbutton attached to pin 2 from +5V

– 10K resistor attached to pin 2 from ground

 

– Note: on most Arduinos there is already an LED on the board

attached to pin 13.

 

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. They’re used here to set pin numbers:

const int buttonPin = 12;     // the number of the pushbutton pin

const int ledPin1 = 13;

const int ledPin2 = 11;

// the number of the LED pin

 

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

 

void setup() {

// initialize the LED pin as an output:

pinMode(ledPin1, 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(ledPin1, HIGH);

digitalWrite(ledPin2, LOW);

} else {

// turn LED off:

digitalWrite(ledPin1, LOW);

digitalWrite(ledPin2, HIGH);

}

}

Arduino Soft Switch – Terrence Powell

My switch is connected to a red LED and a green LED.  The green LED is on when the switch is open and once my switch is closed the green LED turns off and the red one begins to blink.  I used graphite, tin foil and salt water as conductors and they were all successful.  However I had to make my graphite line pretty thick because my mechanical pencil isn’t pure graphite. The lecture really helped me in constructing my switch for two LEDs.

Below is a picture of my code:

Screenshot (14)

I combined what I learned from both the Button and Blink examples provided by Arduino.  My LEDs are connected to pins 6 and 7; The switch is connected to pin 2.

// constants won’t change. They’re used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 6; // the number of the LED pin
const int ledPin2 = 7;

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

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) {

digitalWrite(ledPin, HIGH);
delay(321);
digitalWrite(ledPin, LOW);
delay(321);
digitalWrite(ledPin2, LOW);

} else {

digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, HIGH);
delay(321);
}
}