Pumpkinduino Part 4: The final hardware and software put together

Previous Post: Pumpkinduino Part 3

Ok, I procrastinated, got distracted, then got sick with one of those icky colds that you just can’t shake, so the final product kind is not really all that good.   On the other hand you can pull the parts out of your Arduino pile, since I didn’t use the Galileo in the final product. 

Software

Well nothing like procrastination to get you into trouble, but I did manage to find some ideas like the “Pimp your Pumpkin” by Matt Makes.  I didn’t use his ultrasonic range detector software, maybe the code at Arduino.cc for the range finder has improved since he wrote the code.  Also, I didn’t bother with the capacitor, the newer software seems have noise cancellation.  On the other hand  I did use his two LED approach and range finder, but not the buzzer, my buzzer had a broken lead, so engineering decision: toss out the buzzer.  Which is ok, since my dog hates the buzzer sound.  If your buzzer is working then use it.

image

You could Matt Richardson’s software, which I couldn’t get to work with my range finder or you could use mine, which is lightly modified from:

//Code starts here

#define CANDLELED 6
#define REDLED 3

const int PINGPIN= 7;
long previousMillis = 0;
long closeReadings = 0;

void setup() {
        Serial.begin(9600);
    pinMode(CANDLELED, OUTPUT);
    pinMode(REDLED, OUTPUT);
    pinMode(BUZZER, OUTPUT);
    pinMode(SENSOR, INPUT);
}

void loop()
{
   // establish variables for duration of the ping,
   // and the distance result in inches and centimeters:
   long duration, inches, cm;

   // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
   // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
   pinMode(PINGPIN, OUTPUT);
   digitalWrite(PINGPIN, LOW);
   delayMicroseconds(2);
   digitalWrite(PINGPIN, HIGH);
   delayMicroseconds(5);
   digitalWrite(PINGPIN, LOW);

   // The same pin is used to read the signal from the PING))): a HIGH
   // pulse whose duration is the time (in microseconds) from the sending
   // of the ping to the reception of its echo off of an object.
   pinMode(PINGPIN, INPUT);
   duration = pulseIn(PINGPIN, HIGH);

   // convert the time into a distance
   inches = microsecondsToInches(duration);
   cm = microsecondsToCentimeters(duration);
   if (inches < 48){
     digitalWrite(CANDLELED, LOW);
     digitalWrite(REDLED, HIGH);
   } else
   {
     digitalWrite(CANDLELED, HIGH);
     digitalWrite(REDLED, LOW);
   }
    
   Serial.print(inches);
   Serial.print("in, ");
   Serial.println();
  
   delay(100);
}

long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second).  This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: https://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
   // The speed of sound is 340 m/s or 29 microseconds per centimeter.
   // The ping travels out and back, so to find the distance of the
   // object we take half of the distance travelled.
   return microseconds / 29 / 2;
}

//end of code

Hardware

My pumpkin is quite a bit smaller than Matt’s.  I directly soldered the LEDs to wires connected to the digital write pins on the Arduino protoboard and then attached the protoboard  to the Arduino.  Since the Protoboard has extra 5 volt and ground connections the DuPont wires from the LEDs and Ultrasonic Range,  Finder were easy taped to the inside of the pumpkin.  (DuPont wires are a good addition to your toolbox if you aren’t using them, get the ones that are in a flat cable then you can tear off a few to make a nice run in your project, really cleans things up!).

image

Why not the Galileo?

Pretty simple, you could use the Galileo version 2 since it has a voltage regulator, but since I have the version 1, and I didn’t have a voltage regulated battery supply large enough to support the Galileo’s current requirements, I had to make the switch to the Arduino.  This was unfortunate since it turns out that the Galileo’s ability to support threads would have been a nice to have for the Ultrasonic rangefinder, not necessary but nice.  So from an engineering point of view I dropped the Galileo for this go around.  However, since I used a protoboard the simple electronics can be moved from the Arduino to the Galileo with no effort.

Why not the Launchpad?

Power supply issues again.  This points to a problem in my physical toolbox that I need to add some phone battery extenders, these work well with many devices.  My current one is a sealed package the batteries had gone flat.

Conclusion

This project is an example of what procrastination leads to in technology: Kind of boring solutions.  Now I met my goal of building the Pumpkinduino, but certainly not the way I wanted it to come out, I had plans for a much better product.  I really wanted this to be a good project, and I didn’t make it happen, I let the clock run out. 

On the other hand, if you want to pull together an Arduino project quickly tonight between getting home and waiting for your buddies to get their costumes on, this is a quick and easy project, use Matt Robinson’s code for the flickering LED, which I didn’t.  Use the Arduino.cc code referenced for your Ultrasonic Range Finder. 

And don’t be a creep and procrastinate.  Urrgghhh.