Sensors for Microcontrollers

Contents

Introduction

The fredscave's website philosophy is unashamedly devoted to promoting the use of the MicroPython language on the BBC micro:bit. In our view this delightful little microcontroller platform, initially developed as a school children's educational toy tool, has much more potential that should be explored and exploited.

This section of the website is just a little different. It is specifically about sensors that are readily available for the hobbyist and educator and won't "break the bank" when purchased. Each sensor is described in some detail usually in reference to a product datasheet.

Sample programs will be provided in MicroPython - specifically the micro:bit's flavour - if the sensor is a very simple device. Device drivers have been written for the more complex and "intelligent" sensors. Links will be provided to the driver code which can be freely downloaded (and expanded upon if desired) by anyone interested in trying the sensor on the micro:bit.

AHT15 humidity & temperature sensor module
Fig 1 - AHT15 humidity & temperature sensor module

The emphasis will be on sparking the reader's interest to learn not just what the sensor does and but also how it works. The driver code where available is written to be as simple as possible. On the driver code webpages the code is highly visible to the reader who is encouraged to at least make some attempt to understand what it does.

Note: The driver code unfortunately isn't commented. This has been necessary to keep the .py file as small as possible as it will most often be copied to the micro:bit's tiny filesystem.

What is a Sensor?

The pertinent question is; "What is a Sensor?" This very question was put to the AI agent from the Brave web browser. And the answer:

A sensor is a device that detects changes in its environment and converts them into a measurable signal, typically an electrical signal, which can be interpreted by a machine or human. Sensors act as translators between the physical world and the digital world, enabling us to measure, analyze, and interact with our surroundings.

Sounds reasonable, so we'll go with that!

We particularly liked the bit that states Sensors act as translators between the physical world and the digital world. So armed with this intelligence we've overtime, collected more than 140 things[1] that we considered to be sensors under that definition.

And this collection will continue to grow as new sensors come onto the market. Not all will be able to connect to the micro:bit. MicroPython is a beautiful language but being an interpreted language it is quite slow.

Light dependant resistors (LDR)
Fig 2 - Light dependant resistors (LDR)

Types of Sensors

The next job was to classify our collection of sensors. Traditional classification schemes run along the lines of Temperature, Pressure, Proximity, Force, Light, Motion and Chemical.

However, we decided to exercise a much higher degree of creativity and after much debate decided on:

Classification Types
3D Acceleration & Orientation Accelerometer, Gyroscope
Analog/Digital Converters ADC, DAC
Environmental Monitoring CO2, Conductivity, IAQ, Soil moisture, TDS, Turbidity, TVOC
Heart Monitoring Pulse, SpO2, Temperature
Magnetism Hall Effect, Magnetometer, Reed Switch
Miscellaneous Rotary speed, Gas pressure, Optical flow
Real-time Clocks Time, Calendar, Alarms, Countdown timers
Light and Colour Sensing Ambient light, IR light, UV light, RGB colour
Liquid Level Water level
Location GPS
Sensor Movement Tilt, Vibration
Situational Awareness Distance, Gesture, Line tracking, Motion, Proximity
Sound Detection, Level
Temperature Monitoring Contactless, Probe
Touch Capacitive touch
Tracking NFC, RFID
Voltage & Current Volts, Current, Power
Water Flow Rate Flow sensor
Weather Station Sensors Barometric Pressure, Relative Humidity, Ambient Temperature
Weight Load cell

And… that's the final word.

SHT45 (humidity & temperature) breakout board
43F Hall Affect Sensor

Fig 3 - (1) SHT45 (humidity & temperature) breakout board, (2) 43F Hall Affect Sensor

NEO6MV2 GPS breakout board
Fig 4 - NEO6MV2 GPS breakout board