Input/Output Coincidence: Candle on, Candle off

Assignment: Input / Output Coincidence Lab Assignment

Collaborators:

Description

My project tries to replicate the actions used in lighting and blowing out a candle with a photocell, an LED, and a Piezo speaker. To light the candle, a "match" (in this case, a flashlight made to look like a match), is shined on the candle holder. This turns an LED within the candle holder on. I adapted the Knock code in order to get input from the Piezo speaker. I set the Piezo speaker is set to register very low levels of vibration, so a forceful blow turns the LED off (i.e. blowing out the candle).

Components Used

  • Light Emitting Diode (LED)--red
  • 220 ohm resistor
  • 10k resistor
  • 1M resistor
  • Arduino board
  • Bread board
  • Wires
  • Photocell
  • Piezo speaker
  • Flashlight
  • Candle holder
  • Electrical tape
  • Coffee filter (for LED diffusion)

Arduino Code

 

/* Piezo candle

* A photocell activates an LED when enough light is provided (by a "match").

* A piezo registers the vibration of a forceful blow to turn the LED off.

*/

 

const int ledPin = 13;      // led connected to digital pin 13

const int blowSensor = 0;  // the Piezo is connected to analog pin 0

const int threshold = 5;  // threshold value to decide when vibration is detected

const int lightSensor = 2; // the photocell is connected to analog pin 2

 

int sensorReading = 0;      // variable to store the value read from the sensor pin

int val = 0; //variable to store the value coming from the photocell

 

void setup() {

pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT

}

void loop() {

// read the sensor and store it in the variable sensorReading:

val = analogRead(lightSensor); //read the value from the photocell

if (val > 400) {

// update the LED to be on

digitalWrite(ledPin, HIGH);

}

sensorReading = analogRead(blowSensor);

// if the sensor reading is greater than the threshold:

if (sensorReading >= threshold) {

// update the LED pin to be off

digitalWrite(ledPin, LOW);

}

delay(100);  // delay

}

Photos

Set up

Candle holder with Piezo, LED, and photocell

Flashlight "match"

Lit LED

 

Video