Arduino Tutorial – Creation Of A DIY Lamp “LUMINA”
This Arduino based project tutorial was made by an amateur and is mainly intended for other amateurs of the genre or anyone with a little curiosity for this type of electronic assemblies.
The author calls in advance for the benevolence of the venerable experts who would like to dig a little in the code or in the mechanical design (Arduino code and STL files available at the end of the article).
LUMINA is a 3D printed lamp, housing a chain of RGB LEDs whose color and intensity can be varied. It offers several modes, allowing it to be used as a mood lamp or as a game. The interaction is made by means of 6 ultrasonic sensors embedded in the base, which will allow you to navigate between the different modes, and activate the LEDs.
What Equipment Will You Need?
- 1 x Arduino Uno Rev3 board
- 1 x USB type B cable
- 1 x passive piezoelectric buzzer (optional)
- 1 x 220 Ohm resistor
- 1 x 400 point prototyping plate
- Jumper cables M / M and M / F
(all components available in particular in the Official Arduino Starter Kit ) - 6 x HC-SR04 ultrasonic sensors
- 7 x LED grove RGB V2
- 2 x bags of 5 Grove cables 5 cm
- Just under 300 g of filament (130g for the box, 65g for the plate and 75g for the cover). In my case, ivory Chromatik filament.
- The screw 6mm M2 and M2 nuts, or double-sided tape
- Recommended: 1 x bag of 5 Grove cables / male jumper
- Optional: 1 x wall charger ( 5V USB adapter or transformer between 7 and 12V for power supply via the jack, for example, this one). Otherwise, plug the USB cable into a computer port.
Software And Libraries To Download
- Arduino IDE software
- Newping library for HC-SR04 ultrasonic sensor
- LED Grove Bookstore
- NewTone library
Assembling Your LUMINA Lamp
Place the Arduino board in the crate, as close as possible to the interior wall. Then fix the breadboard using the double-sided tape on its underside, so as to prevent the Arduino from moving.
Then proceed to connect the ultrasonic sensors and the buzzer following the Fritzing diagram. When integrating into the body, the sonar 1 must be placed above the Arduino’s USB and jack connectors.
Attach the LED grove modules to the underside of the intermediate plate. If you prefer the use of double-sided tape for screwing, still base yourself on the position of the screw passages, so as to orient the LEDs correctly.
Connect the “IN” of the central LED (number 7) to the “OUT” of one of the peripheral LEDs. Then connect, step by step, the peripheral LEDs. For this, use the 5 cm Grove cables. You can peel the wires from each other, for more flexibility.
The “IN” of the last LED (number 1) must be connected by means of a mixed Grove – male jumper cable, on the one hand to the Arduino (signal), on the other hand to the breadboard (5V and ground ).
Close the box with the intermediate plate, taking care to position the LED 1 (the one which is directly connected to the Arduino) above the sonar 1, ie above the Arduino connectors.
Before closing everything, I recommend that you test the proper functioning of the lamp by uploading the program to the Arduino (the program is available at the bottom of the page, in the resources).
OPTIONAL: screw the plate into the box (for example if you plan to have the lamp handled by children).
Please note, however, that the ultrasonic sensors can be inserted into the body, by simple pressure, which may affect their operation. If you want to screw the plate, provide a way to fix the sensors. Such a system is under consideration with a view to implementation in the very structure of the box.
Position the cover. Normally, all parts should hold in place when fitted. You can then connect the lamp via USB or the jack and start using LUMINA!
Using Your LUMINA Lamp
To date, LUMINA offers 4 modes of use and a selection mode:
Mode 1: Manual Variation
Three ultrasonic sensors will increase the value of the red, green and blue components in stages, and the other three will decrease these same values. The change is applied uniformly to all LEDs. A subroutine makes it possible to modify the value of the level, so as to accelerate the color changes. Accessible by keeping sonars 2 and 5 * activated together.
Mode 2: Automatic Variation
The LEDs scan the spectrum of colors together. It is one of the demo codes of the library used. A subroutine has been added to allow variation of the scanning speed. Accessible by keeping sonars 2 and 5 * activated together.
Mode 3: Light Piano
Each sonar is associated with the LED located above it, itself associated with a color. Activating a sonar light the corresponding LED in its color. When the sonar is no longer activated, the LED gradually decreases in intensity until it goes out.
Several LEDs can be lit at the same time. The top LED lights up white and at its intensity aligned with that of the last activated LED. Each sonar is also associated with a musical note, played by the buzzer as long as the LED is activated. A subroutine allows you to vary the duration of the speed of the gradient from the moment the sonar is released (between approximately 0 and 5 seconds). Accessible by keeping sonars 2 and 5 * activated together.
Mode 4: Simon, The Famous Game
The lamp plays a sequence of LEDs accompanied by notes, which the player must reproduce by activating the corresponding sonars. The game begins with a sequence of 3, incremented with each success, up to a sequence of 10. A success triggers a small animation in green, and advances to the next level. Success at level 10 exits the game. Failure triggers a small red animation and replays the current sequence. The third failure expels the player from the game. The player is subject to a timer to play his sequence. At the end of the timer, the player is eliminated. In all these cases, the lamp returns to Mode 2 – automatic dimming.
This mode is accessible from all modes except Simon, keeping sonars 1 and 4 * activated. LEDs 1 to 4 * light up white and vary in intensity. Activating one of these sonars for a long time will activate the corresponding mode. LEDs 5 and 6 * send the player to automatic variation mode. Ditto when the timer expires.
* number according to photos and Fritzing diagram, not according to code.
Genesis Of The LUMINA Project
I wanted to make this lamp when I saw the videos presenting the Bare Conductive kits (in particular the lamps controlled by a capacitive sensor). I already had a 3D printer, and I noticed that prints that were sufficiently fine could give nice transparency effects, suitable for my use.
I lacked electronics knowledge, but the prospect of being able to make a complete object, thanks to 3D printing, convinced me to get started!
The Choice Of Platforms
The Electronic Card
As I had just started programming in Arduino, I had the famous Uno R3 for beginners. It was only natural to make profitable both the material and the learnings, by basing the project on this card.
That said, it would be possible to use any other card from the Arduino family, or even any other microcontroller ( Raspberry Pi, for those who like to code in Python, for example).
Attention however to those who would like to reproduce the project with a micro: bit: even if it is possible to have access to enough pins thanks to a breakout, the card delivers a voltage of 3.3V, too low to supply the various sensors.
The Sensors
Capacitive sensors in conductive paint would have liked me, but they need to be large enough to be effective. The final object should not be too big, I needed a more compact solution. The ultrasonic sensor HC-SR04 offers the double advantage of being inexpensive and has a wide detection range. For the same use, one could as well have taken infrared sensors, such as those of the manufacturer Pololu.
LEDs
I hesitated for a while with Neopixel RGB LEDs, but the chainable Grove LEDs offer the significant advantage of being very simple to connect, without soldering. Their plate has holes for easy attachment to the structure. On the other hand, the two references have ready-made Arduino libraries.
The 3D Printer
For my part, I use the Neva, from Dagoma. A setting of 0.2 mm (fast) already makes it possible to obtain a very satisfactory rendering. The thin parts do not have any day between the layers, the parts fit together well. I use an ivory-colored filament (the one I use for my tests, in general). Printed quite fine, it allows diffusing the color of the LEDs, while absorbing the excess of brightness.
NB: in its basic dimensions, the box makes the most of the Neva’s printing surface. Be careful to immediately remove the small block that the printer deposits at startup, before the print head returns to it.
Software Tools
The program is carried out in a classic Arduino environment. Small precision, for the ultrasonic sensors, I used the NewPing library. The HC-SR04 are all connected to the same pin for the trigger, and this caused malfunctions with the “basic” Ping library. Note that the MBlock software from the manufacturer MakeBlock allows you to program Arduino boards in a visual language like Scratch.
The modeling of the parts was done with Tinkercad, a free interface accessible online, extremely simple to use. The modeling is done by means of additions and subtractions of more or less complex geometric shapes. However, it allows for very elaborate designs. There are many online video tutorials.
Some Advice
As a beginner, there is something exhilarating about making your first electronic project. On the other hand, it can also be the source of frustration, when faced with unexpected complications or incomprehensible bugs. Here are some suggestions which I hope will help my novice comrades not to become discouraged.
Have A Clear Idea Of What We Want To Do
As in any creative process, one of the main dangers is to get lost along the way, so there are so many possibilities. It will, therefore, be important, throughout the project, to keep the final objective clearly in mind.
Start Small
Rome was not built in a day! If you are a beginner, you must start by agreeing not to do the mega-project-of-the-dead-death-immediately. But don’t worry: your friends are certainly as new as you are, and even a simple assembly based on obstacle detection and LED blinking will be able to make them exclaim with wonder about your new talents as a programmer! And nothing will prevent you from gradually making your editing more complex.
Find A Code Name For Your Project
Because it’s cool. Well, LUMINA may not win the prize for originality, but if you carry out several projects simultaneously, having a small name for each will help you find your way.
Invest In Pencil And Paper
Whenever I wanted to jump straight into a piece of code around an idea, I spent two hours there, where there was really no need to look far. So before jumping on his keyboard, we take a deep breath, sharpen his pencil, sharpen his eraser, and we think. “What is well conceived is clearly stated, and the words to say it come easily.” This maxim by Nicolas Boileau also applies to program! You will see, you will save time!
Go Fishing For Information
It is certain that when working with geeks, it is quite easy to get explanations on obscure points. But for those who are not lucky enough to attend, do not panic! The Internet is full of gold mines, in different forms. First of all, the official websites of the platforms you use will often help you out, be it Arduino, Rasberry Pi, Python, Micro: bit… For basic indications on how Arduino works, the Openclassroom tutorial for beginners is extremely well done. And in general, a simple google with a few well-chosen keywords will get you out of the panic.
Review The Basics
Many programming errors come from a stupid syntax error that we do not see, even though we have read, re-read and re-read its code line by line. A great classic: the notation “if a = 0”, where you should write “if a == 0”. What to go crazy. In case of a bug, very important, therefore, to check even the most basic functions and notations.
Comply With Programming Conventions
Because you may not be the only one reading your code, or simply because you will sometimes need to come back to it after several weeks: follow the good practices in terms of presentation (indentation my love) and comment! Again you will save time and comfort.
Enjoy!
If you are interested in this tutorial, it is probably an amateur programmer. Learning the code is exciting, but can also have its forbidding and restrictive aspects. So as not to get discouraged, always make sure you do something you enjoy!
Leave a Reply