Photonics

Enter Your Electronics & Design Project for a chance to win an $200 Shopping cart of product!

Submit an EntrySubmit an Entry  Back to homepage
Project14 Home
Monthly Themes
Monthly Theme Poll

 

Introduction

This project is a simple game that inspired my 4-year-old son.

I saw him spellbound looking at the flame of a candle, the candle of a birthday cake. I tried to make him play a bit with LEDs but the charm of a flame that moves as if it were alive cannot be equaled by a cold LED.

Looking at the flame of a candle, I tried to simulate it with a simple circuit that can be used to introduce some of the potentials of an Arduino board to my students.

 

 

If we look closely at the flame of a candle, we can see that it takes on different colors. Below, near the wick, there will be bluish shades, while going up the color changes from blue to red-orange to get bright yellow. In addition to this chromatic variation, we will also have to take into consideration the effect of the convective currents that cause the flame to wave and move continuously in an unpredictable way, especially in its upper part.

These two aspects relating to a candle flame can be modeled using Arduino's PWM modulation and Random function.

This is therefore an excellent opportunity to show students what PWM modulation is and what its typical uses are.

 

 

Pulse Width Modulation

Pulse Width Modulation (PWM) is one of the most used modulations.

It is in fact used not only in telecommunications but also in applications where there is the need to vary the brightness of a lamp or to adjust the speed of an electric motor in direct current.

It is in fact used not only in Telecommunications but also in other applications for example when there is the need to vary the brightness of a lamp or to adjust the speed of electric DC motors.

The PWM modulator is a circuit that receives two signals at its input, the modulating signal, that is, the one that regulates the width of the square wave (the duty cycle) at the output and a triangular wave signal with a fixed frequency. At the output we will find a square wave signal that has the triangular signal frequency and a variable duty cycle that depends on the amplitude of the modulating signal.

 

                                       (From Arduino Site)

 

 

Many years ago this topic was treated at school using the "mythical" NE555, an integrated circuit that used with three or four other passive electronic components could be used as a monostable, astable or bistable multivibrator, as a PWM and PPM modulator, as a comparator, etc.

 

                                           

Since Arduino entered our schools, making a simple fader for a LED or a speed control for a small fan has become even simpler.

In these simple cases, the standard PWM frequency of the most popular Arduino boards is 490 Hz, a perfect frequency for our purposes so it will not be necessary to access the registers to set higher frequencies.

Even Arduino Nano has several PWM output terminals, in particular, the pins that can be used are 3, 5, 6, 9, 10 and 11.

The default frequency of the PWM signal is by default 490 Hz but it can be varied using a little more code complex but in any case, you cannot exceed a few tens of kHz.

 

To get a PWM signal on Arduino just use the analogWrite () function. Its syntax is very simple:

 

     analogWrite(pin, value)

 

Parameters:

  • pin: the Arduino pin to write to. Allowed data types: int.
  • value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int.

 

 

We will use this function to try to recreate the colors of the candle flame.

 

We will use a matrix of 15 LEDs organized as shown. The candle flame will be represented by 5 lines of three LEDs.

Starting from the bottom there will be a blue line, a red line and three yellow lines. In practice, we will use PWM to manage the three colors so that the light produced resembles that produced by a candle.

The two central LEDs of the fourth and fifth row will be controlled together with those of the third row while the two pairs of yellow LEDs on the right and left are piloted by two other doors in order to light up with a random intensity at each cycle.

Their flashing will simulate the random movement of the flame and its variation in intensity.

 

 

 

The Circuit

Per quanto riguarda il circuito non c’è molto da dire, lo schema è piuttosto banale e basta leggere il codice per connettere i Led ed il gioco è fatto.

 

The circuit         The circuit 1

Led array          led array1

 

 

The code is very simple, I added lines of code that could be avoided in order to make it more understandable.

 

The effect obtained is quite pleasant, even considering the fact that everything was made in a very short time and with materials that I was at home.

 

In Italy we are still forced to stay home for Covid 19 and everything is closed, I am dusting off old boxes full of old discrete electronic components and, I must admit that the temptation to do everything with the old NE555 has occurred to me several times but I believe Arduino can be more useful to me in view of the next school year. In fact, I am preparing many simple projects to show my students some uses of Arduino and some IoT applications.