Sketching the bonfire lamp with arduino

First off, to test the blowing interaction we tried it with a readily available photo sensor. It wasn’t really illustrating what we wanted it to, so we explored other options.

 

Continuing our sketching session, we started building the interaction of blowing on a Piezo sensor to light an LED.

We wrote this code to achieve it:

// these constants won’t change:
const int ledPin = 13; // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 500; // threshold value to decide when the detected sound is a knock or not

float averageSensor = 0;

// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}

void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
averageSensor = (averageSensor * 0.99) + (sensorReading * 0.01);
float differenceFromAverage = abs(sensorReading – averageSensor);
Serial.print(sensorReading);
Serial.print(“\t”);
Serial.print(averageSensor);
Serial.print(“\t”);
Serial.println(differenceFromAverage);

// if the sensor reading is greater than the threshold:
if (differenceFromAverage > threshold) {
// update the LED pin itself:
digitalWrite(ledPin, HIGH);
// send the string “Knock!” back to the computer, followed by newline
} else {
digitalWrite(ledPin, LOW);
}
delay(10); // delay to avoid overloading the serial port buffer
}

If the sensor detects a great enough difference in the average measurement, it will light the LED.

Here is a video of the new interaction, using a piezo sensor:

 

For our next step we want to enable ‘blowing up’ the light, like a balloon, which will slowly dim over time.

Leave a comment