Friday, May 19, 2017

Working with Organs and Arduino

Sometime in mid-October I received a call from my friend asking for a 3d printed brain, heat, and set of lungs.  I thought about it for a moment and told her that I could make it pretty cool...and that's how one of my favorite projects was started. 

Finding the STLs to use wasn't too hard, making them usable was a little more difficult.
  • Heart - http://www.thingiverse.com/thing:932606
  • Lungs - http://www.thingiverse.com/thing:1234899
  • Brain - http://www.thingiverse.com/thing:478336

The heart was already hollowed out and ready to go, the Brain was pretty simple because I was able to make a smaller brain and cut out the insides with it.  The lungs were a much bigger problem, because of their weird shape they were difficult to hollow out, and even hollowed it seemed like the supports would use more filament than just printing them solid.  Here comes the biggest mistake from this project.

I decided it would be perfectly fine to print the lungs, and then hollow them out with a drill.  This was a very bad idea.  Sure it worked perfectly fine, but it took forever and felt like a waste of time.  The fact that I had to print the lungs in 8 parts because it was too big for my printer just made it take longer.

As soon as the organs were finished printing I started on the electronics which were relatively easy to put together, it is basically the same setup I had in my last project (so check that out if you want to learn more).  The coding was a little more troublesome.  This was my first endeavor into Object Oriented Programming with C++ so things went a little slow at first.

The Code

The basic plan was to make an organ class and give it attributes for each of the organs.  I'm not going to post this code though, it looks really ugly.  Maybe at some point in the future I'll come back and fix it.

The final plan was to have one arduino connected to each organ, but I was thinking it may be fun to recreate this in the future and have one arduino run all three organs, so I took a more fun route that required me to figure out how to multi-task! (Adadfruit has a pretty good tutorial here)

.  Normally people program Arduinos to run of a single loop, so if I want a light to flash every two seconds I may write something like:
  1. Wait 2 Seconds (delay())
  2. Flash Light
This works perfectly fine for this application, but what if I want a light to flash every 2 seconds, and another to flash every three seconds? The second command stops the entire program, which makes it impossible for these two commands to run simultaneously. Even if I tried to get a light to flash on the third second, it would ruin the first command.
  1. Wait 2 Seconds (delay())
  2. Flash Light -Light Flashes on the 2 second mark
  3. Wait 1 Second
  4. Flash Light - Light Flashes on the 3 second mark
  5. (Loop Beings again)
  6. Wait 2 Seconds
  7. Flash Light - Light Flashed on the 5 second mark, when we wanted it to flash on 4 
This is where a handy command called millis() comes in to play.  millis() will tell you how many milliseconds the Arduino has been running  and based on this we can much more easily fix the problem above with something that looks like this (bear with me, it will be a bit more complicated)
  1. time = millis()
    light1_time =0
    light2_time=0
  2.  if time - light1_time > 2 seconds
    then Flash Light and set light1_time = time
  3.  if time - light2_time > 3 seconds
    then Flash Light and set light2_time = time
As this program loops around it is constantly checking if it has been two or three seconds since the last time it lit, and the light1_time keeps track of the last time it was lit.  And tada! It works!

The code itself replicates each organ.  The lights in the brain randomly light up with varying colors and intensities.  The lungs slowly get brighter and darker, and the heart beats at about 60 beats per minute!


The Hardware

When all the components were finished, it was time to assemble them. The hardware was pretty easy to assemble, it's the exact same layout as my previous Stranger Things build following the same safety precautions to not damage the leds.  The only difference was that I used a lot more shrink wrap.  These are intended to be used at a festival so there is the very real chance that it could rain.  I didn't set up a final box to hold the arduino themselves, but I suggested that they get some plastic containers, cut a hole out of the lid and stick everything in, then superglue the crap out of it.




The Bragging

Look at them and their awesomeness!



How do I hold all these organs?
I have an idea!

























And now to see all of the actually working!

A post shared by Steven Burgess (@stevenryanburgess) on

A post shared by Steven Burgess (@stevenryanburgess) on

A post shared by Steven Burgess (@stevenryanburgess) on
jkljljlkj