protoPumpkin…

Well… the protoPumpkin was off to a great start despite being fairly different than it’s original concept.  Instead of moving panels, I used one servo motor inside to spin a disk which held the various LEDs.  An IR sensor on front would “agitate” the pumpkin, sending the pumpkin from a state of rest (breathing red LEDs) to a state of agitation, a swatch array of LEDs spiraling around its center. After a few loops it would return to its resting state. In addition, the stem acts as a potentiometer, spinning the disk and creating an even more dynamic effect on the front.  See pictures and videos.

Unfortunately construction was far from perfect and I ran into some major obstacles. Some of which were not completely apparent until final assembly.  The code worked perfectly… but due to the size of the disk, a bizarre servo, and a poorly constructed internal structure (due mainly to the challenges of working inside a pumpkin), the disk and soldered wires kept snagging on each other, eventually tangling, destroying crucial pieces of the pumpkin. Without a functioning IR sensor or the breathing lights… protoPumpkin has unfortunately been reduced to an array of colorful LEDs and a finicky servo motor. For now I’m content to consider it a prototype.

[update] after poking around during class, I discovered a questionable soldering connection for the sensor. Excited, since for some reason the red lights only work if the sensor works, I figured if the connection was made everything would be back up and running… and sure enough after clipping the ground cable to the sensor and resetting its contact with the ground wafer, everything came back online.  Still had obvious issues with the spinning disk and sure enough after a few demonstrations, two more wires were torn from their solder (once again killing the sensor and an additional LED). It was a great first run though and a great learning experience in terms of building within a decaying fruit.






and my code:

/*Proto-Pumpkin
  pComp*/

#include <Servo.h>

Servo myservo; 

int potPin = A1;   //analog pin used to connect the potentiometer
int val;  //variable to read the value from the analog pin

int timer = 500;
int sensorPin = A0;
int sensorValue = 0;
int ledPin = 11;

int brightness = 0;    // how bright the LED is
int fadeAmount = 3;    // how many points to fade the LED by

boolean arraySwitch = false;

int pinArray[] = { //array of pins for colorful lights
  10,9,8,7,6,5,4,2
};
int counter=0;
int count=0;

void setup () {
  Serial.begin (9600);
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  myservo.attach(3);  //attaches the servo on pin 3

  for(int count=0; count<8; count++){
    pinMode(pinArray[count], OUTPUT);
  }
  delay (2000); // it takes the sensor 2 seconds to scan the area around it before it can detect presence.
}

void loop (){

  Serial.println (sensorValue);

  val = analogRead(potPin);  //reads value of potentiometer
  val = map(val, 0, 1023, 0, 179);  //scale it to use with servo
  myservo.write(val);

  sensorValue = analogRead(sensorPin);
  if(sensorValue > 160){
    arraySwitch = true;
  }
  if(arraySwitch == true){
    lightFade();
    counter++;
    if(counter >= 5){   //control how long agitation lasts
      arraySwitch = false;   //turn led array off
      counter = 0;   //reset counter
      brightness = 0;   //reset brightness
     fadeAmount = 5;    //reset fadeamount 
    }
  }
  else {
    lightGlow();
  }

}

//CIRCULAR LED ARRAY
void lightFade(){
  int counter = 0;
  for(int i=0; i<10; i++){
    digitalWrite(pinArray[i],HIGH);
    digitalWrite(pinArray[i-2],LOW);
    delay(80);
  }
}

//BREATHING RED LIGHTS
void lightGlow(){
 analogWrite(ledPin, brightness);
  brightness = brightness + fadeAmount;
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}