Silicon ChipMax’s Cool Beans - March 2024 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions
  5. Back Issues: Hare & Forbes Machineryhouse
  6. Publisher's Letter: Teach-In 2024
  7. Feature: The Wibbly-Wobbly World of Quantum by Max the Magnificent
  8. Feature: Net Work by Alan Winstanley
  9. Feature: The Fox Report by Barry Fox
  10. Project: Digital Volume Control POTENTIOMETER by Phil Prosser
  11. Project: Advanced SMD Test Tweezers by Tim Blythman
  12. Project: Active Mains Soft Starter by John Clarke
  13. Project: Teach-In 2024 by Mike Tooley
  14. Feature: Circuit Surgery by Ian Bell
  15. Feature: Max’s Cool Beans by Max the Magnificent
  16. Project: Audio Out by Jake Rothman
  17. PCB Order Form
  18. Advertising Index by Mohammed Salim Benabadji
  19. Back Issues: Bush MB60 portable radio by Ian Batty

This is only a preview of the March 2024 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)
Articles in this series:
  • Computer Storage Systems, Pt1 (February 2024)
  • Computer Storage Systems, Pt2 (March 2024)
  • Flowcode (March 2024)
Articles in this series:
  • Pico Digital Video Terminal (March 2024)
  • ETI BUNDLE (March 2024)
  • Pico Digital Video Terminal, Pt2 (April 2024)
