vogon

colin

@vogon

just setting up my twttr

one-third of @staff, electronics hobbyist

@zip's bf
no supervisor but ludd means the threads any good


the schematic for the weather station I built with @JhoiraArtificer
a rough diagram of the station built up on a solderless breadboard in fritzing; red wires carry 5 volts, black wires are at ground, green and yellow are different analog voltages, and white is digital data

(if you'd like externally readable versions of these diagrams, the fritzing project, the kicad project, and a PDF of the kicad schematic are available over at my gitlab: https://gitlab.com/vogon/weather-friend)

my friend @JhoiraArtificer posted a couple pics of a homemade air quality sensor + thermometer we built together, and @ivym got curious about how to build one herself and asked if we had build instructions! unfortunately, the answer is “we kind of winged it.”

hobby electronics has gotten incredibly accessible over the past couple decades, in large part because the cheapness of microcontrollers has made it possible to throw a microcontroller at a problem that doesn’t need one, and use software instead of hardware to do all the work. liz can attest to the fact that the most we did as far as design planning was draw some lines on a piece of paper representing where we were going to solder wires to on the breadboard, and we didn’t even really do that 100% of the time. even the temperature sensor feature-creeped its way into the project because I realized I had like five of them kicking around.

so, this is a post that describes the way that project works, with the goal of being reproducible for literally anyone, even if you have zero electronics experience! (you’ll need a little passing familiarity with computer programming to build it, but nothing more complicated than what you can learn from an introductory programming tutorial.)


parts selection

okay, so to build an air quality sensor and thermometer you basically need four things: the temperature sensor, the air quality sensor, a display device, and a microcontroller to serve as the brains of the operation.

we selected a temperature sensor (a simple thermistor) and a display device (a generic 16x2 character LCD driven by a Hitachi1 HD44780 controller) based on them being parts I already had; equivalent parts are available at Adafruit (thermistor, LCD) and basically anywhere else electronics are sold.

the air quality sensor we chose was this Plantower PMS5003 + breakout available from Adafruit, mostly because it breaks out to a 0.1” pitch header that you can use conveniently with breadboards.

this device doesn’t really have any special software or hardware requirements, so you can build it with any microcontroller prototyping board that you can find online for $27, or $13, or $4. for this project, we used the Adafruit Metro 328, because it:

  1. is available at Adafruit, where we ordered the air sensor;
  2. is software-compatible with the Arduino ecosystem, which has pre-written libraries for all of the components we’re using and is just generally a pretty friendly environment to write small firmware;
  3. is Arduino Uno shield-compatible, meaning there are fancy little premade breadboard shields for it that stack on top (we built the circuit up on one of these);
  4. has an only-kinda-old-fashioned micro USB port instead of the Arduino Uno Rev3’s truly ancient full-sized USB-B. a USB cable alone will provide more than enough power to run the weather station (you can plug it into the wall through a USB charger).

we could have gone with a Raspberry Pi Pico, saved $13, and had enough computer left over to run Doom, but at the time the Pico was brand new, and it still doesn’t have (afaik) any prototyping solutions quite as cute and tidy as the one we used.

you’ll also need a 10-kiloohm resistor and a 20-kiloohm potentiometer, plus optionally a 100-ohm resistor. these are absolutely dirt cheap parts, and a little bit of a pain to find in quantities of one, so if you don’t already have them, and you think you’re going to do more than one project, you can pick up a cheap electronic components kit containing these parts — plus enough additional parts for literally years of projects — for $40 at any major online retailer; search for “resistor potentiometer kit”.

theory of operation and schematic

the thermometer

sensing a temperature is the simplest part of this project, engineering-wise, but unfortunately I have to explain some stuff about physics first.

every point in space has an electric potential, aka voltage after the units potential is measured in, which measures how strongly electric charge is attracted or repelled by it. (most potentials in practical circuits are implicitly measured relative to a ground potential, ultimately named after the fact that early electric telegraphy used the actual ground — like, through a metal spike driven into the topsoil — as a return conductor.) 2D and 3D spaces also have an electric current, which represents how much electric charge is moving through them per unit time. every path between two points has a quantity called resistance, which is a measure of how easy it is to push current through it; the voltage, current, and resistance of part of an electric circuit are related through a relationship called Ohm’s law, which says V = IR — the voltage drop between two points is the product of the current through those points, and the resistance of the circuit between them.2

there’s a class of practical electronic device called resistors, which are known amounts of resistance wadded up into a little ceramic bead on a wire. there’s also another class of practical electronic device called thermistors (short for “thermal resistors”), which are resistors whose resistance changes substantially and predictably as the ambient temperature changes.

Ohm’s law says that, with the same current applied, the voltage drops across two different resistances is proportional to their resistances; and, conveniently, another law (Kirchoff’s junction rule) says that all of the current flowing into one point on a circuit has to flow back out.

this suggests a really simple temperature sensing circuit! connect a fixed resistor R2 (ideally one produced with tight tolerances — 1% or less is good) and a thermistor TH1 in series across a known voltage drop, then measure the voltage drop across the thermistor — since the currents through the components are equal3, the voltage drop is proportional to the resistance of the thermistor, which is related to the temperature through some math that you can just crib from a tutorial because it’s all derived empirically anyway. when you go shopping for thermistors, they’re sold with a known resistance at a given temperature and some constant that you can plug into this math; https://www.adafruit.com/product/372 is 10 kiloohms at 25 degrees Celsius and has a β constant of 3950, both +/- 1%.

the microcontroller we're using has six analog-to-digital converters (ADCs), which directly convert the voltage on an input to a number that can be read in software; you just need to connect the pin between the thermistor and the known resistor to an input pin that the ADC can see — one of the pins named A0 through A5. you also want to choose your known resistor about the same size as the resistance of the thermistor in the middle of your temperature band of interest, so that at that temperature the voltage on this input is somewhere in the middle of the ADC’s scale; a 10k resistor is a good choice here.

the air quality sensor

the inner workings of an AQI sensor are way more complex than a thermistor — I believe a fan sucks air into a small chamber across a filter with a known pore size, and a paired infrared LED and photodiode measure how much light gets blocked by it — which ironically means the hardware work of interfacing to it involves much less math, because the sensor itself can do all of the math onboard (and likely has to, because each unit behaves slightly differently, so it has to be calibrated at the factory.) the sensor we used (U2) breaks out to an 8-pin cable, 5 pins of which you can ignore for this application.

VCC and GND are the power supply (this sensor takes 5 volts), with GND being at ground and VCC being positive; the only other wire you need to connect is TXD, which is one half of a simple serial connection, like you’d use for a modem or a mouse in the ‘90s (modern USB is still a serial connection, hence “universal serial bus”, but with fancier electrical behavior to enable sending data at higher speeds.) this sensor only communicates at 9600 bits per second, which is slow enough that you can use software serial communication (which is good, because the Arduino doesn’t have a hardware serial device available.) you can use any pin on the Arduino for this, but digital pins 0 and 1 are also used for the USB port, so avoid those.

the display device

the actual LCD component is invisible to you as a hardware designer, because from your perspective, it’s hidden behind the HD44780 chip. you’ve probably seen LCDs powered by this exact controller in a bunch of different places in your life, like on those little credit card acceptor boxes on vending machines, or 3D printers, or fire alarm control boxes, or whatever — and for good reason, because it presents a (comparatively) simple and (comparatively) user-friendly interface that takes care of knowing how to draw letters and numbers and multiplexing 20 input pins to drive a couple thousand LCD pixels.

HD44780-based LCD screen modules (U1) will generally have 16 pins:

  • A and K are the power supply for the backlight — the anode (positive side) and cathode (negative side) of the light-emitting diodes which light the LCD panel from behind so you can see it in dim conditions. diodes have a resistance that’s close to zero, so if you connect them directly to a power supply they’ll consume as much power as the power supply is capable of giving them, and generally overheat and quickly burn themselves out. many LCD modules include a current-limiting resistor on the backlight for this reason (surface-mount resistors are unfathomably cheap when you buy them in industrial quantities, so why not); Adafruit says theirs do, and you can check to see if there’s a little resistor chip on this line if you inspect the PCB, but you can also just throw your own current-limiting resistor R1 — Adafruit’s tutorial recommends one or two hundred ohms — on the wire either way, and the worst thing that’ll happen is the LCD will be a little dim. feel free to use a resistor or just a wire based on your personal risk tolerance. worst case, even if you do burn out the backlight, the rest of the LCD should continue to work normally, you’ll just have to hold it up to a light to read it.
  • VSS and VDD are the power supply for the LCD itself; the air quality sensor’s VCC is synonymous with VDD, and its GND is synonymous with VSS , for reasons that we won’t get into right now. our LCD takes also 5 volts across these pins.
  • V0 is the contrast pin; it determines how bright or dim the LCD is. it should sit at “a couple of volts” — exactly where depends on the electrical characteristics of your particular LCD, lighting conditions, and good old-fashioned personal taste — which makes it a great candidate to introduce A New Type Of Guy, the potentiometer (RV1), which is a resistor divided into two parts, one on either side of a moving center contact called the wiper. as you physically turn a knob, the ratio of these two parts changes (and if you put a voltage drop across the outer contacts, so does the voltage on the wiper contact), causing the LCD to get brighter and dimmer.
  • the leftover 11 pins — RS, RW, E, D0, D1, D2, D3, D4, D5, D6, D7 — are the pins that the microcontroller uses to talk to the LCD controller. the specifics of the protocol don’t matter that much if you’re handing responsibility for talking to the LCD off to a library, which we did. if you’re curious, RS is an index into the controller’s internal registers, RW is a read/write flag, E is a read enable pin (the controller only reads its data lines when E is set high), and the other 8 pins are the data bits being read or written. if you’re pressed for space (or don’t want to do quite so much soldering) you can even get by with just connecting D4 through D7, though the display will refresh slower because the underlying software has to do more work to send each command. the exact microcontroller pins you connect to these pins on the LCD doesn’t matter, so you can just choose them to make the wiring neat.

a brief introduction to digital signaling and logic levels

a lot of electronic components send information back and forth digitally, as rapidly switched “0” and “1” voltages, rather than a voltage that increases and decreases continuously. as electronics manufacturing has gotten better, the working voltage of digital signaling has dropped from 12 volts, to 5, to 3.3, to 2.5, to 1.8, to 1.5, to 1.24, depending on how sophisticated the component you’re working with is; for hobby electronics, you’ll mostly be working with 5 and 3.3-volt components. different components, depending on how they’re implemented internally, will subdivide this voltage range into different ranges that they consider logic low (0) and logic high (1), as well as a region in between that isn’t guaranteed to be read either way.

the microcontroller we’re using says in its datasheet that it interprets logic low as 0-(0.3 * Vcc) volts, and logic high as (0.6 * Vcc)-Vcc volts; at Vcc = 5 volts, this works out to 0-1.5 volts and 3-5 volts. this is helpful for our application; the air quality sensor uses 3.3-volt signaling, but the LCD uses 5-volt signaling. if we told the Arduino to do 3.3-volt signaling and then fed it 5 volts from the LCD, it could be damaged, and the LCD might not recognize the Arduino’s logic high voltage properly. but, since 3.3 is greater than 3, and the Arduino is only reading data from the air quality sensor rather than writing to it5, we can cheat a little bit and tell it that it’s talking only to devices which are doing 5-volt signaling. shifting between voltages isn’t that hard — you can buy chips that do it for you all in one place — but it’s a hassle that’s nice to be able to avoid.

some notes on assembly and software

breadboards and soldering

experimental and other one-of-one electronic devices are often assembled on various types of breadboards6, which are components with regularly-spaced holes (a 0.1” pitch is almost universal) that hold electronic components in place; many of them have sets of holes that are electrically connected to save you manual wiring as well. breadboards can be either solderless, made up of mostly plastic and holding all the components in place with a friction fit, or made out of traditional circuit board material and with soldered joints; the former requires less messing around with molten metal and lets you make easier changes after initial assembly, but is also prone to randomly breaking if jostled wrong.

you can build this circuit on solderless breadboards with nothing more than a pair of flush cutters, a wire stripper, and some hook-up wire (you don’t even need the flush cutters since the wire stripper has a wire cutter built into it, but they’re nice to have for this and a lot of other hobbies.) if you want to build it like we did, on Adafruit’s Arduino proto shield, you’ll also need a soldering iron and to learn how to solder, and either way you should get a cheap digital multimeter for debugging purposes.

the nuts and bolts of electronics assembly are difficult to teach in text, but here are some video tutorials:

using solderless breadboards: https://www.youtube.com/watch?v=_j1oCHseWAc

using multimeters: https://www.youtube.com/watch?v=bF3OyQ3HwfU

introductory soldering tutorial: https://www.youtube.com/watch?v=6rmErwU5E-k

(one complaint I have with this soldering tutorial, as with a lot of soldering tutorials on youtube, is that I don’t think you should make a habit of using leaded solder, even though it’s more forgiving than lead-free solder. temperature-controlled soldering irons are so cheap now (I use the $25 pine64 pinecil for all my soldering and can’t recommend it enough), there are plenty of good lead-free solder alloys7 and fluxes available, and if you ever have to work on a modern commercially-assembled board you’re going to have to be able to solder lead-free anyway. imo it’s worth reducing the amount of heavy metals that end up in e-waste and just not having to work with lead at all.)

using perfboard (the same ideas transfer over to other types of solderful breadboard): https://www.youtube.com/watch?v=l9Kbr8cPqOE

writing the software

depending on exactly what parts you use and how you assemble them, you’ll need to change the software running on the station a little bit, so I don’t want to drop source code on you; instead I’m just going to give you links to the tutorials we used to get liz’s station up and running:

https://learn.adafruit.com/thermistor

https://learn.adafruit.com/character-lcds

https://learn.adafruit.com/pm25-air-quality-sensor

there's no real special sauce to the software we put on the station, it’s basically just snapping those three blocks together.

hopefully this long text post taught you something or at least kept you busy for a bit. if you end up trying to build a station of your own, I’d be more than happy to help you with any issues you run into in the comments!


  1. yep, that Hitachi

  2. there’s nothing special about metal wire; the reason practical electronics are made out of metal wire is because its resistance is close enough to zero that you can mostly ignore it8, meaning you can characterize a circuit almost entirely by what useful devices are on it.

  3. roughly equal; the input to the microcontroller does consume some current, but ADCs are designed to affect the value they’re measuring as little as possible. Atmel/Microchip claims an ADC input impedance of 100 megaohms, implying an error of about 1 part in 5,000. electrical engineering is a field with tons of stuff like this to hyperfixate on and chase out of your circuits, if that’s something that interests you.

  4. below this, if you get really fancy about it and use differential signaling

  5. note that this also only works because the air quality sensor is talking very slowly (on computer scales); if the air quality sensor was sending data more rapidly, the signal might not change between low and high sharply enough for the Arduino to read it reliably.

  6. named after the fact that early radio experimenters used to put circuits together on wooden bread cutting boards, wrapping wires around nails to connect them

  7. I’ve heard good things about SAC305, which is 96.3% tin + 3% silver + 0.7% copper, though I haven’t had a chance to try it first-hand because I’m still getting through the cheap spool of Sn-0.3Ag-0.7Cu (99% tin, 0.3% silver, 0.7% copper) I bought when I first started, which still works just fine.

  8. there are other electrical properties of wire that can’t always be neglected, but you don’t need to know about those right now.


in reply to @vogon's post: