Midterm: Fairy Garden

Concept:

The concept is of a magical fairy’s garden. A fairy is very shy and when someone touches her hand she gets embarrassed and turns red from blushing. The fireflies in her garden blink with her blushing.

Behavior:

When the fairy is touched, her hand specifically, the FSR sensor behind her is touched. Based on the pressure of the sensor the red LED that’s behind the fairy gets brighter. When the sensor is touched the LEDs behind her also start to blink and they stop when you take off your finger from the sensor/fairy.

I used the input from the sensors to control the LEDs algorithmically through mapping the sensor value to the red LED and blinking the fireflies when touched.

Project:

Schematic:

Program:

//Fairy's sensor pin and value
const int fsrPin1 = 0;
int fsrValue1;

//LED pins, red for blushing on a PWM pin speicifically so it can fade
const int REDPIN = 11;
const int LED1 = 10;
const int LED2 = 9;
const int LED3 = 7;
const int LED4 = 6;
const int LED5 = 5;
const int LED6 = 4;
const int LED7 = 3;

//Boolean to see when the LED lights are on and off to be able to make them blink effectively
bool ledisoff = true;

//Millis, to get the time delay for blinking the LEDs
unsigned long previousMillis = 0;
const long interval = 1000;


void setup() {

  pinMode(REDPIN, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED7, OUTPUT);

}

//function to turn on LEDs instead of having to type it out multiple times
void turnON() {
  analogWrite(LED1, 255);
  analogWrite(LED2, 255);
  analogWrite(LED3, 255);
  analogWrite(LED4, 255);
  analogWrite(LED5, 255);
  analogWrite(LED6, 255);
  analogWrite(LED7, 255);


}
//function to turn off LEDs
void turnOFF() {
  analogWrite(LED1, 0);
  analogWrite(LED2, 0);
  analogWrite(LED3, 0);
  analogWrite(LED4, 0);
  analogWrite(LED5, 0);
  analogWrite(LED6, 0);
  analogWrite(LED7, 0);

}
void loop() {
  //reads sensor input
  fsrValue1 = analogRead(fsrPin1);

  //maps sensor input to an LED light spectrum so when you put pressure on the sensor the spectrum of values is the same as the red LED's spectrum
  fsrValue1 = map(fsrValue1, 0, 980, 0, 255);

  //if the fairy is being touched
  if (fsrValue1 > 0) {
    //the red LED that makes her blush is equivalent to the sensor value
    analogWrite(REDPIN, fsrValue1);

    //starts counting milliseconds
    unsigned long currentMillis = millis();
    //if the period interval passes and the led is off it turns it on and if its on it turns it off
    if (currentMillis - previousMillis >= interval) {
      // save the last time you blinked the LED
      previousMillis = currentMillis;

      if (ledisoff == true) {
        turnON();
        ledisoff = false;
      } else {
        turnOFF();
        ledisoff = true;
      }
    }

  }
  // if the function above stopped while the sensor wasn't being touched, it turns the LEDs off
  if (fsrValue1 == 0) {
    turnOFF();
  }
}

Issues faced and lessons learned:

I found working with mills very difficult, I spent a lot of time trying to figure that out only to realize that it wasn’t working because of silly mistakes such as using a “=“ instead of a “==“. Although this is I also accidentally short-circuited one of the LEDs because of the exposed metal at the top where I soldered so I ended up putting tape to avoid that.

I also learned how people can interact with a project different than I would’ve imagined. To me the project was simple but when people were interacting with it a gathered new insights, this ranges from how people would interact with the fairy by touching, tapping or in other ways. I was also asked some questions that I didn’t think of like if the fireflies would blink faster the more you touch the fairy which wasn’t something that ever popped into my mind. I also would’ve loved to add tone if I had more time where magical music would play when you touched the fairy’s hand.

Side Note:

Although it’s fairly straight forward I used this website to figure out how to use the sensor:

https://learn.adafruit.com/force-sensitive-resistor-fsr/using-an-fsr

 

Leave a Reply

Your email address will not be published. Required fields are marked *