Max’s Cool Beans By Max the Magnificent Arduino Bootcamp – Part 15 I fear we need to commence this column with a mini mea culpa. A couple of columns ago (PE, January 2024), I presented what I considered to be a rather cunning water-based analogy for the forward-voltage drop associated with diodes in general and light-emitting diodes (LEDs) in particular. Unfortunately, as I was to discover, that analogy wasn’t cunning enough. I’ve just received an email from a reader we will call Steve (because that’s his name). This email was short, sharp and to the point, reading as follows: Your recent column shows a lamentable lack of hydrodynamic intuition, leading you to be proud of an analogy that didn’t really seem to explain what you were trying to achieve. Maintaining the analogy between voltage and depth of water, a better metaphor for the diode voltage drop might have been a channel whose floor was higher than the floor of the lake feeding it. The channel would remain empty until the water level (voltage) is high enough. So, the diode voltage drop is represented by the difference in floor levels. Once the water level reaches the bottom of the channel, it (current) starts to flow, and the depth of the channel will be the depth of the lake minus the floor level difference. To me this seems a rather more intuitive explanation than your somewhat tortured diagram. Happy New Year! Channel 2' 2' 2' flow Lake Channel Lake 2' 2' Wall (Diode) 0' (a) 2' of water in lake, channel floor same as floor of lake, 2’ of water flowing in channel 3' flow Lake Channel 2' 5' Wall (Diode) 3' (b) 2' of water in lake, channel floor 2' higher than floor of lake, 0' of water flowing in channel (c) 5' of water in lake, channel floor 2' higher than floor of lake, 3' of water flowing in channel Fig.1. Graphical depiction of a diode’s forward-voltage drop. 56 What can I say? I can only blame my lamentable lack of hydrodynamic intuition on my dear old mother, who firmly believed that torrid tales of a hydrodynamic nature were not wellsuited for the supper table. Be this as it may, it must be admitted that surly Steve is correct, and his analogy is far better than mine. I hang my head in shame, and I shall chastise myself soundly as soon as I’ve finished writing this column. For your future reference, an updated version of this analogy is shown in Fig.1. As before, we use a lake to represent our power source. This lake feeds a channel, which represents a wire. The height of the water in the lake is equivalent to voltage and any flowing water is equivalent to current. Fig.1a depicts a lake with 2 feet of water (equivalent to 2V in our electrical circuit) and an unobstructed channel through which the water from the lake is free to flow. By comparison, in Fig.1b we raise the channel such that its floor is 2-feet higher than the floor of the lake. The wall where the channel meets the lake represents our diode, whose forwardvoltage drop we are assuming to be 2V. In this case, assuming the water in the lake is still only 2-feet deep, no water will flow through the channel. Finally, in Fig.1c, we increase the depth of the water in the lake to 5 feet. Since the floor of the channel is 2-feet higher than the floor of the lake, the result will be 3 feet of water flowing through the channel. (For those of you outside the US, where I live, 2 feet is often abbreviated to 2', and 3 feet is (very) roughly a metre.) A beatitude of breadboards Thus far, we’ve performed all our experiments on a single full-sized breadboard. However, we now need to spread our wings a little by adding a second board. In my previous column (PE, February 2024), I made mention of the fact that my friend Joe Farr ran across a source of extremely low-cost, highquality breadboards. Joe immediately snapped up 25 of these little rascals. I hope you also took advantage of this splendid offer. There’s a lot more to the humble breadboard than first meets the eye – the folks at SparkFun have a great tutorial on the anatomy of these little scamps: https://bit.ly/41LsGkX If you look closely at the underside of your breadboard, for example, you’ll see that what you initially assumed to be some sort of boring backing material is, in fact, covered in adhesive on both sides. One side is stuck to the bottom of the breadboard. You can peel the protective covering off the other side, and then use the adhesive to attach your board to a larger worksurface. So, if we wish to use two boards, we could simply stick both to a common platform, which could be anything from a thick piece of card to the wall of your family room. But wait, there’s more. If you look closely, you will see that there are dovetailed nubbins projecting from one side of the board with corresponding slots on the other side (Fig.2). These features allow you to connect multiple breadboards together without having to attach them to a larger base. Some boards also have nubbins and slots at their ends. Also, note that different manufacturers may have different sized/shaped nubbins and slots in different places, which can make things awkward should you wish to mix-and-match offerings from multiple vendors. And there’s still more. Return to Fig.2 and observe the narrow grooves delimiting the terminal strips in the center of the board from the power rails at the top and bottom of the board. These Nubbin Narrow groove Wide groove Narrow groove Slot Fig.2. Meet the nubbins. Practical Electronics | March | 2024 Fig.3. Example of a multi-breadboard assembly. grooves aren’t simply aesthetic artifacts. The power rails are attached to the main board by means of their own nubbins and slots. If you flip the board over, you can use a hobby knife (eg, an X-Acto knife) to cut through the double-sided adhesive backing along lines corresponding to the narrow grooves, after which you can separate the power rails from the main board. Joe sent me a photo of a prototype project he recently started (Fig.3). Note how some of the power rails have been removed from the breadboards in the middle and relocated to the left- and right-hand sides of the breadboard array. Also, you can see in Fig.3 how all the boards are attached to a large piece of white card. You’re welcome We are about to embark on the creation of a compendium of chronometers that present time (hours and minutes) using one, two, and four 7-segment displays. As part of this, we are going From Arduino Fig.4. Preparing our dual board combo. Practical Electronics | March | 2024 to be introducing several interesting integrated circuits (ICs). Since I have piles of breadboards lying around (they seem to accumulate over the years), I was tempted to move to using three boards – one for the 7-segment displays, one for the integrated circuits, and one to act as a sort of patch panel, thereby allowing me to re-route connections quickly and easily between the 7-segment displays and the ICs. But then it struck me that if you are buying new breadboards individually, you would probably prefer to spend less money and use fewer boards. So, after mulling this over, I determined that we could muddle and meander our way through using only two breadboards. You’re welcome. Preparing our dual-board combo Setting up our dual-board combo is really just an extension to the way in which we inaugurated our original breadboard at the start of this series (PE, January 2023). We commence by connecting two breadboards together using their nubbins and slots (Fig.4). We use two flying leads to bring power (+5V, red) and ground (0V, black) from our Arduino into the bottom right-hand corner of the combo. The reason for adding the little red and black wires linking the power and ground rails in the middle of the boards is that some breadboards have split power rails, which may or may not be indicated by breaks in their red and blue graphical lines. This is discussed in my Arduinos and Solderless Breadboards blog at: https://bit.ly/3NZ70uF Your boards may have continuous rails, in which case you don’t need to add these wires, but it’s good practice to do so to prevent being caught out in the future (it’s said that you learn from your mistakes, but – in my experience – it’s better to learn from other people’s mistakes, so – in this case – you can learn from my mistakes; once again, you’re welcome). On the left-hand side of the boards, we use jumper wires to carry power and ground from the lower set of rails to the other three sets. Why didn’t I decide to daisy chain these from one set of rails to the next? There are two reasons. First, I wish to minimise voltage-drop effects, and every additional connection adds a little more resistance. Second, this setup will be a tad easier to debug if any of my power or ground wires fail. Finally, we return to the right-hand side of the boards. For each board we add a green LED with an associated currentlimiting resistor. The green LEDs I’m using have a forward-voltage drop of 3V and can support a maximum forward current of 20mA. This means that if we wished these to shine as brightly as possible, then we would use 100Ω resistors (the way we calculate this value was discussed in PE, January 2023). In this case, however, I don’t want these LEDs to be too bright because they hurt my eyes, plus they last longer when we use less than the maximum allowable current, so I’ve used 680Ω (blue, grey, brown) for my current-limiting resistors. This limits the current to around 3mA, but the LEDs are still more than bright enough to serve their purpose. The reason for including these LEDs in our setup is that – every time we apply power to the boards – they provide confirmation that everything is connected as it should be and that we are getting power and ground to all the right places. Actually, ‘all the right places’ is not strictly true. We could do better. Can you see how? The answer is presented at the end of this column. The thing is, it’s a lot easier to weed out fundamental mistakes at this stage before we start adding more sophisticated components. And, more importantly, verifying that our power and ground connections are correct can prevent us from damaging other components when we add them to our breadboards. I just powered up my Arduino, and little tears of joy are rolling down my cheeks because both my green LEDs are glowing gloriously. If you wish, you can download an image of the entire setup described above, including the connections to our Arduino Uno (file CB-Mar24-01. pdf). As usual, all the files mentioned in this column are available from the March 2024 page of the PE website: https://bit.ly/pe-downloads Adding a 7-segment display In the fullness of time, we will be using four 7-segment displays that we will call D0, D1, D2 and D3 to our upper breadboard. For the moment, we will simply add D0 on the left-hand side of the board as illustrated in Fig.5, which 57 10 9 8 7 6 D0, 7, A D0, 6, B D0, 4, C D0, 2, D D0, 1, E D0, 9, F D0, 10, G D0, 5, DP 5V and 0V from lower breadboard 1 2 3 4 5 D3 Display segment Display pin numbers D2 D0 Arduino pin numbers 9 8 7 6 5 4 3 2 DP G F E D C B A Fig.5. Adding our first 7-segment display. also indicates where the other displays are to be added in the future. Before we do anything else, let’s connect a black wire between pin 3 of our D0 display and the nearest 0V power rail (it’s easy to forget to do this later in the excitement of the moment when we try to wrap our brains around the rest of the wiring). Next, let’s add eight current-limiting resistors on the right-hand side of the board. As we’ve previously discussed, the red LEDs in the displays we’re using have a forward-voltage drop of 2V and a maximum forward current of 20mA. For the moment, we’re going to use the same 150Ω (brown, green, brown) resistor values we’ve used before because this will give us our 20mA. In turn, this will result in maximum brightness, which will become important when we start multiplexing between multiple displays in a future column. Now let’s add the eight purple wires (or any colour of your choosing) between the 7-segment display and the tops of the current-limiting resistors. Finally, add the eight orange wires between the bottoms of the resistors and the Arduino. Observe that we are using a different Arduino-to-Display pin mapping to what we’ve used before. This makes the wiring easier on the right-hand-side of the boards, which will make our lives straightforward as we start to add more displays (well, that’s the plan, anyway). Once again, you can download an image of our latest and greatest dual Listing 3a. New pin assignments. 58 breadboard setup, including the connections to our Arduino Uno – see file CB-Mar24-02.pdf. Does everything work? Do you recall those distant halcyon days (as depicted in PE, April 2023 for the delectation and edification of future generations) when we created a program to repeatedly count from 0 to 9 and to display these values on our 7-segment display? Well, I just forked (copied) that program and gave it a tiny tweak. The modified file is available for you to download: CB-Mar24-03.txt. As illustrated in Listing 3a, all we needed to do to get this program to work on our new dual-board combo was to change the Arduino pin numbers associated with the segments on the 7-segment display. (Remember that, following some confusion in earlier columns, we’re now using a scheme in which the listing number [Listing 3 in this example] corresponds to the associated program file [CB-Mar24-03. txt in this example], after which we use ‘a’, ‘b’, ‘c’, … suffixes as appropriate.) Not surprisingly, these new pin assignments reflect those shown in Fig.5 (we’d be in a bit of a pickle if they didn’t). I just powered-up my Arduino. I wish you could see my 7-segment display merrily counting away. Handy-dandy reference sheets Before we proceed, every now and then it’s necessary to refer to some reference values. When we perform a theoretical calculation, we may end up with a desired current-limiting resistor value of 213.268Ω, for example. The problem here is that no one makes this value of resistor. If we look this up, we find the closest values in the series we are using are 200Ω and 220Ω. In the case of a current-limiting application, we would go for the higher value, which will result in a (safer) lower current. Tracking these available values down can be a pain, so Joe has created a set of handy-dandy reference sheets for himself. He keeps laminated copies on his workbench. Also, he’s kindly agreed to share them with the rest of us: CB-Mar24-04.pdf. And, while we are on this topic, if you’ve ever wondered as to how the various resistor values came to be decided on, you should check out the links to Parts 10 and 11 in my What Are Voltage, Current, and Resistance? Blog: https://bit.ly/3NV4Flw Tick tock, tick, tock… If we wish to create a clock, then you probably won’t be surprised to hear that one of the things we are going to need to know is the time to be displayed. We discussed resonators and oscillators in an earlier Techno Talk column (PE, January 2024). The Arduino has a quartz oscillator that acts as its system clock, and it can use this oscillator to keep track of time via its internal timers. Unfortunately, the Arduino’s oscillator is cheap-andcheerful and prone to drifting slightly. This isn’t a problem in the usual scheme of things, but we certainly don’t want our terrific timepiece to lose or gain a few seconds each day. Also, we would be obliged to reset our clock and reenter the time every time we powered the Arduino down and up again, which would be a pain. To get around these problems, we use an integrated circuit called a real-time clock (RTC) whose sole purpose in life is to mark the passage of time as accurately as possible. Furthermore, we use an RTC equipped with a backup battery, which means it can continue to keep track of time in the event of a power failure (in the case of a real clock) or the powering down of our Arduino (in the case of our prototype projects). The RTC I opted to use is the DS3231 Precision RTC Breakout Board (BOB) from Adafruit – see: https://bit.ly/3TRvjjk As illustrated in Fig.6, this bodacious beauty is based on the DS3231 chip, whch comes from Analog Devices, see: https://bit.ly/48IJxam Readers in the UK can purchase a DS3231 BOB from Amazon at: https://bit.ly/3S9OjHl To be honest, there are a lot of cheaper RTCs available, such as the DS1307 chip from Analog Devices or the PCF8523 and PCF8563 chips from NXP Semiconductors, and Adafruit has BOBs for them all. You can use whichever device you want (see also the discussions on RTClib below), Practical Electronics | March | 2024 can incorporate it into the left-hand side of our lower breadboard, as illustrated in Fig.7. Yes, of course you can download an image of our latest and greatest dual breadboard setup, including the 7-segment display, the RTC, and any ancillary components and wiring, along with all the connections to our Arduino Uno (file CB-Mar24-05.pdf). Fig.6. The DS3231 precision RTC BOB (real-time clock One of the reasons I like breakout board) (Source: Adafruit). Adafruit’s DS3231 RTC is that they provide a treasure-trove of but the DS3231 is the most accurate you information in their online tutorial: can get in this price range and it’s the https://bit.ly/3RQQMG9 one I use for all my projects. Consider the input/output (I/O) pins One small point is that the 8-pin header shown in Fig.6 and Fig.7. First up are strip comes separately, so you’ll have to Vin and GND, which we will connect solder this yourself. You want the long to the power and ground rails on the pins pointing down to push into your breadboard as illustrated in Fig.7 (this breadboard, and you want the IC side of RTC can be powered from 2.3V to 5.5V). the board facing upwards. If you aren’t It’s best to connect things without power used to soldering, now would be a good being applied to the board but – if you time to start learning. A great resource like to live dangerously – then always is The Basic Soldering Guide Handbook, connect the ground wire first. which was written by PE’s very own Alan The next step is to connect the DS3231 Winstanley and is available on Amazon: to the Arduino using the green and blue https://bit.ly/3H7LUaO wires shown in Fig.7. The DS3231 and You’ll also need a CR1220 lithium coin the Arduino communicate via a 2-wire I2C cell battery, which is sold separately. When you are inserting this little rascal, (Inter-Integrated Circuit) bus. This bus is make sure the large metal side of the bidirectional, which means we can use the battery (with the plus ‘+’ sign) mates with Arduino to tell the RTC what the current the outward-facing side of the battery clip time is (we only do this once or if we need (also with a ‘+’ sign, as seen in Fig.6). to change things later for some reason or other), after which the Arduino reverts Incorporating the DS3231 RTC to asking the RTC for the current time. Once we’ve added the header pins The two wires in the I2C bus are called and backup battery to your RTC, we SCL (the clock) and SDA (the data). These signals require 10kΩ pull-up resistors, but we don’t need to worry about that because these resistors are already included on the DS3231 breakout board. Unfortunately, there aren’t any SCL and SDA annotations on the Arduino board. A pinout diagram is available on the Arduino website – see: https:// bit.ly/48pLOrd – but I prefer the moredetailed version created by Alberto Piganti at: https://bit.ly/41LTNMJ One important point to note is that the Arduino’s SCL and SDA pins shown in Fig.7 are also connected to the Arduino’s A5 and A4 analogue input pins, respectively (this is reflected in Alberto’s version of the pinout diagram). This means we cannot use the A4 and A5 pins as analogue inputs if we are already using them to perform I2C communications. The great thing about I2C is that you can have multiple devices like sensors and actuators all controlled using the same two pins on the Arduino. This means that each device requires its own address for everyone to know who is talking to whom. The DS3231 breakout board has a default address of 0x68 in hexadecimal (104 in decimal), and this address cannot be changed. We aren’t planning on using the DS3231’s other pins at the current time, but it’s worth noting what they do in case we decide to use them later. The BAT pin is connected to the positive side of the coin cell battery. The 32K pin provides a 32kHz oscillator output, while the SQW pin provides an optional square wave, which can be used as an interrupt to the Arduino (both these To upper breadboard DS 3231 V in SCL B AT SDA SQU 32K RST ARE F G ND 13 12 ~11 ~10 ~9 8 GND Fig.7. Adding the RTC. Practical Electronics | March | 2024 Listing 6a. Initialising the RTC. 59 Online resources 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. pins require pullups if we wish to connect them to the Arduino). Last, but not least, we have the RST (‘reset’) pin. This is a bit different to other reset signals you may have seen because it isn’t used to reset the RTC; instead, the RTC can use it to reset (or inform) other devices whenever main power is lost. RTClib and first RTC tests In order to use our RTC, we are going to need a special library. A few years ago, a guy called Jean-Claude Wippler of JeeLabs fame created an awesome RTC library called RTClib. The folks at Adafruit forked (and subsequently modified) a form of this library, and that’s the one we’re going to use. In addition to our DS3231 RTC, Adafruit’s RTCLib also supports the DS1307, PCF8523 and PCF8563 RTCs we mentioned earlier. Instructions on how to download and install Adafruit’s version of RTClib can be found in the aforementioned Adafruit tutorial. Remember to exit and restart the Arduino IDE after you’ve installed the library. As you will see in their tutorial, the folks at Adafruit provide some great example programs for the RTC. Since a lot of their stuff isn’t of interest to me, I’ve forked their main example and used it as the basis for a couple of my own. Listing 6b. Retrieving values from the RTC. 60 Let’s download, peruse and ponder my first program (file CBMar24-06.txt). We start by including the RTClib library we just installed. Next, we instantiate our real-time clock and we call it rtc (so, no surprises there). We also declare a 2-dimensional array of characters called daysOfTheWeek[][] to which we assign the names of the days of the week (‘Sunday,’ ‘Monday,’ ‘Tuesday,’ … and so on). Now let’s consider the setup() function shown in Listing 6a. Observe that when the serial communications are initialised on Line 9, it’s with a baud (communication) rate of 57600. For the purposes of these discussions, we can think of ‘baud rate’ as meaning ‘bits-per-second,’ but don’t say this to a professional engineer because they will bore you to death with an explanation of what baud rate really is. In our earlier experiments, we’ve always used the default baud rate of 9600. So, now you have a choice, you can change this value to 9600 in the code, or you can do what I did, which is to click on the Serial Monitor icon in the Arduino IDE and change its rate to 57600. The main thing is that baud rates in the code and the Serial Monitor match. Line 12 calls the rtc.begin() function to initialise the RTC and set the ball rolling. Like all functions of this type, this returns a value of 0 (false) or 1 (true) to reflect whether or not the RTC is online and responding. If we were to use rtc.begin() on its own, its return value would be discarded. In this case, however, we are using it as part of a test, which basically says ‘If not rtc.begin()’ or ‘If rtc.begin doesn’t return a true value’ then… The bottom line is that if the program cannot detect our RTC, it will print ‘Couldn’t find RTC’ in the serial monitor window and then loop around twiddling its metaphorical thumbs. In fact, this just happened to me. ‘Oh dear,’ I said to myself (or words to that effect). I rechecked all my wiring and used my multimeter to ensure the RTC’s connections to 5V and GND were good. Next, I had a quick Google while no one was looking to see if the interweb had any words of wisdom to offer. It did. It said, ‘Check your solder connections’ and ‘Check your jumper wires.’ My solder connections looked good, so I simply swapped out my blue and green jumper wires, and everything was fine (phew!). Since we only recently added the battery to our RTC, we need to tell it what the time is. We do this using a call to the rtc.adjust() function on Line 21. Don’t ask me how this works, but it sets the RTC to the date and time this program was compiled and loaded into our Arduino. Observe the comments on Lines 23 through 25. These tell us how we can use the rtc.adjust() function to load the RTC with an explicit date and time. If we decide to add some pushbuttons to our clock in the future, we can use them in conjunction with this function to change the date and time (perhaps to set an alarm function or to reflect daylight saving time, for example). Now let’s consider the loop() function as illustrated in Listing 6b. One of the things RTClib does is declare a new data type called DateTime. In fact, this is a structure containing multiple members whose values we can access using full-stop/period ‘.’ delimiters (we introduced enumerated types, structures, and type definitions in PE, December 2020). On Line 31, we declare a variable called now which is of type DateTime to which we assign the values returned from a call to the rtc.now() function. In Lines 33 through 46 we use a series of calls to the Serial.print() function to access some of the fields in our now variable and print these values in the Serial Monitor. For example, the Serial Monitor on my host computer is currently showing the following: Practical Electronics | March | 2024 Components from Part 1 LEDs (assorted colours) https://amzn.to/3E7VAQE Resistors (assorted values) https://amzn.to/3O4RvBt Solderless breadboard https://amzn.to/3O2L3e8 Multicore jumper wires (male-male) https://amzn.to/3O4hnxk Components from Part 2 7-segment display(s) https://amzn.to/3Afm8yu Components from Part 5 Momentary pushbutton switches https://amzn.to/3Tk7Q87 Components from Part 6 Passive piezoelectric buzzer https://amzn.to/3KmxjcX Components for Part 9 SW-18010P vibration switch https://bit.ly/46SfDA4 Components for Part 10 Breadboard mounting trimpots https://bit.ly/3QAuz04 NEW! 5-year collection 2017-2021 All 60 issues from Jan 2017 to Dec 2021 for just £44.95 PDF files ready for immediate download Components for Part 12 Light-Dependent Resistor https://bit.ly/3S2430m Components for Part 13 BC337 NPN Transistor https://bit.ly/40xAgyS Components for Part 14 HC-SR04 Ultrasonic Sensor https://bit.ly/49AMBq4 Components for Part 15 Real-Time Clock (RTC) https://bit.ly/3S9OjHl : 2024/1/7 (Sunday) 16:48:55 2024/1/7 (Sunday) 16:48:58 2024/1/7 (Sunday) 16:49:1 2024/1/7 (Sunday) 16:49:4 2024/1/7 (Sunday) 16:49:7 2024/1/7 (Sunday) 16:49:10 : Now download my second program (file CB-Mar24-07.txt). You will see the loop() function is identical to our previous program. However, the setup() function has changed. All it does now is start the RTC; it no longer loads it with a new date and time. Load and run this second program and observe the date and time values appear in the Serial Monitor. Now, power-down your Arduino, count to 10, power it back up again, open the serial monitor, and observe that the RTC remembered the time when power was removed from the system (tra la!). And the answer is… When we were discussing the setting up of our dual-board combo earlier in this column, I noted that we weren’t truly verifying the fidelity of all our power and ground rails. The way our original green LEDs are located (Fig.4), we are only verifying the upper power rail and the lower ground rail on each board. This has never been a problem in the past for me personally because these are the rails I predominantly use. Now I come to think about it, however, it would be a good idea to add a pair of blue LEDs as illustrated in Fig.8. Why blue? Why not? We could carry on using green LEDs but – if nothing else – the blue versions certainly make Fig.8 easier to understand. Also, the green and blue look pretty on the board. See page 6 for further details and other great back-issue offers. Purchase and download at: www.electronpublishing.com Furthermore, my blue LEDs have the same 3V forward-voltage drop as my green LEDs, which means we can use the same values for our current-limiting resistors. Of course, you may say that I’m overengineering things, to which I would respond that I’m playing to my strengths because overengineering things is one of the things I do best. Also, I have boxes of LEDs lying around and more LEDs make everything better (a simple rule of thumb, but I’m a simple man). I just added these blue LEDs to my own dual-board combo, which has certainly brightened my day. Last, but not least, this is a prototype and we’re trying to make our lives easier by detecting any potential problems early in the game. We would remove these LEDs if we ever decided to create a production version of our project. Next time In our next column, we are going to use the hour and minute values from our RTC to drive our 7-segment display. Think of a time like 12:17 (seventeen minutes past twelve o’clock). This has four digits, but we have only one display. Let’s all start thinking about how we are going to use our display to present these values. Until next time, have a good one! 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 Practical Electronics | March | 2024 From Arduino Fig.8. Checking all the power rails. 61