This webpage contains links to "how to" documents about using Arduinos.
Because that's where my own interests lie, many of the documents arise
from using Arduinos to monitor, display,
and log
environmental data. These documents assume some previous knowledge of how
to write code for using Arduino sensors. A comprehensive introduction to using
Arduinos for environmental monitoring, assuming no previous Arduino
programming experience, can be found in David Brooks' book,
Exploring Your Environment with Arduino Microcontrollers.
The availability of
sensors and other devices discussed in that book and these documents
is always a moving target and there is no
way to guarantee future availability.
Some of the documents referenced here refer to other documents available from this webpage. All the documents are in Microsoft Word format so you can copy code from them. All the Arduino projects described on this webpage have been developed on a Windows 10 computer using the free Arduino Integrated Development Environment (IDE). The IDE is a cross-platform application, but versions for other operating systems, including older Windows systems, may have problems with drivers, for example, or other problems for which I can offer no assistance. |
The image shows the contents for this book. Some of the documents on this page
reference the book, which is available for $25 including shipping to any U.S.
address. Contact brooskdr@instesre.org. All book proceeds go to support the
mission of the Institute for Earth Science Research and Education..
When errors are found in the book they will be noted here: |
The image shows an inexpensive UNO-compatible board I've set aside
just for testing I2C devices with header pins. The board, which I use for many of my projects, is the Seeedstudio V4.3
UNO compatible that you can find at this URL: https://www.seeedstudio.com/Seeeduino-V4-2-p-2517.html Yes, the URL says "V4-2," but the product described is actually the V4.3, which as of July 2024 cost US$7.60. You just need to upload test code for your I2C device with header pins connected to the M/F jumper wires. This board uses a USB A/microB cable. The board can be switched between 3.3 V and 5 V power/logic. Some I2C sensor modules require 3.3 V. Also, there are several online sources for code that will test for the presence of I2C devices. They will give you the device's I2C hardware address if you need that. |
This document shows how to use RGB LEDs, including boards using 5050 RGB LEDs. Several examples are given, with breadboard layouts and code for controlling single and multiple LEDs, including using PWM to control LED brightness. |
This document describes several options for displaying data collected with Arduinos, ranging from simple LCD text displays to TFT displays for creating full-color graphics |
This document compares data from two inexpensive Arduino-compatible airborne particulate sensors. Both devices use a single laser beam that's deflected by particulates in a fan-driven air stream flowing past the laser. Both sensors reliably track time-dependent variability in particulates, but the quantitative mass density values are considerably different. |
This document shows how to use piezo vibration sensors. It suggests that rather than depending on Arduino's very coarse 10-bit 0-5 V A/D resolution, a 16-bit programmable gain ADS1115 A/D board is a much better choice for detecting small vibrations such as might be encountered from heavy traffic or construction activities. |
This document shows how to use Arduino's interrupt-processing capabilities to look for pulses from a Geiger counter built from a kit. The code counts pulses and calculates counts per minute. This kind of code can be adapted to any situation where it's necessary to look for events that happen randomly, with only a very fast and transient indication of their occurrence. |
This document shows how to use data logging shields for collecting and storing data. Although it may be more "modern" to think of storing data online, there are still many good reasons for collecting, recording, and storing data locally with date/time stamps. Data logging shields make this possible. They are widely and inexpensively available online for UNO and Nano Arduino boards. |
Although UNOs and Nanos are almost always suitable for data collection projects with
multiple sensors, projects that use graphic display devices can sometimes cause program
memory problems. The software libraries required to use TFT and eInk displays take a lot of program memory. An option for users who are already comfortable using UNOs and Nanos is to use a Mega 2560. This board has eight times the program memory space as an UNO or Nano. UNO data logging shields will fit on Mega boards, but some adjustments must be made to pin assignments, and the topic is explored in detail in this document. |
See Comparing PMS5003 and Sensirion SPS30 particulate sensors, above. This document performs a similar comparison between PMS5003 and HM3301 particulate sensors with an I2C interface. |
This document provides an introduction to the new Arduino UNO R4 MINIMA. This board has the same physical layout as the UNO R3, and it's supposed to accept R3 code without modification – an assumption that turns out to be not entirely true, depending on what hardware you attach to the board! The R4 uses a different microprocessor that offers several advantages over the R3, including 8 times more memory for storing code compared to the R3! This board may override the need to use a more expensive UNO Mega to get more program storage space for large projects. |
This document provides an introduction to the
Arduino Nano Every.
This board has the same physical layout as the Nano, as shown below the Nano in the image, with
exactly the same pinout configuation. It costs less than an "official" Nano –
currently about $20 vs. $25 – but of course more than "off shore" Nanos.
The Nano Every uses a different processor than the Nano and you need to install board support for it in your IDE. It has much more memory storage space than a Nano and for many applications, it should accept Nano code with no changes. This is a huge potential advantage for projects that exceed the memory space of Nanos. Some sensor and other device software libraries may not work with this board. |
My book Environnmental Monitoring with Arduino Microcontollers shows how to use two I2C multispectral sensors from Sparkfun.com -- one with 6 VIS channels and one with 6 NIR channels. (Those two sensors have the same I2C address, so a multiplexer is needed to use both of them on the same Arduino.) This document shows how to use a 10-channel multispectral sensor, the I2C AS7341 from Adafruit.com, which has 8 VIS channels, a broadband "clear" channel, and an NIR channel. The code presented in the document displays raw data from the 10 channels on a small OLED and draws a full-color bar graph showing those data. |
The AMG8833 is an interesting low-resolution 8×8 pixel
"thermal camera." This document provides code for using this sensor to
produce 64 16×16-pixel colored squares on a small TFT display, where the
colors are based on the thermal response of each pixel on the sensor.
This
device will detect a human presence at least a few feet away when
viewed against a relatively uniform thermal background that's cooler
than a human body. The AMG8833 breakout board is from SparkFun.com and the Arduino board is an UNO code-compatible MetroMini from Adafruit.com. There are six possible colors, ranging from black for temperatures cooler than some selected minimum, to red for the warmest sensor pixels. A small OLED displays the matrix containing the 64 color selection values. |
The thermal sensor document on this page
shows how to use an AMG8833 8×8 pixel thermal
sensor to produce a matrix of 64 16×16 pixel color squares s on a small
TFT display. The visual appearance of these data can be enhanced by interpolating
the original 8x8 matrix to a 15×15 matrix to produce 225 8×8 pixel pixel color squares
on the TFT display. This document shows how to write an Arduino sketch that starts with an 8×8 matrix and produces a 15×15 interpolated matrix, using two-dimensional arrays. The image here shows this interpolation done in Excel, which I used as a guide for writing the code. |
This document shows how to use a small generic data logging module for Arduino 5 V boards that don't share the UNO R3/R4 or Nano physical layout, like Arduino ProMinis or Pros. (There are data logging modules that plug into the headers of UNOs and Nanos.) There's no data logging shield for Adafruit.com's MetroMini, a board that is recognized as an UNO R3 by the Arduino IDE, but which is about the same size as, but not pin-compatible with, a Nano. - |
Based on some problems I've encountered when trying to use Nano data logging shields with projects that include a small OLED display, I wrote this document that uses the generic data logging module discussed in the previous post to log data from an MS8607 T/RH/P sensor. This is an I2C sensor that I believe is an improvement over the BME280. |
This document shows how to track your position using an inexpensive GPS module. The module requires a CR1220 coin cell battery for power, which is in a holder under the pc board, below the rectangular GPS receiver module. A four-wire cable is included. An antenna, the square module, snaps onto the pc board. Code in the document shows how to extract longitude, latitude, elevation, and UTC time from GPS satellite transmissions. See the posting below about how to use thermistors with a GPS system to track and locate temperatures in "walking around" expeiments. |
Record high temperatures across the U.S. and Europe during the summer of 2023 motivated this project. This Document shows how to use an MLX90614 IR sensor to monitor ground temperatures in urban heat islands and other microclimates. The image shows a sensor system recording temperatures of a gravel driveway on a warm sunny day. |
The previous entry in this list described using an MLX90614 IR sensor to monitor surface temperatures. This Document gives details about building such a system. The document was developed as part of IESRE's role as a science consultant to ECoSTEM, a project at Xavier University of Louisiana funded by the National Science Foundation's Improving Undergraduate STEM Education program. There are instructions for a building an Arduino Nano-based "breadboard" thermal sensing system at an in-person workshop for secondary school students. |
IR sensors like the MLX90614 are typically calibrated for an object emissivity of 1 – a situation that's never encountered with real surfaces. This document gives emissitiites for a range of natural and manmade surfaces and two approaches to changing sensor emissivity. My preferred method is to correct temperatures "after the fact" as shown in the image. |
Chapter 19 in Brooks' book Monitoring Your Environmental with Arduino Microcontrollers shows how to use SparkFun spectral sensor breakouts with Adafruit's Feather M0 Express board. This Document shows an alternative approach using Adafruit's MetroMini UNO-compatible board. A small OLED is used to display data. |
Julian dates are used for astronomical calculations and for solar tracking applications. Because of
some limitations with Arduino floating point variables, some tricks are needed to calculate a
Julian Date accurately. This document shows
how to do it.
  The code also provides an example of how to read a string of characters representing numerical values typed in the COM port window (for this project, integers for the year, month, day, hour, minute, and second) and then split that character string into an array of integers. The same basic procedure will also work for floating point numbers. As a bonus, the lower image shows a different calculation implemented in Excel, based on python code provided by ChatGPT, to which you could add code for including minutes and seconds. In Excel, the int() function truncates a floating point number, rather than rounding it – acting like a "floor" function. |
|
There are interesting projects that involve tracking the sun. The best way to do this is with
calculated solar positions and a
servo-driven pan-tilt device. A basic need for such code is to be able to calculate the
Julian date.
Because of the limitations on the accuracy of Arduino floating point
numbers you have to be creative about how you do this calculation –
see the previous posting!
This document shows how to use servos with Arduinos and how to program a small two-servo pan-tilt device to follow the sun. |
Solar radiation reaching Earth's surface is usually measured with pyranometers. Graphs of these data show diurnal variation in solar radiation, including effects due to variable cloud cover. Lux sensors, which respond to light as perceived by human eyes, can also be used to monitor daytime sky conditions. including cloud effects. This document shows how to build an inexpensive Arduino Nano-based system to collect and log lux, temperature, and relative humidity data. |
Lithium-Polymer (LiPo or LiPoly) batteries are widely used in low-power Arduino projects. It's important to use batteries from a reliable vendor and chargers that are specifically designed for safely charging and maintaining these batteries. This document provides a brief discussion of the hardware IESRE uses for its LiPo-powered Arduino projects. |
Wind speed is an essential meteorological parameter. Anemometers are instruments
used to collect these data. For routine monitoring activities, these devices
often use three cups to collect the wind, causing a shaft to rotate.
The rotation speed is related to wind speed. This document shows how to use an inexpensive three-cup anemometer that produces a voltage (0-3.8 VDC) proportional to the wind speed up to about 70 mph. This is a completely passive device so it's very easy to use with just two Arduino connections – to an analog input pin and ground. The image shows the anemometer with a Nano and an LCD to display the output voltage when the shaft is rotating. |
Measuring airborne particulates is the central science focus for the National Science
Foundation-funded ECoSTEM project at Xavier University of Louisiana, for which IESRE serves as
the science consultant. Inexpensive laser-based and Arduino-compatible sensors are used for this
project and data are collected for PM1, PM2.5, and PM10 particulates. While the PM values themselves
are of interest, it's also desirable to convert the PM2.5 and PM10 values into their corresponding
AQI values as defined by the U.S. Environmental Protection Agency. These
values are used by the EPA to
assign health risks due to airborne particulates. The reported AQI is based on the maximum
AQI associated with each of six pollutants – O3, PM2.5, PM10, CO, NO2,
and SO2. Especially
in urban areas, the PM2.5 AQI is often the pollutant that defines the reported AQI. This document provides Excel formulas and Arduino code for converting PM2.5 and PM10 values into their AQI values. |
Airborne particulates can cause health problems if their values are too high. This document shows some particulate data collected indoors near a woodstove and converted to their AQI values as defined by the U. S. Environmental Protection Agency, using calculations as described in the previous document in this list. |
Adafruit's HUZZAH32-ESP32 board is a popular choice for WiFI/IoT applications. This document shows pin assignments for interfacing Adafruit's 1.44" full-color TFT display with this board. Those assignments should work for other Adafruit TFTs, too. |
There are many full-color TFT displays available from vendors like Adafruit.com
and online. A less expensive but equally usable alternative is the older ILI9225 176×220
pixel TFT available from MPJA.com and other online sources.
This document shows how to use the ILI9225 to create data graphs. The image
shows sine and cosine curves. Code is also included for displaying temperature, humidity,
barometric pressure, and Air Quality Index values for airborne particulates. The pixel count is a little lower than newer similarly sized TFTs but it's still useful for many applications. A possibly useful feature of this SPI device is that is can be plugged directly onto the UNO header that includes power, ground and analog input pins. That feature then requires use of software SPI rather than faster hardware SPI. It also ties up analog pins A0 through A5, which will be a problem if your application needs these pins for analog output or I2C devices that use analog pins A4 and A5. By using a breadboard the pins can be wired to the usual digital pins for hardware SPI. |
This document compares Adafruit's MS8607 T/RH/P sensor (shown in the
image) with
BME280 T/RH/P and AM2315C T/RH sensors. The BME280 is widely
used in Arduiino-based weather station applications, but its relative humidity performance
always degrades catastrophically in outdoor applications where relative humidity varies
over a very wide range. It's possible that the other two sensors, which are designed to promote better air flow around the sensing element, will be less prone to saturation of the hygroscopic dielectric materials used in the humidity sensor, and will also reduce self-heating of the temperature sensor that's required to convert absolute humidity to relative humidity. The MS8607 module, which allows air flow around three sides of the sensing element, should be an improvement over the BME280 module, where the sensing element is mounted directly on the PC board with no air space around it. |
This document gives an introduction to using small monochrome OLEDs for displaying data with text or graphics. These devices work well with Nanos, for example, but large programming projects that require a graphics library will strain the Nano's programming capabilities. One solution is to use Arduino's Nano Every – a newer board that's pin- and (nearly) performance-identical to the Nano but has much more space for code. The image here shows a Nano Every project that displays PM 1, PM 2.5, and PM 10 values on three horizontal bar graphs. |
Noise can be a significant environmental "air pollutant," especially in urban areas where there is constant noise from traffic, construction, and other sources. This document shows how to monitor noise with an Arduino-compatible sound meter module. It incorporates a small electret microphone like the one shown in the image into a complete module that converts sounds to an analog voltage that can then be converted to decibels, the standard way to quantify noise. |
This document shows how to use nRF24L01+ RF modules operating in the license-free 2.4 GHz radio band to collect and display environmental data. These inexpensive modules are widely available online with on-board antennas for ranges of several 10s of meters indoors and screw-on "rubber duck" antennas for outdoor ranges up to 1 km under ideal open-air conditions. They are alternatives to the 915 MHz and 433 MHz RF devices described in Chapter 20 of David Brooks' book Monitoring Your Environment with Arduino Microcontrollers. The nRF24L91+ is the small pc board at the bottom of the image. |
This document shows how to use negative temperature coefficient (NTC) thermistors for monitoring temperatures. These devices are inexpensive, accurate, and easy to interface with Arduinos. They come in a variety of configurations, including the one shown in the image with 1 m stranded wire leads, to which short solid wires have been soldered for use with breadboards. See the posting above about using a GPS tracker with a thermistor for a "walking around" experiment to study heat island effects. |
This document shows how to use an MQ-4 sensor to monitor
methane, a major greenhouse gas. These devices produce an analog output,
so they're trivially easy to interface with Arduinos like UNOs and Nanos.
The analog input pins on those boards, with their 10-bit A/D resolution,
produce an integer value
between 0 and 1023 over 5 V. Like other MQ sensors,
the MQ-4 responds to gasses other
than methane and calibrating them in units of parts per million of methane is
challenging and requires expensive
laboratory equipment. Therefore, these devices are best suited for
"sniffing out"
relative methane levels in specific environments or across a range
of environments. Some sources of methane include wetlands and marshes,
agricultural and farming areas,
landfills, and petroleum processing facilities.
There are several physically identical or similar MQ devices optimized for detecting various gasses. They all use a heated sensor element (SnO2) so they require more power than is typical for Arduino/sensor systems. This makes outdoor use away from plug-in power sources a challenge. |
I have written extensively about the deficiencies of BME280 T/RH/H sensors for prolonged outdoor use because of the failure of their humidity sensors. Recently I bought by mistake some HiLetGo BMP280 T/P sensors (no humidity sensor) from Amazon. If an appropriate I2C hardware address is used, these generic temperature and pressure sensors are supported by a library from Adafruit.com and this short docoument shows code for using them. Only four of the six pins are required -- VCC, GND, SCL, and SDA. Some other versions of these sensors may include only those four pins on their pc boards. Unlike similar sensor modules from Adafruit.com, which will most often work with either 3.3 V or 5 V power, these generic devices are 3.3 V power only! For testing them I have used a Seeeduino V4.2 UNO compatible with switchable 3.3/5.0 logic, but they will also work with 3.3 V power/5 V logic. |
Two common devices that use serial peripheral interface (SPI) connections
for communicating with Arduinos are
TFT displays and SD card modules for data storage. I am constantly uncertain
about how to connect these devices, especially when a system needs more than
one SPI device. (It's easy to connect multiple I2C devices to an Arduino system
because each device has its own hardware address, but the pin connections
are always the same: VCC, GND, SDA(pin A4), SCL(pin A5).) UNOs may have a
second pair of I2C pins labeled SDA and SCL, just above the AREF pin in the
image.) SPI connections are also available through the ISCP header at the
bottom of the image, but I've never used it. The four SPI pinouts can have different names on different devices, which can be confusing: SCLK=CLK-->13 (fixed) MISO=DO-->12 (fixed, not needed to write to SD card) MOSI=DI=SDI=SDA-->11 (fixed, this SDA not the same as I2C SDA!) SS=CS-->10 (code-selectable) For the MOSI pin I included SDA because that's what the MOSI pinout is called on the ILI9225 TFT, an older device documented elsewhere on this web page. It's possible to use multiple SPI devices on the same system. They all use pins 11, 12, and 13, but the chip select (SS or CS) pin must be specified in code, different for each device. That's perhaps why the "SS" pin in the image is in a different color than the other three pins and isn't available through the ISCP header. I've assigned the CS pin as digital 10 because on data logging shields for UNOs and Nanos the CS pin is hard-wired to this pin, so it can't be used for another SPI device. The pin connections shown above are for "hardware SPI," which is what you would most commonly use for SPI devices. However, it's also possible to use "software SPI" with all pins specified in code. An example of this is the ILI9225 TFT. (See a previous entry on this web page.) Its pins are laid out so it can be plugged directly into Aruino UNO headers. The MISO connection isn't needed for displaying data and graphics to the screen: CS-->A5 MOSI-->A2 CLK-->A1 power-->5V GND-->GND Software SPI may draw content on a TFT noticeably more slowly than hardware SPI, but I've used the ILI9225 in both software and hardware SPI modes and not noticed significant differences. Of course this unusual feature of the ILI9225 is useful only if you don't need access to these pins (including all the analog input pins) for anything else! SPI connections are different for other Arduino boards, like the MEGA (see a previous entry on this web page). The pin names should be consistent, so the connections should be clear. |
This document shows how to use a DFRobot CO2 sensor. It's intended mainly for indoor monitoring, but is can also be used to "sniff out" prominent outdoor sources of this important greenhouse gas. Its I2C interface and software library makes it easy to use with Arduinos. At a cost of almost $60, it's relatively expensive for Arduino sensors, but it could be useful in classrooms and other enclosed indoor spaces to make sure that CO2 levels remain lower than about 1000 ppm. Note that energy efficient buildings, which are highly insulated and airtight, may reduce energy consumption, but without adequate indoor/outdoor air exchange, CO2 levels can be higher than is healthy for humans. |
This document shows how to use an Adafruit Feather M0 Express
board with a FeatherWing data logging shield and OLED display. Although this is a
relatively expensive system as Arduino systems go, there are at least four
significant advantages of the M0 Express, which is about the size of a Nano,
over a Nano or UNO: 1. a complete display/logging system can be put together with Adafruit FeatherWing add-on boards that minimize breadboard wiring and allow a system with several sensors to fit comfortably on a half-size breadboard; 2. a LiPo battery can be connected to the system that allows you to switch seamlessly between online USB power and offline battery power, which is ideal for projects that will be used away from a plug in power source; 3. for analog-output devices you can select 8, 10, 12, or 14 A/D resolution instead of the fixed 10-bit resolution available with UNOs and Nanos; 4. the available program memory space is huge compared to UNO/Nano boards. |
For battery-powered systems on a breadboard, it's very convenient
to be able to have an on/off switch to control a battery that most
likely will need to be connected to an Arduino board's GND
and VIN pins.
I recently found such a switch
at adafruit.com (ID 805, $1.00), that plugs directly into a breadboard.
It's a little flimsy and unstable on a breadboard, but this can be
solved with some hot glue to hold it in place. Similar breadboard-friendly
switches are available from spakfun.com
(COM-09609, $0.95; COM-00102, $1.60) It's easy to find other small and much cheaper SPDT switches online, but it's never clear whether their pins are on 0.1" (2.54 mm) centers for use on a breadboard. Any of these Adafruit or Sparkfun switches are reliable for their intended purpose. For battery-operated systems, I'm now using a 6 AA battery pack (Adafruit ID 248) with a 2.1 mm power plug and a breadboard-compatible 2.1 mm jack (Adafruit ID 373). Why go to this extra expense rather than just inserting wires from a battery pack directly into breadboard tie points? Typically, these wires will to to an Arduino board's VIN and GND pins. If you're careless with these wires and insert them where they don't belong, you can short out a battery or destroy an Arduino board, as I did recently with a Nano. The on-board power-in jack and SPDT switch essentially eliminates chances for these outcomes, assuming that the power jack and switch wiring is done properly. |
I often create projects that include a temperature in their output. It's not obvious how to display a "degree" symbol before a temperature unit, like °C, or after an angle, like 36.6°N, on a display device. THIS SHORT DOCUMENT shows hows to do it with OLED displays. |
There are several documents available from this webpage that show how to monitor
air and ground temperatures
– essential components of examining
microclimates like those associated with urban heat islands.
This document describes a project that uses
an Adafruit Feather M0 Express board with a data logging shield and OLED,
and thermistor,
MS8607 T/RH/P, MLX90614I IR, and lux sensors to give a more complete view
of conditions found in
microclimates. This is a relatively expensive project by Arduino standards,
but UNOs and Nanos can't handle the amount of code required. A Mega would
probably work, but it's more expensive than the Feather M0 Express.
This system is very compact and the
M0 Express has a port for a LiPo battery that can be "hot swapped" with
USB power, making this a good
choice for projects that need to work when no plug-in power is available.
I believe you should consider this as an "advanced" Arduino project, as the document assumes that you already have experience working with Arduinos. The Feather M0 Express board will be unfamiliar to UNO and Nano users and you may need to reference other postings on this webpage to be successful with this project. |
I've posted here about this item (Adafruit ID 2078) just to remind myself about its availabilty. Using UNOs away from plug-in power sources is often not easy, requiring awkward battery packs to power the UNO through its VIN pin with voltages in the 7-12 V range. Here's a better solution: a $20 UNO shield that allows you to use a LiPo battery (not included) to provide a regulated 5 V to the UNO's 5 V power pin. The shield includes an off/off switch. At the time I wrote this posting (October 2024), this item was out of stock, but hopefully that isn't a permanent situation. |