Silicon ChipMax’s Cool Beans - January 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: Cheeky chiplets by Max the Magnificent
  8. Feature: Net Work by Alan Winstanley
  9. Project: Active Mains Soft Starter by John Clarke
  10. Project: ADVANCED SMD TEST TWEEZERS by Tim Blythman
  11. Project: Active Subwoofer For Hi-Fi at Home by Phil Prosser
  12. Feature: Max’s Cool Beans by Max the Magnificent
  13. Feature: Circuit Surgery by Ian Bell
  14. Feature: MITCHELECTRONICS by Robin Mitchell
  15. Project: Audio Out by Jake Rothman
  16. PCB Order Form
  17. Advertising Index: Bush MB60 portable radio by Ian Batty

This is only a preview of the January 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)
Items relevant to "Active Mains Soft Starter":
  • Active Mains Soft Starter PCB [10110221] (AUD $10.00)
  • PIC12F617-I/P programmed for the Active Mains Soft Starter [1011022A.HEX] (Programmed Microcontroller, AUD $10.00)
  • Firmware for the Active Mains Soft Starter [1011022A] (Software, Free)
  • Active Mains Soft Starter PCB pattern (PDF download) [10110221] (Free)
  • Active Mains Soft Starter lid panel artwork (PDF download) (Free)
Articles in this series:
  • Active Mains Soft Starter, Part 1 (February 2023)
  • Active Mains Soft Starter, Part 2 (March 2023)
  • Active Mains Soft Starter (January 2024)
  • Active Mains Soft Starter (February 2024)
Items relevant to "ADVANCED SMD TEST TWEEZERS":
  • Advanced/ESR Test Tweezers back panel PCB (blue) [04105242] (AUD $2.50)
  • Advanced SMD Test Tweezers PCB set [04106221+04106212 {blue}] (AUD $10.00)
  • PIC24FJ256GA702-I/SS programmed for the Advanced SMD Test Tweezers (0410622A.HEX) (Programmed Microcontroller, AUD $15.00)
  • 0.96in cyan OLED with SSD1306 controller (Component, AUD $10.00)
  • Advanced SMD Test Tweezers kit (Component, AUD $45.00)
  • Firmware for the Advanced SMD Test Tweezers [0410622A.HEX] (Software, Free)
  • Advanced SMD Test Tweezers PCB patterns (PDF download) [04106221+04106212] (Free)
  • Advanced SMD Test Tweezers sticker artwork (PDF download) (Panel Artwork, Free)
Articles in this series:
  • Advanced Test Tweezers, Part 1 (February 2023)
  • Advanced Test Tweezers, Part 2 (March 2023)
  • ADVANCED SMD TEST TWEEZERS (January 2024)
  • ADVANCED SMD TEST TWEEZERS (February 2024)
Items relevant to "Active Subwoofer For Hi-Fi at Home":
  • Bookshelf Speaker Passive Crossover PCB [01101201] (AUD $10.00)
  • Bookshelf Speaker Subwoofer Active Crossover PCB [01101202] (AUD $7.50)
  • Bookshelf Speaker Passive and Active Crossover PCB patterns (PDF download) [01101201-2] (Free)
  • Bookshelf Speaker System timber and metal cutting diagrams (PDF download) (Panel Artwork, Free)
Articles in this series:
  • Easy-to-build Bookshelf Speaker System (January 2020)
  • Building the new “bookshelf” stereo speakers, Pt 2 (February 2020)
  • Building Subwoofers for our new “Bookshelf” Speakers (March 2020)
  • Stewart of Reading (October 2023)
  • Stewart of Reading (November 2023)
  • ETI BUNDLE (December 2023)
  • Active Subwoofer For Hi-Fi at Home (January 2024)
  • Active Subwoofer For Hi-Fi at Home (February 2024)
Articles in this series:
  • Audio Out (January 2024)
  • Audio Out (February 2024)
  • AUDIO OUT (April 2024)
  • Audio Out (May 2024)
  • Audio Out (June 2024)
  • Audio Out (July 2024)
  • Audio Out (August 2024)
  • Audio Out (September 2024)
  • Audio Out (October 2024)
  • Audio Out (March 2025)
  • Audio Out (April 2025)
  • Audio Out (May 2025)
  • Audio Out (June 2025)
Max’s Cool Beans By Max the Magnificent Arduino Bootcamp – Part 13 But first… I’ve received several emails from readers saying they remain confused by the concept of forward voltage drop in diodes in general, with light-emitting diodes (LEDs) forming a special case. As you may recall, we introduced this concept as part of calculating the value of an LED’s current-limiting resistor in our first Arduino Bootcamp column (PE, January 2023). In our second Bootcamp column (PE, February 2023), we noted that the data sheet for the 7-segment display we’re using stated that its LED segments had a forward voltage drop (aka VF) of 2V and a maximum allowable forward current (IF) of 20 milliamps (20mA), or 0.02A. As we are working with the Arduino Uno’s 5V supply, and since we are working on the assumption that we want our segments to be as bright as possible, then using Ohm’s Law V = I × R (which we can refactor as R = V/I) we calculated the value of our current-limiting resistors as R = (5V – 2V) / 0.02A = 150Ω. The question remains as to why we subtract V F from our 5V supply. Although the equation is simple, the underlying mechanism is less than obvious to beginners (I know it confused the heck out of me). Well, the way a diode works, it doesn’t start conducting until the potential difference across its input and output is greater than its forward voltage drop value. For any potential greater than this, we are currently assuming the LED acts like a simple piece of wire (apart from it emitting light, of course). The way I describe this if I’m giving a lecture is illustrated in Fig.1. 42 There’s more… Transistors are semiconductor devices that can be used in various roles, including analogue amplifiers and digital switches. The two main classes of transistor with which we (well, you and I) typically come into contact are bipolar junction transistors (BJTs) and field-effect transistors (FETs). For the purposes of this column, we will be experimenting with a BJT. We can dope pure, non-conducting silicon (add impurities into the crystal lattice) to form conducting N-type and P-type silicon. Any interfaces between these different flavours are where most of the magic occurs. BJTs come in two flavours, each with three doped regions ordered as NPN or PNP. The symbol for a generic NPN transistor is shown in Fig.2. Note the arrow pointing out of the heart of the transistor toward the emitter terminal. In the case of a PNP transistor symbol, this arrow would be pointing the other way. Two useful mnemonics are Not Pointing iN (NPN) and Pointing iN Proudly (PNP). The origins of the terminal names (base, collector, and emitter) are too Lake C hannel 2' 2' 2' flow Lake C hannel 0' (a) 2' of water in lake , no barrier, 2' of water flowing in channel 2' (b) 2' of water in lake , 2' barrier, 0' of water flowing in channel 3' flow Lake C hannel 3' Imagine we have a lake, which represents our power source, feeding a channel, which represents a wire. The height of the water in the lake is equivalent to voltage, while any flowing water is equivalent to current. Fig.1a depicts a lake with 2 feet (yes, I’m an Imperial units chap here the US) of water (equivalent to 2V in our electrical circuit) and an unobstructed channel through which the water from the lake flows. By comparison, in Fig.1b we introduce a 2-foot-high barrier, which represents our diode, across our channel, which represents our wire. In this case, assuming the water in the lake is 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 barrier is 2 feet tall, the result will be 3 feet of water flowing through the channel. I know analogies are always suspect, but I must admit to being rather proud of this one. 3' is my current favorite expression.) I can’t believe it’s practically 2024 already. I don’t have a speech prepared and I don’t have anything applicable to wear. What I do know is that we are poised to perform some exceedingly exciting experiments, so let’s make sure we are all dressed appropriately. I’m thinking Monty Python Gumby attire (https://bit.ly/3StpyHL), which – by some strange quirk of fate – means I’m already ready to rock and roll. 2' W TW? (‘What the What,’ (c) 5' of water in lake , 2' barrier, 3' of water flowing in channel Fig.1. A graphical depiction of a diode’s forward voltage drop. befuddling to go into here. Suffice it to say that the base acts as the control terminal. In the case of an NPN transistor wired as shown in Fig.2a, connecting the In signal to 0V will turn the transistor off (making it look like an open circuit or a break in the wire), in which case the Out signal will be pulled-up to 5V by the resistor. By comparison, connecting the In signal to 5V will turn the transistor on, thereby connecting the Out signal to 0V through the transistor. When we consider the operation of this simple circuit (Fig.2b), we see that the transistor is acting as an inverter; that is, the Out signal has the opposite value to the In signal. What’s not obvious from Fig.2 is that only a small amount of current needs to be applied to the base (known as the base current, IB). This small current is amplified into a much larger current flowing between the collector and the emitter (this is known as the collector current, 5V 5V In Out 0V 5V Collector In Out Base 0V Emitter 0V (a) NPN Transistor (b) Operation Fig.2. A generic NPN transistor. Practical Electronics | January | 2024 From Arduino From Arduino From Arduino 150 Ω C B 1kΩ 0V (a) Original circuit 0V (b) Switch on cathode B C 377 E 0V (c) Transistor on cathode Fig.3. Controlling all the segments together. IC). I don’t want to give too much away here, but suppose we wished to control all eight* LEDs on our 7-segment display with a single pin on our Arduino (*in addition to the 7 main segments, there’s also a DP (decimal point) segment). Since each segment has a maximum current of 20mA, we would be talking about 8 × 20mA = 160mA. Unfortunately, the digital pins on an Arduino Uno have a maximum current limit of only 40mA, and they really shouldn’t be asked to handle more than 20mA for extended periods of time. Happily, we can easily find a transistor that can handle an IC current of 160mA between its collector and emitter terminals, and we can control such a transistor by applying a much smaller current – one the Arduino can easily supply – to the transistor’s base. That’s all we need to know to set the stage for the wonders that are to come. If you wish to learn more about fundamental BJT and FET concepts, may I make so bold as to recommend my book, Bebop to the Boolean Boogie: An Unconventional Guide to Electronics – see: https://bit.ly/3u9XIWV Semiconductor switcheroo We introduced the concept of light-dependent resistors (LDRs) in our previous column (PE, December 2023). We finished that column by employing our Arduino to read values from an LDR and display those values on the Serial Monitor. If you wish, you can refresh your memory by downloading a copy of this program (file CB-Jan24-01.txt). As usual, all the files mentioned in this column are available from the January 2024 page of the PE website (https://bit. ly/pe-downloads). If you’ve been following this series, you will be more than familiar with our existing breadboard layout, which – at its heart – has our single-digit common cathode 7-segment display along with eight 150Ω current-limiting resistors (one per segment). However, if you’re new to the party, you might wish to download an image of our current breadboard layout showing our LDR, trimpot, piezoelectric buzzer and 7-segment display – along with various pull-up and current-limiting resistors – coupled with Practical Electronics | January | 2024 the connections to our Arduino Uno (file CB-Jan24-02.pdf). What we want to do now is use the value from an LDR to control the brightness of our 7-segment display. We’re going to keep this simple. In low-light conditions (which we will start off by defining as any LDR reading less than 200), we will assume it’s night time and we will dim our display to a fraction of its full brightness. For any higher ambient light level (an LDR reading of 200+), we will drive our display as brightly as we can. Until now, the way we’ve been controlling the LEDs on our 7-segment display is as illustrated in Fig.3a. In this case, the anode of each LED is controlled by its own digital pin on the Arduino (since we’re using a common-cathode display, all the LEDs’ cathodes are connected and presented as one). In our last-but-one column (PE, November 2023), we noted that Arduinos include special hardware implementations of pulse-width modulation (PWM) functions associated with some of their digital pins. In the case of the Arduino Uno, there are six such pins (3, 5, 6, 9, 10, 11), indicated by ‘~’ characters on the board. The Arduino doesn’t have true analogue outputs but – as discussed in an earlier column (PE, March 2023) – the PWMs provide a pseudo-analogue capability. We access the PWMs using calls to the Arduino’s built-in analogWrite() function, which accepts two arguments – the pin we wish to control and a value between 0 and 255. One of the PWM-equipped pins (pin 6) drives segment D on our 7-segment display. The way we’ve wired our circuit, a PWM value of 0 on Pin 6 will turn that segment fully off (0% brightness), a value of 255 will turn it fully on (100% brightness), and in-between values will result in a corresponding brightness (128 will result in 50% brightness, for example). We experimented with this in PE, November 2023. Let’s suppose we now wish to control the brightness of all the segments on the display using PWM functionality. There are two problems with our current approach. First, we have eight segments on the display but only 6 PWM-equipped pins on the Arduino. Second, it would be painful (figuratively speaking) for us to be obliged to specify the brightness values of the segments individually. What we want is a way to control the brightness of all the segments simultaneously. The only pin that’s shared by all the LEDs is the display’s common cathode. Suppose we added a handcontrolled switch (Fig.3b). Now, we can turn the segments on and off individually using the Arduino’s pins, and we can turn them on and off collectively using our switch. If we could repeatedly turn our switch on and off quickly enough, thereby implementing a clunky PWM function, we could control the brightness of all active segments simultaneously. The solution is to replace our switch with a transistor and to control that transistor using one of the Arduino’s PWM-equipped pins (Fig.3c). (Yes, a ‘Tra-la’ is certainly in order.) Which transistor? This is where things start to get interesting. When turned on, NPN transistors have their own voltage drop. As a rule of thumb, we typically assume this to be 0.7V. Returning to Fig.1c, this is like adding an extra 0.7 feet to our existing 2-foot barrier, resulting in 5 – 2.7 = 2.3 feet of water flowing through the channel. Suppose we stick with our existing 150Ω current-limiting resistors. Returning to Ohm’s law V = I × R, we now know V and R, so refactoring the equation to be I = V/R gives us I = (5 – 2.7) / 150 = ~15mA. This means that if all eight segments are fully on, we will have a total current of 8 × 15mA = 120mA. If we were desperate to achieve the maximum possible brightness, which – as we know – corresponds to an IF of 20mA, we could recalculate the values of our current-limiting resistors using R = V/I, which gives us R = (5V – 2.7V) / 0.02A = 115Ω. Since the closest standard resistor values are 110Ω and 120Ω, we would opt for the higher value of 120Ω, resulting in a slightly lower current of I = (5 – 2.7) / 120 = ~19mA, which is ‘close enough for government work,’ as they say. Are you desperate enough to replace all your 150Ω current-limiting resistors with their 120Ω counterparts? If so, go for it. For myself, I’m going to stick with what we’ve got (for the moment, at least). The internet is a wonderful resource, but it’s not without its problems. For example, if you perform a Google search for something like ‘Controlling the brightness of a common-cathode 7-segment display with a transistor,’ you may run across circuits showing BC547 NPN transistors (for example, https:// bit.ly/49zpYTa). Rather than blindly 43 Fig.4. Removing the two GND wires. F A G B E DP C AREF GND 13 12 ~11 ~10 ~9 8 7 ~6 ~5 4 ~3 2 TX-1 RX-0 D Remove these wires DIGITAL IN/OUT (PWM ~) Listing 3a. Light up all the segments. follow someone else’s circuit, this is the point when you should say to yourself, ‘Let me check the data sheet first’ at: https://bit.ly/479vs5p It doesn’t take long to discover that the BC547 has a maximum IC of only 0.1A, or 100mA, which isn’t sufficient to handle the 120mA associated with our existing 150Ω currentlimiting resistors, let alone the 8 x 19mA = 152mA we would see if we decided to use 120Ω current-limiting resistors. There are two solutions, if we were on a mission-critical assignment to save the world (I’ve been watching too many science fiction films) and all we had at our disposal was a single BC547 transistor that we were determined to use, then we could say that our maximum IC of 100mA equates to 100mA/8 segments = 12.5mA per segment. Using this new intelligence, we could recalculate our current-limiting resistors as R = (5V – 2.7V) / 0.0125A = 184Ω. In this case, the closest standard resistor values are 180Ω and 200Ω, and we would opt for the latter to be on the safe side. However, since we aren’t tasked with saving the world, and as we aren’t pushed for time, a better alternative is to select a transistor capable of meeting our requirements, such as the BC377, for example. Checking its datasheet, we see this little scamp has a maximum IC of 1A, which is more than sufficient to meet our current (no pun intended) and future needs – see: https://bit.ly/3QCc3mo We will be requiring only one BC377 in this column, but we will be using two or three in future experiments, so I’d get at least five (‘just because’). You can obtain these little rascals from any component supplier, but I just found an awesome deal on Amazon for a variety of 20 each of ten types of NPN and PNP transistors (including BC377s), which means a total of 200 transistors, all for only £6.99: https://bit.ly/40xAgyS This is mind-boggling when you think that this would have been the price of a single transistor circa 1960. One step at a time If I’ve taught you anything in this series, I hope it includes taking things one step at a time. This is because it’s a lot easier to verify and debug things in isolation than it is to tackle a bunch of things all at once. So, before we add our transistor 44 into the mix, let’s start by creating a simple program whose task is to light all the segments on the display, including the decimal point (Listing 3a, file CB-Jan24-03.txt). (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-Jan24-03.txt in this example], after which we use ‘a’, ‘b’, ‘c’… suffixes as appropriate.) There’s nothing here we haven’t seen before. On Lines 4 and 5, we declare an array of integers PinsSegs[], which we initialise with the numbers of the Arduino pins that are driving the LEDs in our 7-segment display. On Lines 12 through 16 in our setup() function, we use a for() loop to cycle through each pin in turn, first defining it as being an OUTPUT, and then assigning it a value of SEG_ON, which will light that segment up. Once all of the segments have been illuminated, the loop() function just cycles round doing nothing. I just ran this program. All my LEDs are glowing furiously, which means we’re now ready to turn our attention to the transistor itself (imagine a roll of drums if you will) ... Adding the transistor Before we add the BC377 transistor to our breadboard, we first need to make some changes. Specifically, we need to remove the two black ground (GND) wires shown in Fig.4. Why two GND wires? Isn’t that a little enthusiastic? Well, as we discussed when we first established our breadboard (PE, February 2023), the display we are using has two pins (3 and 8) that are connected inside the device to form the common cathode. We could have connected either of these to the GND (0V) rails on our breadboard. The reason we connected both is to provide redundancy. If one of our black jumper leads is bad (broken inside), for example, then the other will suffice. As we also discussed, although we don’t need both connections in this instance, we would use both if we were creating a safety-critical or mission-critical system ‘just in case,’ and this is a good mindset to adopt. The BC377 transistor we are using is presented in a TO-92 plastic package (Fig.5). The pin numbers are associated with the package, which means they’re always the same in relation to the package’s ‘D’ shape. However, the association between the pin numbers and the collector, base and emitter signals can vary on a transistor-type-by-transistor-type basis, so be careful and always check the data sheet! Let’s add this transistor to 1 Collector our breadboard, along with associBase 2 ated wires, as illustrated in Fig.6. 3 Emitter If we compare Fig.6 to Fig.3c, 1 2 3 we see that the green wire con(a) Symbol (b) TO -92 Package nects the collector (pin1) on the transistor to pin 3 on the 7-seg- Fig.5. BC377 symbol and ment display. The black wire plastic D-shaped package. Practical Electronics | January | 2024 Fig.6. Adding the BC377 transistor. F A G B DP E D C 1C 2B AREF GND 13 12 ~11 ~10 ~9 8 7 ~6 ~5 4 ~3 2 TX-1 RX-0 B C 377 E 3 DIGITAL IN/OUT (PWM ~) Listing 6a. Definitions and pin assignments. connects the emitter (pin 3) on the transistor to the GND (0V) rail. And the base (pin 2) on the transistor is connected to one side of a 1kΩ (brown, black, red) resistor, the other side of which is connected to pin 11 on the Arduino using a purple wire. As denoted by the ‘~’ character on the Arduino’s board, this pin is equipped with a hardware PWM function inside the Arduino. An image of our full breadboard layout – including the BC377 – is available for your perusing pleasure (file CBJan24-04.pdf). OK, let’s modify our current test program to cause all the segments on the display to cycle around gradually brightening and dimming. We’ll start by adding a new definition, STEP_DELAY, which we will use to control the speed with which the display brightens and dims. We’ll also declare an integer PinTran to which we will assign the number of the Arduino pin (pin 11) that we are using to drive the base of our transistor (via the 1kΩ resistor). The setup() function turning all the segments on individually will remain unchanged. The main modification will be to the loop() function, as illustrated in Listing 5a (file CB-Jan24-05.txt). Since all the segments have been lit up by the setup() function, we commence the loop() function by fading everything down using the for() loop on Lines 28 to 32, after which we fade everything back up again using the for() loop on Lines 35 to 39. To be honest, wrapping our brains around how this works requires some mental gymnastics. We know that we’ve used the setup() function to apply HIGH (5V) to all the segment Listing 5a. Using the transistor to control the brightness. Practical Electronics | January | 2024 anodes to turn the LEDs on. We also know that if we apply the same electrical potential (eg, 5V) to both sides of an LED, then it won’t conduct, so why do we start our for() loop on Line 28 with a value of 255, which equates to 5V on the Arduino’s pin? Allow me to refer you back to Fig.2 and remind you that our transistor acts as an inverter. This means that when we use the Arduino to drive 255 (5V) onto the base of our BC377 transistor at the start of our for() loop on Line 28, this turns the transistor on, which connects the common-cathode pin on the 7-segment display to GND, thereby activating all of the segments. Similarly, when we use the Arduino to drive 0 (0V) onto the base of the transistor at the end of our for() loop on Line 28, this turns the transistor off, which prevents it from conducting, thereby deactivating all of the segments. Upping the ante Just for giggles and grins, I’ve combined a couple of our earlier programs together. I started with the program we created last month (PE, December 2023) that reads the value from the trimpot, maps it into a range of 0 to 9, presents this value on our 7-segment display, and plays a musical note corresponding to that number using our piezoelectric buzzer. I also took parts of the program from last month that reads the value of the LDR, along with parts of the program from this month that uses our transistor to control the brightness of the display. I munged all this together to form a new super-duper program that reads the value from the trimpot, maps it into a range of 0 to 9, presents this value on the 7-segment display, plays a musical note, and reads the value from the LDR. If the value on the LDR is >=200 (greater than or equal to 200), then the value on the 7-segment display is presented at full brightness, otherwise it’s dimmed to a fraction of its full value. You can peruse and ponder this program at your leisure (file CB-Jan24-06.txt). All we need to do at the moment is look at the definitions and pin assignments (apart from the pins driving the segments), as seen in Listing 6a, along with the main loop() function, as shown in Listing 6b. You’ll see we’ve moved things around a bit in the loop() function, but it’s still fundamentally similar to what we’ve seen before. We use the if() test on Line 78 to see if our trimpot has changed. If so, we present the new value on our 7-segment display and we play a tone on our piezo buzzer. We now perform a new if() test on Line 88. If the value read from our LDR is >= NIGHT_LDR (which we’ve tentatively defined as 200), then we use the transistor to drive the display at its full brightness, otherwise, we drive it at a fraction of this value. We’re still using serial commands on Lines 93 to 96 to display the mapped values from the trimpot, along with the 45 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 Components for Part 12 Light-Dependent Resistor https://bit.ly/3S2430m Components for Part 13 BC337 NPN Transistor https://bit.ly/40xAgyS Listing 6b. The main loop() values read from the LDR, on the Serial Monitor to help us to work out what’s happening. For example, I started off with my LDR exposed to roomlevel light, which resulted in my 7-segment display operating at full brightness as expected. However, when I put my finger over the LDR, the 7-segment display continued to operate at full brightness. Looking at the Serial Monitor revealed that although the value from the LDR had fallen, it was still higher than the 200 threshold I’d set. The problem is that light seeps in through the sides of the LDR as well as through its face. Shrouding the LDR with a small piece of cardboard caused its value to fall below 200, at which time the 7-segment display dimmed accordingly (hurrah!). If we were using this technique to control a bedside clock, for example, then we would perform some real-world experiments to determine the ideal threshold value. We might also provide some way for the user to modify the threshold value, but that’s a story for another day. Fig.7. The HC-SR04 ultrasonic sensor (Source: Adafruit) are classed as ‘infrasound.’ Although barely perceptible to humans, various animals – including elephants, hippopotamuses and whales – communicate via infrasonic means. Frequencies above 20kHz are classed as ‘ultrasound.’ Some animals – like dolphins, frogs and tarsiers – communicate using ultrasonic sounds; others, like bats, use ultrasound for echolocation purposes. Have you ever seen bats flying at night? Their ability to use ultrasonic echolocation to navigate through complex three-dimensional terrains while identifying and homing in on prey like moths and mosquitoes is nothing short of phenomenal. It’s so phenomenal that a huge chunk of their little batty brains is devoted to hearing. As Groucho Marx famously said, ‘From the moment I picked your book up until I laid it down, I was convulsed with laughter. Someday I intend reading it.’ The reason I mention this here is that there’s a legendary paper on the topic of consciousness by American philosopher Thomas That’s batty! Nagel titled, What Is It Like to Be a Bat? – someday I intend The hearing ability of a healthy young human typically reading it – see: https://bit.ly/3SyGmgz spans 20Hz to 20,000Hz (20kHz). Frequencies below 20Hz In the meantime, humans have developed technologies Cool bean Max Maxfield (Hawaiian shirt, on the right) is emperor of all he that allow is to use ultrasonic surveys at CliveMaxfield.com – the go-to site for the latest and greatest sound for things like object in technological geekdom. detection and distance measureComments or questions? Email Max at: max<at>CliveMaxfield.com ment. For example, there’s the 46 Practical Electronics | January | 2024 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. also display the result on… you guessed it… our 7-segment display. This will be the first step along our path to creating a suite of 1-digit, 2-digit, and 4-digit clocks. Until then, as always, I’m only an email away. 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 well-known HC-SR04 ultrasonic sensor (Fig.7). This little beauty is available from multiple suppliers, including Adafruit via Amazon: https://bit.ly/49AMBq4 Next time I can barely control my excitement, because we are going to do all sorts of cool things in our next column. We will commence by employing an HC-SR04 ultrasonic sensor to measure distances, present the results on our 7-segment display, and implement a soon-to-be fabled therabone, which will be our 21st Century answer to the 20th Century’s theremin: https://bit.ly/3ubLrBj Next, while the haunting sound of the therabone still echoes in our ears (and tears of joy still roll down our cheeks), we are going to introduce the concept of real-time clocks (RTCs). In addition to using an RTC to keep track of the time, we will See page 6 for further details and other great back-issue offers. Purchase and download at: www.electronpublishing.com Teach-In 8 CD-ROM Exploring the Arduino EE FR -ROM CD ELECTRONICS TEACH-IN 8 FREE CD-ROM SOFTWARE FOR THE TEACH-IN 8 SERIES FROM THE PUBLISHERS OF This CD-ROM version of the exciting and popular Teach-In 8 series has been designed for electronics enthusiasts who want to get to grips with the inexpensive, immensely popular Arduino microcontroller, as well as coding enthusiasts who want to explore hardware and interfacing. Teach-In 8 provides a one-stop source of ideas and practical information. The Arduino offers a remarkably effective platform for developing a huge variety of projects; from operating a set of Christmas tree lights to remotely controlling a robotic vehicle wirelessly or via the Internet. Teach-In 8 is based around a series of practical projects with plenty of information for customisation. The projects can be combined together in many different ways in order to build more complex systems that can be used to solve a wide variety of home automation and environmental monitoring problems. The series includes topics such as RF technology, wireless networking and remote web access. PLUS: PICs and the PICkit 3 – A beginners guide The CD-ROM also includes a bonus – an extra 12-part series based around the popular PIC microcontroller, explaining how to build PIC-based systems. £8.99 INTRODUCING THE ARDUINO • Hardware – learn about components and circuits • Programming – powerful integrated development system • Microcontrollers – understand control operations • Communications – connect to PCs and other Arduinos PLUS... PIC n’MIX PICs and the PICkit 3 - A beginners guide. The why and how to build PIC-based projects Teach In 8 Cover.indd 1 04/04/2017 12:24 PRICE £8.99 Includes P&P to UK if ordered direct from us SOFTWARE The CD-ROM contains the software for both the Teach-In 8 and PICkit 3 series. ORDER YOUR COPY TODAY! JUST CALL 01202 880299 OR VISIT www.epemag.com Practical Electronics | January | 2024 47