Silicon ChipKickStart - February 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: What is it about Tesla?
  7. Feature: A thousand words by Mark Nelson
  8. Feature: The Fox Report by Barry Fox
  9. Feature: Net Work by Alan Winstanley
  10. Project: Solid-State Flame Discharge by Flavio Spedalieri
  11. Project: Cooling Fan Controller & Loudspeaker Protector by John Clarke
  12. Project: Driveway Gate Remote Control by Dr Hugo Holden
  13. Project: Geekcreit’s LTDZ V5.0 Spectrum Analyser by Jim Rowe
  14. Feature: KickStart by Mike Tooley
  15. Feature: Make it with Micromite by Phil Boyce
  16. Feature: Circuit Surgery by Ian Bell
  17. Feature: Max’s Cool Beans by Max the Magnificent
  18. PCB Order Form
  19. Advertising Index

This is only a preview of the February 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)
KickStart by Mike Tooley Part 11: Sensing the environment – introducing the BME280 sensor Our occasional KickStart series aims to show readers how to use readily available low-cost components and devices to solve a wide range of common problems in the shortest possible time. Each of the examples and projects can be completed in no more than a couple of hours using ‘off-the-shelf’ parts. As well as briefly explaining the underlying principles and technology used, the series will provide you with a variety of representative solutions and examples, along with just I recently became the proud owner of an antique ‘weather station’ – a barometer incorporating a thermometer and hygrometer and wanted to have a means of checking its accuracy when making measurements of pressure, temperature and humidity. The solution to this problem proved to be very simple and straightforward. It first involved finding a suitable sensor, interfacing it with an Arduino Uno microcontroller, and adding a low-cost 20x4-character LCD module on which to display the results. The entire task (including software development and testing) was accomplished in less than a couple of hours. My recently acquired antique instrument (see Fig.11.1) uses a column of mercury contained in a glass tube with one end open and the other end sealed. The open bottom of the tube is placed in a reservoir filled with mercury with the upper surface of the mercury in the reservoir open to atmospheric pressure (for more details, see: https://bit.ly/pe-jan23-hg). When raised into position, the mercury level in the glass tube descends, creating a vacuum at the top. The weight of mercury in the glass tube is then balanced against the atmospheric pressure acting on the reservoir. By this means the height of mercury in the column is an indicator of the current atmospheric pressure. Increasing pressure indicates good weather, with the chance of it being cold during winter months. Decreasing Fig.11.1. (left) The author’s late-Regency mahogany-cased mercury barometer incorporates a large circular silvereddial, mercury-in-glass thermometer (long rectangular display), hygrometer (top circular dial), and at the bottom, a (redalcohol) spirit level. 46 enough information to be able to adapt and extend them for their own use. This eleventh instalment introduces the latest in a series of low-cost environmental sensors from component manufacturer Bosch. This powerful device will allow you to accurately sense temperature, pressure, and humidity. Its I 2C connectivity solves the problem of connection to a host such as an Arduino microcontroller or Raspberry Pi computer. pressure generally indicates that the weather is set to worsen, with storms and winds likely. A rapid drop in pressure usually signifies that a storm can be expected in the next few hours. Antique mercury barometers are invariably shipped in safe transportation mode and thus arrive unset. The in-built safety mechanism locks the needle and pulleys, preventing damage in transit. On arrival, the barometer needs to be assembled, positioned, and then the user can manually set the instrument to the current ambient pressure. The process usually involves an adjustment that sets the indicating pointer to the required position. Once the barometer is set, it is ready for use. Modern electronic barometric instruments, with their tiny sensors, microcontrollers and digital displays avoid this process completely. Fig.11.2. Sensor module incorporating a BME280 sensor with I2C interface circuitry on the reverse side. Practical Electronics | February | 2023 Introducing the BME280 sensor In forced mode, a single measurement is performed in accordance with the selected measurement and filter options. When the measurement is finished, the sensor returns to sleep mode and the measurement results can be obtained from the data registers. For the next measurement, forced mode needs to be selected. This mode is recommended for applications that require relatively low sampling rates or those that rely on host-based synchronisation. Normal mode involves continuous cycling between an active measurement period and an inactive standby period. The measurements are performed in accordance with the selected measurement and filter options. The standby time can be set to between 0.5 and 1000ms. The BME280 uses an infinite impulse response (IIR) filter to cope with short-term disturbances (eg, blowing air into the sensor) the output of which is computed using the current and previous input value together with the previous output value. Note that normal mode is recommended whenever the IIR filter is used. Pressure units may be set in pascal (Pa), hectopascal (hPa), inches of mercury, (in-Hg), relative to standard atmosphere (atm), bar (metric unit of pressure equal to 100 kPa), torr (1/760 of a standard atmosphere or 133.32 Pa) or pounds per square inch (psi). Temperature units can be set to Celsius The Bosch Sensortec BME280 is a combined humidity, pressure and temperature sensor housed in a tiny metal LGA package. Small dimensions (the package measures a mere 2.5 x 2.5 x 0.93 mm) coupled with minimal power requirements make this sensor ‘chip’ ideal for use in a wide variety of portable and hand-held devices. The BME280 combines sensors for humidity, pressure and temperature for use in a wide range of applications including environmental control, measurement, automation, logistics and navigation. The humidity sensor provides an extremely fast response time for rapid context awareness applications and high overall accuracy over a wide temperature range. The pressure sensor is an absolute barometric pressure sensor with extremely high accuracy and resolution (and for those familiar with its predecessor, the BMP180, significantly less noise). The integrated temperature sensor is optimised for low noise and high resolution, and its output is available for temperature compensation of the pressure and humidity sensors. It can also be used to provide an estimate of the ambient temperature. The BME280 provides both SPI and I2C interfaces and requires a supply voltage in the range 1.71V to 3.6V for the sensor supply and 1.2V to 3.6V for the interface supply. Measurements can be triggered by a host microcontroller or performed at pre-set intervals. When the sensor is disabled, current consumption drops to a mere 0.1μA. Current consumption ranges from around 350μA when measuring humidity and temperature to a little over 700μA when measuring pressure. Standby current (when operating but not actually making a measurement) is less than 0.5μA. To tailor data rate, noise, response time and current consumption to the requirements of a particular application, a variety of oversampling modes, filter modes and data rates can be selected. All of this is achieved as part of the sensor’s software configuration. BME280 sensor operating modes The three BME280 operating modes offers three sensor modes: n Sleep – (no operation, all registers accessible, lowest power, initiated at start-up) n Forced – (perform one measurement, store results and then return to sleep mode) n Normal – (perpetual cycle of measurement and inactive periods). Sleep mode is entered by default after power on reset. In sleep mode, no measurements are performed, and power consumption remains at a minimum. All internal registers are accessible and internal parameters can be read. There are no special restrictions on interface timings. Fig.11.3. Complete circuit schematic for the BME280 environmental monitor. Table 11.1 Recommended settings for representative BME280 applications Parameter Field of application Weather monitoring Humidity sensing Navigation Gaming Forced Forced Normal Normal Sample rate 1 per minute 1 per second n/a n/a Standby time n/a n/a 0.5ms 0.5ms Pressure ×1 ×0 ×16 ×4 Temperature ×1 ×1 ×2 ×1 Humidity ×1 ×1 ×1 ×0 Mode Filter Current consumption RMS noise Data output rate Off Off ×16 ×16 0.16μA 2.9μA 633μA 581μA 3.3Pa/30cm, 0.07% RH 0.07% RH 0.2Pa/1.7 cm 0.3Pa/2.5 cm 1/60Hz 1Hz 25Hz 1.75Hz Practical Electronics | February | 2023 47 (°C) or Fahrenheit (°F). The BME280’s operating mode may be set to either sleep, forced or normal, as required by a particular application (see Table 11.1). Standby time can be set between 50μs and 1s in discrete steps, while the IIR filter can be configured for four values, again depending on the application concerned (see Table 11.1). Further information can be found in the BME280’s header file (BME280.h – see Going Further for download details). BME280 electronic barometer Thanks to its ability to measure p r e s s u r e , h u m i d i t y, a n d temperature within the same sensor, the BME280 was an ideal candidate for use as the basis of my electronic barometer. To simplify the task, the BME280 is supplied ready-mounted on a small circuit board (see Fig.11.2). The prebuilt module also contains the necessary interfacing and power conditioning circuitry (see Going Further for a source). All that is then required is an I2C connection to the host microcontroller (an Arduino Uno) and the I2C 20x4 LCD module on which to display the currently measured values. The complete circuit schematic for the BME280 electronic barometer is shown in Fig.11.3. The four connections to the BME280 sensor module shown earlier in Fig.11.2, are: n SDA I2C serial data n SCL I2C serial clock n VIN DC supply input (+3.3V) n GND common ground (0V). While the electronic barometer can be quickly and easily assembled using short wire links and coloured jumper leads, a lowcost prototyping shield will help simplify interconnection of the three main components: BME280 sensor module, Arduino Uno, and the 20x4 LCD, as shown in Fig.11.4. The DC supply for the electronic barometer can be obtained via the Arduino’s USB port during testing. However, once programming has been completed, the whole system can be powered from an external DC source of between +7V and +12V applied to the Arduino’s unregulated DC power jack. Coding the electronic barometer Using readily available libraries (see the Going Further section 48 Listing 11.1. BME280 Arduino code for an electronic weather station /* Electronic barometer using an Arduino and BME280 sensor Requires the BME280 library by Tyler Glenn and the LiquidCrystal_I2C library */ #include <BME280I2C.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,4); BME280I2C bme; // BME280 I2C library // LCD I2C library // set the LCD parameters void setup() { lcd.init(); // initialize the display lcd.backlight(); Serial.begin(9600); // serial debugging if needed Serial.println("Waiting...."); while(!Serial) {} // Wait Wire.begin(); Serial.println("Starting!"); while(!bme.begin()) { Serial.println("Could not find BME280 sensor!"); delay(1000); } switch(bme.chipModel()) { case BME280::ChipModel_BME280: Serial.println("Found BME280 sensor! Success"); break; case BME280::ChipModel_BMP280: Serial.println("Found BMP280 sensor! Humidity unavailable"); break; default: Serial.println("Found UNKNOWN sensor! Error!"); } } void loop() { float temp, hum, pres, mb; BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); BME280::PresUnit presUnit(BME280::PresUnit_Pa); bme.read(pres, temp, hum, tempUnit, presUnit); mb = pres/100; lcd.clear(); lcd.setCursor(0,0); lcd.print(" BME280 SENSOR DATA"); lcd.setCursor(0,1); lcd.print("Temp: "); lcd.print(temp); lcd.print(" C"); lcd.setCursor(0,2); lcd.print("Pressure: "); lcd.print(mb); lcd.print(" mb"); lcd.setCursor(0,3); lcd.print("Humidity: "); lcd.print(hum); lcd.print(" %"); delay(10000); } Practical Electronics | February | 2023 Fig.11.4. Prototype BME280 environmental monitor uses a lowcost Arduino prototyping shield with integral mini breadboard. Fig.11.5. BME280 sensor data displayed on the 20x4-character I2C LCD display. below), coding for the electronic barometer is made extremely straightforward. We recommend the BME280 library produced by Tyler Glenn used together with the standard I2C LCD library. In this application we have used the default settings from the library module; ie, the forced mode with a standby time of one second and a filter setting of ×16. Note that the BME280 has a hexadecimal I2C address of 76. The code (see Listing 11.1) starts by including the required library files, after which the setup code initialises the LCD and selects the display’s backlight. The serial interface is then started so that data for debugging is sent to the host computer. For example, if the BME280 sensor is not found an error message will be sent via the serial link. Having ascertained that a sensor is connected, the next block of code verifies the sensor type and generates a further serial port message confirming the type of sensor detected. Note that if a BMP280 (ie, not BME) sensor is used, then humidity data will not be available. Having completed checking and reporting the sensor type, the code is ready to enter and continuously execute the main loop. The units used for temperature and pressure data (Celsius and pascal) are configured using the following two lines of code: BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); BME280::PresUnit presUnit(BME280::PresUnit_Pa); Alternative measurement units (for example, temperature in Fahrenheit and pressure in psi) can be selected by modifying these two lines. Now we are ready to read the data from the sensor and display the results on the LCD. Note that we have chosen to display pressure in millibar (mbar) so the returned pressure data (in pascal) is divided by 100 in order to obtain the required indication (ie, 100Pa = 1mbar = 0.001 bar). Fig.11.5 shows a typical set of data displayed on the LCD. Mounting the finished project in a small enclosure should present little difficulty and readers will be able to readily adapt the code to provide indications in different units, as required. Finally, the electronic barometer makes a great project for anyone interested in measuring and displaying basic weather data or, as in my case, simply checking the readings obtained from a beloved antique instrument! Going Further This section details a variety of sources that will help you locate parts and further information that will allow you to get the best out of BME280 sensor modules. It also provides links to relevant underpinning knowledge and manufacturers’ data sheets. Table 11.2. Going Further with the BME280 pressure, temperature and humidity sensor module. Topic BME280 Source The BME280 datasheet can be downloaded from: https://bit.ly/pe-jan23-bme280 BME280 sensor modules are available in various forms from several suppliers; eg, AZ-Delivery: https://bit.ly/pe-jan23-az Notes A useful tutorial on using the BME280 with an Arduino Uno can be found at: https://bit.ly/pe-jan23-uno Electronics Teach-In 8: Introducing the Arduino (available at: https://bit.ly/pe-jan23-eti8) provides a one-stop source of ideas and practical information. Arduino Uno The official Arduino website (www.arduino.cc) provides a variety of resources to support the Uno. The Arduino’s integrated development environment (IDE) can be downloaded from: www.arduino.cc/en/Main/Software BME280 I2C library The official Arduino website provides the library for reading and interpreting BME280 environmental sensor data (using either I2C or SPI). You can visit the library by going to: https://bit.ly/pe-jan23-uno280 The code for this project can be downloaded from the February 2023 page of the PE website. I2C bus You will find a useful introduction to the I2C bus at the Texas Instruments website. Just go to: https://bit.ly/pe-jan23-ti KickStart 7 (PE, February 2022) provides a useful introduction to the I2C interface. Practical Electronics | February | 2023 The Arduino Uno and 20x4 I2C LCD are available from numerous suppliers. 49