Silicon ChipMax’s Cool Beans - January 2023 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions
  5. Back Issues: Hare & Forbes Machineryhouse
  6. Publisher's Letter: SMD tips and tricks
  7. Feature: Raudive Voices Revisited by Mark Nelson
  8. Feature: Net Work by Alan Winstanley
  9. Project: Classic LED Metronomemes by Randy Keenan
  10. Project: Geekcreit’s 35MHz-4.4GHz Signal Generator by Jim Rowe
  11. Project: REMOTE CONTROL RANGE EXTENDER by John Clarke
  12. Project: Multi-Channel Speaker Protector by Phil Prosser
  13. Feature: AUDIO OUT by Jake Rothman
  14. Feature: Make it with Micromite by Phil Boyce
  15. Feature: Circuit Surgery by Ian Bell
  16. Feature: Max’s Cool Beans by Max the Magnificent
  17. PCB Order Form
  18. Advertising Index

This is only a preview of the January 2023 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
Max’s Cool Beans By Max the Magnificent Arduino Bootcamp – Part 1 Fig.1. Arduino Uno R3 microcontroller development board. A s I happily meander (some may say ‘blunder’) my way through life, I meet a lot of people with ages ranging from youthful sprogs to venerable golden-agers who are interested in learning about computers in the form of microcontrollers. These people come from all walks of life. A few years ago, for example, I was introduced to an ex-army attack helicopter pilot whom we’ll call Mike (because that’s his name). Mike was in the process of building a gigantic model railway. He wanted to be able to illuminate the streetlights and houselights in his miniature world, but he didn’t want them to all simply turn on and off at the same time. Mike’s wish was that when he dimmed the lights in the room housing the layout, the streets in his model would light up at slightly different times. Also, that the lights in the houses would start to turn on in a random fashion. This was, of course, a perfect task for a microcontroller, so I gave Mike a crash course and helped him get things up and running. There are vast amounts of training resources already available for this sort of thing in the form of books, websites and YouTube videos, but sometimes it can be hard to take that first trepidatious step (don’t worry, I’m right behind you and I’ll be happy to give you a push). It’s also true that there are many ways into this topic, and everyone teaches things differently, so if you’ve already tried dipping your toes in the microcontroller waters, only to find them cold, confusing and uninviting, perhaps I can persuade you to try once more with your humble narrator as 62 your guide (I pride myself on my humility). Meet the micro You’ve probably heard the terms microprocessor and microcontroller. These are often abbreviated to MPU (for microprocessor unit) and MCU (for microcontroller unit), respectively. So, what’s the difference? Well, a high-level way of looking at this is as follows. The brain of a digital computer is its central processing unit (CPU), which is where all the number crunching and decision making takes place. An MPU is essentially an integrated circuit (IC) – also known as a silicon chip – containing only a CPU, with everything else (eg, memory and peripheral functions) being presented externally as separate devices. By comparison, in addition to its CPU, an MCU also contains on-chip memory and onchip peripheral functions. The MCU’s on-chip memory comes in two main forms: Flash and RAM. The Flash is non-volatile, which means it retains its contents when power is removed from the system. In turn, this means we can store a program in the Flash memory and, when power is applied to the system, the MCU will wake up and immediately start to execute that program. By comparison, the RAM, which stands for ‘random-access memory’, is volatile, which means it forgets its contents when power is removed from the system. When the MCU is running, the RAM is used by the program to store temporary values, intermediate results from any calculations, and data read from the outside world. The microcontroller with which we will be playing is an ATmega328P. This device was originally created by a company called Atmel, which was acquired by another company called Microchip Technology in 2016. A microcontroller development board is a printed circuit board (PCB) that contains a microcontroller along with other devices and connectors. The microcontroller development board we will be using for our experiments is an Arduino Uno R3 (Fig.1) (the ATmega328P is the big 28-pin chip presented in a dual in-line (DIL) package that’s located in the middle-ish of the board). You can find these little rascals all over the place (like Amazon, for example: https://amzn.to/3TFkltu). When you are making your purchase, check that your Arduino Uno comes with an associated USB cable, otherwise make sure that you have a USB-A to USB-B cable lying around (the A end plugs into your host computer while the B end plugs into the Arduino). What a shock Call me an old fuddy-duddy if you wish, but I’ve been the victim of electrostatic discharge (ESD) more times than I care to remember, so I strongly recommend that you take appropriate anti-static precautions. Is this mandatory? No. Is it a good idea? Yes. Suppose you are ambling your way around your home after making a refreshing cup of tea, and you build up an electrostatic charge on your way. (For modelling the effect of ESD on sensitive electronic devices, a human being is represented as a capacitor of 100pF (picofarads) charged to a voltage of up to 35kV (35,000 volts). Suffice it to say, it can be a monumental pain if you zap yourself. It can also make your eyes water if you end up destroying one of the elements – a pin on your nice new Arduino, for example – of a project on which you’ve been working for hours, before you’ve even had a chance to play with it. To prevent any such unfortunate occurrence, may I make so bold as to suggest that you invest in an anti-static mat (https://amzn.to/3g1YH4A) and an anti-static wrist strap (https://amzn.to/3WYZ9Bu). Both typically come with crocodile clips (a.k.a. ‘alligator clips’ in the US), which you can pull off to reveal banana plugs. My preferred modus operandi is to plug these banana plugs into an anti-static grounding plug (https://amzn.to/3hDIcML), which is – in turn – plugged into a wall socket or a power strip. To be clear, the connection is just to ground – never to the bitey terminals (live/active or neutral)! Let’s get started An Arduino Uno (Fig.2) requires 5V to perform its magic. One possibility is to use a 9V supply plugged into the Arduino’s Practical Electronics | January | 2023 AREF GND 13 12 ~11 ~10 ~9 8 7 ~6 ~5 4 ~3 2 TX-1 RX-0 DIGITAL IN/OUT (PWM ~) USB Orange LED Green LED POWER ANALOG IN A0 A1 A2 A3 A4 A5 RESET IOREF Power Jack 3.3V 5V GND GND Vin ATmega328P Fig.2. Arduino Uno pins and two of its LEDs. power jack, in which case the Uno’s primary on-board regulator will drop this down to the desired 5V. For the purposes of our initial experiments, however, we are going to supply power via the Uno’s USB port, with the other end of the cable being plugged into our host computer (Windows, Fig.3. Our first look at the Arduino IDE. Mac or Linux). In addition to being used to download proCreating our first program grams into the Arduino, this cable (well, the host computer) also As we see, the IDE has already started to create a program (sketch) supplies up to 500mA of current at the required 5V. for us. There are many more computer programming languages This is a good time to note that various external sensors and roaming wild and free in the cybersphere than you might supother components we might one day wish to connect to our Arpose. If you visit the ‘List of programming languages’ page on the duino Uno may require either 5V or 3.3V. Thus, the Uno has a Wikipedia (https://bit.ly/3NZMQ3N), I think you’ll be surprised secondary on-board voltage regulator that takes the 5V supply (the words ‘astonished’ and ‘alarmed’ may also apply). and drops it down to 3.3V. Note the header (connector) marked Two of these languages are called C and C++. (We can think of ‘POWER’ on the bottom of Fig.2. This is one way in which we C++ as being a superset of C, although this isn’t strictly true.) Arcan access 5V and 3.3V sources to power our external devices. duino programs are written in C/C++. There are many resources Now, take your USB cable, plug the A end into a port on your available to you to learn these languages, one of which will be host computer and plug the B end into your Arduino Uno. The this series of Arduino Bootcamp columns. first thing you should observe is that the green LED on the Uno Every Arduino program includes two functions called setup() starts to glow continuously to tell you that power is being supand loop(). The setup() function is executed only once at the plied to the board. If you don’t see this LED light up, then check beginning of the program, after which the loop() function is that your computer is powered on and that your USB cable is executed over and over again. plugged in all the way at both ends. If the LED still doesn’t light, The body of each function is bounded by open ‘{‘ and close ‘}’ we might need to consider the possibility that you have a broken squiggly brackets – their official name is ‘braces’ (smooth curved cable or a non-functioning Uno (or a non-functioning green LED). versions – ( ) – are called ‘parentheses’, while square ones – [ ] – Assuming the green LED does light up and this is a brand new are ‘brackets’). Anything following a pair of // characters is seen Arduino Uno, then the second thing you should observe is that by the IDE as a comment (for humans) and is ignored (by the the orange LED starts to slowly flash, turning on for one second program). The first thing I always do is remove the IDE-generatand then off for one second and then repeating this cycle over ed comments. The second thing I do is move the squiggly open and over again. brackets so that they are vertically aligned with their squiggly The reason for the orange LED flashing is that, by default, every close bracket counterparts (Fig.4). Arduino Uno is loaded with a sample program called Blink before We should probably note that C/C++ are free-form languages, it’s delivered to the end user, which is you, where the sole purwhich means the positioning of characters on the page in the pose of the Blink program is to flash the orange LED. program text is insignificant. However, experience has taught me that it’s a lot easier to understand and debug programs when matching pairs of squiggly brackets are vertically aligned. Meet and greet the IDE Now let’s create our program, as shown in Fig.5, and use the In a moment we are going to create our own version of the Blink File > Save As command to save it with the name MyBlink. The program (Arduino aficionados typically use the term ‘sketch’ as Arduino IDE includes a predefined suite of easy-to-use funcan alternative to saying ‘program’). To do this, we need something tions. We are employing three of called an integrated development environment (IDE), which is a these functions in our program: software application that runs on our host computer. pinMode(), digitalWrite(), The Arduino IDE provides a suite of tools and capabilities, like and delay(). a source code editor, a compiler, a debugger, and the ability to The digital pins on a microupload our programs into our Arduino. To access the IDE, visit controller can act as both inputs the Arduino.cc website and click on the SOFTWARE tab. There and outputs, which is why we are two versions of the IDE – the original IDE 1 and the more call them input/output (I/O) recent IDE 2 – we will be working with IDE 2, so this is the one pins. When a microcontroller you should download and install. is first powered up, before its Once you’ve installed the IDE, connect your Arduino Uno program starts to execute, on to your host computer and launch the IDE (it doesn’t matter in the principle of primum non which order you perform these two tasks). Observe the upper nocere, which is Latin for ‘first, left-hand corner of the IDE window (Fig.3). do no harm,’ all of its pins are Note the field containing the ‘Select Board’ text. Click the downset to be inputs by default. pointing arrow at the right-hand side of this field and select the The pinMode() function entry reflecting your Arduino Uno and the COM port to which it is is used to configure a speciconnected (alternatively, use the Tools > Board menu to select the fied pin as being an input or Fig.4. Let’s get organised! Arduino Uno and the Tools > Port menu to select the COM port). Practical Electronics | January | 2023 63 To summarise the contents of our current loop() function: we turn the orange LED on and wait for one second, then we turn the LED off and wait for one second. Remember that, in the Arduino world, the loop() function is automatically called over and over again, so this will result in the continuous flashing of our orange LED. Compiling and uploading In computing, the term ‘compiler’ refers to a computer program that compiles (translates) computer code written in one programming language (the source language) into another language. In our case, the Arduino IDE’s compiler translates our C/C++ source code into the machine code that will be executed by the Arduino Uno’s microcontroller. Let’s start by verifying our code is good by clicking the Verify icon (Fig.6). Fig.5. Our first version of our own Blink program. We can also use the Sketch > Verify/ Compile command. Hopefully, we will be presented with little popup windows saying, ‘Compiling sketch’ and ‘Done compiling’ accompanied by a report saying ‘Sketch uses 924 bytes (2%) of program storage space’ along with some other stuff. Alternatively, if Upload icon Verify icon we’ve done something wrong, we will be presented with a popup window Fig.6. The Verify and Upload icons. saying ‘Compilation error’ accompanied by a report detailing any errors. an output. This function accepts two ‘arIf the IDE informs you that you have guments’ (parameter values in computer errors and you can’t work out what the speak). The first is the number of the pin problem is, then bounce over to the Things in which we are interested. The second to note section a little later in this column. is a keyword (INPUT or OUTPUT), which If you still have problems with your own specifies the mode. In this program, we are version and simply can’t resolve them, declaring digital pin 13 as being of type then download my version (file CB-Jan23OUTPUT. The reason this statement is in 01.txt) from the January 2023 page of the the setup() function is because we only PE website: https://bit.ly/pe-downloads need do it once. Let’s assume there are no errors. In this Just to be sure we’re all tap dancing to case, we are ready to upload our program the same skirl of the bagpipes, digital pin into the Arduino. We do this by clicking number 13 on the ATmega328P is conthe Upload icon (Fig.6). We can also use nected to the pin marked 13 on the DIGIthe Sketch > Upload command. This time TAL IN/OUT header on the Arduino Uno we should see a series of popup windows development board (Fig.2). Also, it’s consaying, ‘Compiling sketch,’ ‘Done compilnected to the orange LED on the board. ing,’ ‘Uploading,’ and ‘Done Uploading.’ The digitalWrite() function is used Also, during the upload portion of the proto write a value to a specified digital pin, cess, two more LEDs marked TX (‘transwhere this value will be presented to the mit’) and RX (‘receive’) located close to outside world. This function accepts two the orange LED on the Uno will flash to arguments. The first is the pin number in indicate that the upload is taking place. which we are interested. The second is the value we wish to present to the outside world. In this example, we are using the Tweaking keywords LOW and HIGH, which – for the Unfortunately, since all we’ve done is repmoment (and with respect to our on-board licate the program that was already runorange LED) – we can consider as reprening in our Arduino, nothing will appear senting the states Off and On, respectively. to have changed. Last, but not least, the delay() function Let’s try tweaking the LED’s On and pauses the execution of the program. This Off times. For example, set the On time function accepts only one argument – the to 100ms and the Off time to 900ms, and amount of time the program will pause – then click the Upload icon again. Observe specified in milliseconds (ms), where there that the orange LED now displays a 100ms are 1000ms in a second. (1/10th of a second) flash once a second. 64 Suppose we wish the LED to give two 100ms flashes separated by 100ms, and we want this to happen once every two seconds, can you modify your program to achieve this? If you are unsure, you can sneak a peek at my solution (file CB-Jan23-02.txt). Things to note There are a couple of things that are worth noting at this point. The first is that C/C++ are case-sensitive languages, which means uppercase and lowercase letters are treated as being distinct entities. Thus, fred, Fred and FRED would be seen as being three totally different things by the C/C++ compiler. Try changing one of our delay() function calls to Delay(), click the Verify icon, and see what happens (remember to change it back again afterwards). Also, every statement in our program (which would be our function calls in this example) must be terminated by a semicolon ‘;’ character. Try removing one of the semicolons associated with a statement in our loop() function, click the Verify icon, and see what happens (don’t forget to add the semicolon back in again afterwards). Break out a breadboard A solderless breadboard (or ‘breadboard’ for short) allows us to create circuits without the need for soldering. The reason for the ‘solderless’ qualifier is that hobbyists of yesteryear (prior to 1971 when the solderless breadboard was invented) often created their circuits by hammering nails into pieces of wood and then wrapping their component leads and wires around these nails. Much to the chagrin of a youthful experimenter’s parents, this piece of wood was oftentimes the same board upon which members of the family sliced their loaves of bread. Breadboards come in several sizes. If you happen to have a half-size board, then this will suffice for the purposes of this column. Otherwise, I recommend you purchase a full-size board to accommodate our future columns. Actually, I just found a really good deal involving three full-size and two half-size breadboards for only £11.19 on Amazon at: https://amzn.to/3O2L3e8 Another thing we’re going to need are multicore jumper wires. These are typically presented in rainbow-coloured ribbons of various lengths from which we peel off individual wires as required. 4-inch and 8-inch lengths tend to be the most useful, but it doesn’t hurt to have a few 12-inch jumpers lying around. These little scamps come in male-male, male-female, and female-female flavors (Fig.7), but all we will need for our experiments are the male-male configuration. You can buy a starter set of 40 wires for £4.49 on Amazon (https://amzn.to/3O4hnxk), but this is a case of ‘the more the merrier,’ so it wouldn’t hurt to get more if you can afford to do so. Practical Electronics | January | 2023 suggest purchasing a variety pack, such as the 1,350-piece set I just found for £12.99 on Amazon at: https://amzn.to/3O4RvBt Conducting pin Plastic shell Insulated wire Setting up the breadboard Male-Male Male-Female Female-Female Fig.7. Multicore jumper wires. Additional bits and pieces We are going to need a single LED for our first set of breadboard experiments. If you happen to have one laying around, then let’s use that. Otherwise, on the basis that LEDs come in handy for so many projects, it really can’t hurt to purchase a box of assorted colours. I just found a box of 300 yellow, red, green, blue and white LEDs for only £7.09 on Amazon at: https://amzn.to/3E7VAQE We’re also going to need a current-limiting resistor to go with our LED, otherwise it will quickly become an ex-LED. Every LED has two important parameters: its forward-voltage drop (VF) and its maximum forward current (IF). Ohm’s law states that V = I × R (with units in ohms, volts and amps, respectively). Since we wish to calculate R in this case, we rearrange things to give R = V/I. The way we calculate the value of the current-limiting resistor is to subtract VF from the supply voltage (which is 5V in our case) and divide the result by IF. I just pulled a green LED out of my treasure chest of parts. The data sheet says that this LED’s VF = 3V and its IF = 20mA (that is, 0.02A), which means that my current-limiting resistor needs to be (5V – 3V) / 0.02A = 100Ω. This value of resistor will have brown-black-brown colour bands. Resistors are available in a fixed set of values (visit here: https://bit.ly/3O01LLj for more details about resistor values and colour bands). If, when you perform your own currentlimiting calculation, the result doesn’t exactly match one of the available resistor values, use the next higher value, which will result in a slightly lower current (you don’t want to use the next lower resistor value because this will result in a current that’s higher than the LED’s specified maximum). If I were a betting man, I’d say we will almost certainly be using a bunch of 100Ω and/or 150Ω resistors during the course of our experiments, along with other assorted values. On the basis that, like LEDs, resistors always come in handy, I would k Power Jack Fig.8. Setting up the breadboard. Practical Electronics | January | 2023 7 ~6 ~5 4 ~3 2 TX-1 RX-0 A0 A1 A2 A3 A4 A5 a a = anode k = cathode 3.3V 5V GND GND Vin k RESET Side view IOREF USB a Controlling the LED’s anode Suppose we wish to use our Arduino to control the green LED on our breadboard. One way to do this is to leave the LED’s cathode connected to 0V (GND) and use one of the Uno’s digital I/O pins to drive the LED’s anode via its current-limiting resistor (Fig.9a). We are going to use the Arduino’s digital I/O pin 6 for this purpose. Why pin 6? There are two reasons: (1) it’s not pin 13 (we want to mix things up a bit) and (2) six is my lucky number. Let’s start by repositioning the resistor and adding an orange jumper wire from pin 6 on the Arduino to the breadboard, as illustrated in Fig.9a. Next, we are going to modify the first version of our own Blink program which we introduced in Fig.5. Actually, we’re going to modify the first tweaked version – the one where we set the On time to 100ms and the Off time to 900ms. All we really need to do is replace the number 13 with the number 6, but we have to do this three times and I’m feeling lazy. This isn’t a huge problem in this case, but it could become so if our program were hundreds or thousands of lines long. One alternative approach is to use a #define preprocessor directive, as illustrated in Listing 1 (overleaf). In this case, we are using the #define directive to equate something we are calling PIN_LED (the pin driving our LED) with the number 6. Following this definition, every time the preprocessor sees the PIN_LED string of characters in the body of the program, it DIGITAL IN/OUT (PWM ~) will replace it with the number 6. Definitions of this type can use both uppercase and lowercase characters (along with numbers and underscore characters). Like many professional programmers, however, I POWER ANALOG IN use only uppercase and underscore characters for this sort of constant definition because this makes it obvious to me what they are when I’m reading my code at a later date AREF GND 13 12 ~11 ~10 ~9 8 Top view We can power our breadboard in various ways. For the sake of these discussions, we will power the breadboard from our Arduino (Fig.8). This is the way in which I usually set up the breadboards for all my projects. When I connect the USB cable to the Arduino Uno and the green LED on the breadboard lights up: (a) I know that my power and ground rails are connected and (b) I already have a bright green LED glowing before I start building my main project (a glowing LED always makes me happy). One of the things I can’t stress too strongly is that it’s a really, really good idea for you to pick a colour scheme for your wiring and then stick to it. For example, I use red wires for power (5V), black wires for ground (0V), and other colours for control and data signals. This may seem like an obvious point, but you’d be amazed how tempting it can be to use whatever wire comes to hand in the heat of the moment. Sticking to a defined scheme makes it easier to understand and debug your circuits should problems arise later. Does anything you see in Fig.8 cause you to think ‘What? Wait! Why did he do that?’ If so, it might be a good idea to bounce over to my Cool Beans website to peruse and ponder the special breadboard column I wrote just for you – see: https://bit.ly/3NZ70uF 65 Components Pin 6 5V GND Pin 6 From Arduino Pin 6 From Arduino GND 5V (a) Driving the LED’s anode Pin 6 GND Microcontroller: Arduino Uno R3 LEDs (assorted colours) Resistors (assorted values) Solderless breadboard Multicore jumper wires (M2M) https://amzn.to/3TFkltu https://amzn.to/3E7VAQE https://amzn.to/3O4RvBt https://amzn.to/3O2L3e8 https://amzn.to/3O4hnxk Other recommended stuff Anti-static mat Anti-static wrist strap Anti-static grounding plug https://amzn.to/3g1YH4A https://amzn.to/3WYZ9Bu https://amzn.to/3hDIcML 5V (b) Driving the LED’s cathode Fig.9. Different ways of driving the LED. (speaking of which, you can see my version of this program in file CB-Jan23-03.txt). Once you’ve made these changes, click the Verify icon to ensure that all is as it should be, then click the Upload icon to upload this new program into the Arduino. If you’ve wired everything correctly, the LED on your breadboard should start to display a 1/10th second flash once a second. Controlling the LED’s cathode An alternative way of controlling the LED is to leave its anode connected to 5V via its current-limiting resistor, and to use one of the Uno’s digital I/O pins to drive its cathode. Once again, we will use pin 6 for this purpose. Rewire the breadboard as shown in Fig.9b (remember to remove the black wire connecting the LED’s cathode to ground). Observe that, this time, using our current program, the LED is On for 9/10th of a second and it flashes Off for 1/10th of a second. The reason for this is that when we use our digitalWrite() function to output logical values of LOW or HIGH, these appear on the pin as physical values of 0V and 5V, respectively. When the Arduino’s pin was connected to the LED’s anode as discussed above, a HIGH (5V) turned the LED On and a LOW (0V) turned it Off, all of which tends to be the way in which we think about things. However, now that we’ve connected the Arduino’s pin to the LED’s cathode, a HIGH (5V) turns the LED Off and a LOW (0V) turns it On. Assuming we prefer our original short On flashes, one way in which we could address this would be to simply swap the two delay values. Another approach would be to leave the delay values ‘as-is,’ but to swap the HIGH and LOW arguments. A better option, however, would be to create two new definitions for LED_ON and LED_OFF (Listing 2 and file CB-Jan23-04.txt). This means that if we wish to return to driving the LED’s anode at some time in the future, all we will have to do is swap the LOW and HIGH assignments associated with our LED_ON and LED_OFF definitions. Phew! ‘Wanger gadangers,’ as one of my old friends used to say, there’s a lot to wrap our brains around here. On the one hand, all we’ve learned thus far is how to use a microcontroller to flash a single LED. On the other hand, WE’VE LEARNED TO FLASH AN LED!!! (Break out the party hats!) In reality, we’ve covered a lot of ground and we’ve set ourselves up for some exciting experiments when next we meet. As a helpful hint, without giving too much away, you may wish to get a head start by ordering one or more common-cathode 1-digit 7-segment displays. I just found a pack of 10 for £7.49 on Amazon at: https://amzn.to/3Afm8yu As always, I welcome your insightful comments, perspicacious questions and sagacious suggestions. Online resources Listing 1. (above) Defining PIN_LED. Listing 2. (right) Defining LED_ON and LED_OFF. Cool bean Max Maxfield (Hawaiian shirt, on the right) is emperor of all he surveys at CliveMaxfield.com – the go-to site for the latest and greatest in technological geekdom. Comments or questions? Email Max at: max<at>CliveMaxfield.com 66 For the purposes of this series, I’m going to assume that you are already familiar with fundamental concepts like voltage, current and resistance. If not, you might want to start by perusing and pondering a short series of articles I penned on these very topics – see: https://bit.ly/3EguiJh Similarly, I’ll assume you are no stranger to solderless breadboards. Having said this, even if you’ve used these little scamps before, there are some aspects to them that can trap the unwary, so may I suggest you feast your orbs on a column I wrote just for you – see: https://bit.ly/3NZ70uF Last, but not least, you will find a treasure trove of resources at the Arduino.cc website, including example programs and reference documentation. Practical Electronics | January | 2023