Tuesday, December 31, 2019

Building a Modellighthouse using a 3D printer and an Arduino nano

About a month ago everyone started the yearly christmas hype and so I had to ask myself: who and what do I gift this year?
And then my Dad came up with a very cool idea for my mom.
She loves lighthouses and practicaly there was a model for the "Roter Sand" on Thingiverse. So he hooked me up with the question if I would solder some LED lights for it and ofcourse this was a BIG yes from me.

But, what does a lighthouse needs to actually look like one that is in use? Signal LEDs ofcourse. But isn't it that there are also people living in a lighthouse? 


So I searched through the stuff I had lying around and found a few of LEDs, resistors and so on. Based on this I made a plan what I would need for my Lighthouse-Installation ending up with the following list: 


  • 1 x RGB LED
  • 1 x white LED
  • 4 x yellow LED
  • 5 x resistors 220 ohm 
  • 1 x Arduino nano 
  • Jumperwires (about as long as the hight of the Lighthouse) 

Ok, I wanted to have the four yellow LEDs for the tower and the RGB LED up on the top as the main spotlight. The white LED I decided to be the secondary spotlight. 

Combining all this with an Arduino Nano the set up came out like the following: 



The Arduino Nano has a 5V pin-output and some of the pins feature the pulse width modulation (pwm), a technologie turning a digital pin on and off so quick with changing ratio that in case of an LED it looks like dimming, which I decided to use for simulating the rotation of the spotlights. 

Also, in my first version I tried to use a nano every what failed abysmally, moste likely because I'm just to dumb, but more on this later. 

To test my set-up I assambled it on a breadboard, using an arduino uno on an interim basis because the nano every was still on it's way through all of the christmas shipping horror. 




After verifying that my set-up works fine, it was time to write a sketch that can a) simulate a rotating signal light and b) something like a "candle flickering" for the yellow LEDs. 
As mentioned earlier, I used the pwm feature of some of the digital pins to give the signal LEDs an up and down fading. After that, I just wrote a simple "on - off sequence" for the yellow LEDs by playing try and error with the up- and downtimes and integrated it in the fading cicle. 

The complete sketch looks as the following: 



Ok, nice. My set-up worked fine on the testbench so it was now time to solder it all fix together. To reduce the amount of things I had to check if something would go wrong I solderd it all in two parts. First, I put the resistors together on a perfboard to reduce possible fragile points and solderd the LEDs with 50 cm jumperwires onto it. Then I connected them back to my test arduino uno and got trolled that damn hard by this little thing my ego still has a little scratch.
I powerd on aaaaand... nothing happened. Absolute clear thing: I made a mistake during soldering with the low budget soldering iron that starts burning stuff away at some point because it doesn't has a temperature regulation... or maybe... yea, maybe that wasn't the problem. But first, I took the next hour measuring the connections once after another one time, two times, three times... and wasn't able to identify the problem. 
Frustrated, in an act of despair, I reuploaded the sketch to the uno and... the LEDs turned on and flickered as they should do. I still don't know why the Arduino just decided to delete the sketch, but it did and I decided to take it personal. ;) 




At least, I had it all working now. All? No! But soldering the Nano Every to the construction and loading a sketch onto it couldn't be a big deal right? I mean, Arduinos are close to unbreakable and absolutely simple to get run... as long as it's not me working with them. When the Every arrived, I solderd it to the rest of the construction without testing the sktech on it before.

Please note: If you don't wanna have a minimum of double the work, go in the absolutely smallest steps possible. 

Then I connected the nano every to my Laptop and started the upload... not recognising that I shosed the normal nano, not the every in the IDE. I haven't figured out yet if this already was the breaking point, but on natural reasons the upload failed and after getting behind my stupidness here, I chose the Nano every and made it all set up for an upload as the internet told me. 
What followed next was an incredible multiple hours try of debugging why the every gave me multiple errors e.g. "Failed to communicate with programmer" and so on. Sadly at some point I ran out of time so I had to get to a quick solution which was my local electronics reseller of trust. So I bought a normal Nano there, changed it against the every and uploaded the sketch like there never was a problem. 
About the every I'm still about to find out what the problem is here. Some guy told me to post the problem on the Arduino Forums. If I get it solved, I'll make this an extra post!

Meanwhile my dad printed part after part for the lighthouse with our Prusa i3 MK2, having his really own problems with layershifting and so on (the printer has already a lot of hours printing done so it falls apart once in a while `:/ ). 


  
As said before, we found the constructionfile for this one on Thingiverse and just added some holding for the cables and a ring at the Bottom to get the cable throgh it. 


Last but not least we assambled module by module with the cables between. I decided to base the main electronics at the bottom so it is easy to reach it if something needs to be fixed. The whole construction runs on the 5V power- and datacable from the Arduino and so can reprogrammed at any time if the lighthouse should blink like a disco light on the next houseparty. 

Here we go with the finished build: