Lab 5: Reactive Flower

Description

This rose responds to specific interactions. When a bug lands near the bloom, it turns on, pulsing white light. When a face comes near to the leaf (giving CO2), it calmly pulses blue light. And if you try to pick the flower, squeezing the base of the stem with moderate pressure, it flashes red light. At higher pressure, this flashing is accompanied by a blaring warning sound.

Components

  • Arduino
  • Breadboard
  • 2 photosensors
  • 1 force sensitive resistor (FSR)
  • 1 red, 1 blue, and 1 white LED
  • 1 piezo speaker
  • hookup wires
  • paper, straws, tape

Code

/*
controls various inputs and output to an origami flower
By Leah Rosenbaum
*/

int pullSensor = A0; // force sensor at the base of the stem
int bugSensor = A2; // photo sensor for presense of bug on the calyx
int proximitySensor = A1; // photo sensor for proximity of face to leaf

// select the pins for LED output:
int redPin = 11;
int whitePin = 9;
int bluePin = 10;
int piezoPin = 7;

int pullValue = 0; // stores value coming from the pull/force sensor
int bugValue = 0; // stores value coming from the photo/bug sensor
int proximityValue = 0; // stores value coming from the photo/proximity sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(whitePin, OUTPUT);
pinMode(piezoPin, OUTPUT);

Serial.begin(9600);
}

void loop() {
digitalWrite(piezoPin, LOW);

pullValue = analogRead(pullSensor); // read the value from the force sensor
bugValue = analogRead(bugSensor); // read the value from the photo/bug sensor
proximityValue = analogRead(proximitySensor); // read in the value from the photo/proximity sensor

Serial.print("pull value:");
Serial.println(pullValue);
Serial.print("bug value:");
Serial.println(bugValue);
Serial.print("proximity value:");
Serial.println(proximityValue);

if ( pullValue > 700) { //if pulling too hard on the stem
allOff();

//flash the red LED and buzz piezo:
digitalWrite(redPin, HIGH); //turn on red LED
buzzPiezo(1000);
delay(25);

digitalWrite(redPin, LOW); //turn off red LED
buzzPiezo(1000);
delay(25);
}
else if (pullValue > 500) { //touching the stem
allOff();

//flash the red LED:
digitalWrite(redPin, HIGH);
delay(150);
digitalWrite(redPin, LOW);
delay(150);
}
else { //minimal force input
if (proximityValue < 800){ //and proximity to leaf
allOff();

//pulse blue:
fadePin(bluePin, 15, 30);
}
else { //minimal proximity input
if (bugValue < 900){
allOff();

//pulse the white LED:
fadePin(whitePin, 5, 30);
}
}
}
delay(500);
}

void buzzPiezo(int delayTime){
for( int i=0; i<250; i++ ) { // play it for 50 cycles
digitalWrite(piezoPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(piezoPin, LOW);
delayMicroseconds(delayTime);
}
}

void fadePin(char pinName, int fadeStep, int waitTime){
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += fadeStep) {
analogWrite(pinName, fadeValue);
delay(waitTime); // wait to see the dimming effect
}
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= fadeStep) {
analogWrite(pinName, fadeValue);
delay(waitTime); // wait to see the dimming effect
}
}

void allOff(){
digitalWrite(redPin, LOW);
digitalWrite(bluePin, LOW);
digitalWrite(whitePin, LOW);
digitalWrite(piezoPin, LOW);
}

Images

responsive-flower

Leave a Reply