This is only a preview of the July 2024 issue of Silicon Chip. You can view 42 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Automatic LQ Meter":
Items relevant to "180-230V DC Motor Speed Controller":
Items relevant to "New use for Mains Sequencer":
Items relevant to "Lava Lamp Display":
Items relevant to "Digital Compass":
Items relevant to "Workman 1kW Loudspeaker":
Purchase a printed copy of this issue for $12.50. |
Mini Projects #002 – by Tim Blythman
SILICON CHIP
Lava Lamp
Display
Lava lamps have always invoked a
fascination due to the seemingly infinite
patterns that they produce. The Lava Lamp
Display is a simple Arduino project that
emulates a lava lamp, creating a soothing
view that doubles as a groovy night light.
T
he lava lamp was invented in 1963
and consists of a glass bulb containing a mixture of liquids like oil
and water. An incandescent bulb in
the base heats the contents, and the
different components swirl around
due to their changing densities and
surface tensions.
The liquids are often coloured and
the random, slow movements of their
contents can be captivating and hypnotic. And bizarre as it may sound,
lava lamps are even used as a source
of random numbers for encryption.
Companies like Cloudflare use them
as part of their encryption process (see
https://youtu.be/1cUUfMeOijg).
Our Lava Lamp Display is a simulation of a lava lamp, using software to
imitate the physics. We can’t simulate
things down to the atomic level with
an 8-bit processor, but we can create
something that looks and behaves similarly. Our Display isn’t actually random, but it looks like it is.
The photos shows how the completed Lava Lamp Display uses an
8×5 LED matrix shield mounted on
an Arduino Uno board to provide the
processing power.
Simulation
The simulation involves several
‘blobs’. Each has a ‘temperature’ and
position within the display. They are
analogous to the balls of oil that break
off and travel around a Lava Lamp.
The temperature determines whether
or not the blob rises or falls, mimicking its density changing.
The position affects the temperature;
when the blob is near the bottom, the
temperature increases, as though the
blob is being heated. Near the top, the
temperature falls, as though by radiating heat to the surroundings. This feedback sets the scene for the constantly
changing movement of the blobs.
To avoid the blobs overlapping and
disappearing, the simulation prevents
a blob from moving on top of another.
Assembly of the Lava
Lamp Display just involves plugging the
LED matrix shield into an Arduino Uno (shown above). The blobs in
the Lamp drift around like those in a lava lamp. The software can be modified
to alter the colour or behaviour if desired.
64
Silicon Chip
Australia's electronics magazine
siliconchip.com.au
Lava lamps are produced in a variety of colours, and they produce unique and
constantly changing patterns. Source: https://w.wiki/9TUn (CCA 2.0).
To prevent a deadlock, blocked blobs
occasionally move in a random direction. This randomness comes from a
pseudo-random number generator.
The blobs’ colours also change
depending on their temperature, adding further variety to the display. The
result is a fairly convincing simulation
of a lava lamp.
Hardware and assembly
The construction phase of this
project simply involves plugging the
XC3730 shield into an Arduino Uno
board. The XC3730 LED Matrix Shield
uses so-called ‘intelligent’ RGB LEDs.
We described how these LEDs work in
an article on page 85 of the January
2020 issue of Silicon Chip magazine
(siliconchip.au/Article/12228).
In summary, we can drive all 40 RGB
LEDs on the shield using just one digital output on the Uno. Since the LEDs
are already attached to the shield,
assembly is simple: plug the XC3730
LED Matrix Shield into the Uno and
connect the USB cable between the
Uno and a computer.
Programming the Arduino
You will need to install the Arduino
IDE software plus some custom libraries. Adafruit’s NeoMatrix library is
responsible for driving the display. It
can be installed (along with its other
dependent libraries) by searching for
“neomatrix” in the Library Manager –
look for the version by Adafruit.
siliconchip.com.au
Download and unzip the software
package for this project, which is available from siliconchip.au/Shop/6/396
Next, open the XC3730_LAVA_
LAMP_COLOURS sketch, select the
correct board type and serial port
from the menus, then upload it to the
Uno. Arduino boards like the Leonardo should also work, but we haven’t tested that.
If all is well, you should see a display similar to that seen in our photo.
There isn’t much that can go wrong; it
should just work. A video of it can also
be found at siliconchip.au/link/abu8
Software details
The software has been written to
be configurable, so there are some
#defines and variables that you can
change to customise your Lava Lamp
Display. Remember to upload your
sketch again after any changes so that
they can take effect.
The BACK_COLOUR #define sets
the background colour; the default is
a dim blue. Changing the number in
the line matrix.setBrightness(6) will
alter the display intensity. We have
set it quite low so that the Lava Lamp
Display is suitable as a night light or
for nighttime mood lighting.
The colour of the blobs is set by
the tempColour[] array, based on the
blobs’ temperatures. The default is
quite subtle; you can try uncommenting one line at a time to see different
schemes we have tried, or you can
make your own.
To speed up or slow down the Display, you can change the delay() function call within the loop() function.
A higher value will result in a slower
update rate. You can also change the
number of blobs with the BLOB_
COUNT #define. The heatMap[] array
dictates how the temperature changes
based on position.
The updateBlob() function encapsulates the physics of how each blob
behaves based on its temperature. For
more advanced constructors, modifying the code can produce some significant changes to the simulation.
All of these changes will have very
subtly different effects on the model’s
behaviour and lead to so-called emergent behaviour, where a simple set of
rules can result in complex outcomes.
Another example of emergent
behaviour is a set of mathematical rules called Conway’s Game of
Life. You can see examples of this at
https://w.wiki/3TKJ
We have also written an implementation of this scheme in a sketch called
XC3730_CONWAY, which you can try
out by uploading it to the Lava Lamp
Display hardware. It is included in
the same download package. There is
an array you can use to set the initial
conditions, after which you can see
how the state evolves.
Each LED is either lit or not; its
state in the next phase of the sequence
depends only on it and its immediate neighbours. The rules are pretty
simple, but the animations generated
almost look like they are alive, hence
the name.
Conclusion
The Lava Lamp Display takes a simple simulation of lava lamp physics
and turns it into a unique and mesmerising display that can be used as a
night light or simply for amusement. It
shows how simple rules can combine
SC
to create complex behaviour.
Parts List – Lava Lamp Display (JMP002)
1 Arduino Uno microcontroller module [Jaycar XC4410]
1 8×5 RGB LED Matrix Shield [Jaycar XC3730]
1 USB-A to USB-B cable [Jaycar WC7705 or similar]
Australia's electronics magazine
July 2024 65
|