Temperature And Humidity Display Using Arduino, DHT22, And MAX7219 Display

I finished another project today. This time it’s a simple temperature and humidity display, and so far it’s working pretty well. It’s built around an Arduino Nano and uses a DHT22 sensor. The display is an extremely cheap MAX7219-based four-module LED matrix (130x32mm), and its brightness is controlled by a capacitive touch sensor (11x15mm).

In this case, everything runs off a 5V supply so there are no level shifters needed and a single USB cable can power the whole thing. Any other 5V Arduino with hardware SPI will work fine here, too. The software libraries I used also support software SPI but I haven’t tried that out.

Here’s the layout:

  • Everything is connected to the +5V and GND pins on the USB connector.
  • MAX7219 CLK to Arduino 13.
  • MAX7219 DATA to Arduino 11.
  • MAX7219 CS to Arduino 10.
  • DHT22 I/O to Arduino 2.
  • Touch sensor I/O to Arduino 4.

I had everything on a breadboard but forgot to take a picture before wiring everything up to fit in the case… here it is wired up and just before being prepared to put into the case.

Arduino DHT22 ST7735

The program uses the MD_MAX72XX and MD_PAROLA libraries for the display, and the SimpleDHT library for the DHT22. It took me a while to wrap my head around the MD_PAROLA stuff, but the examples included with the libraries were very helpful. Here’s the program:

/* Temp and RH DHT22 MAX7219 for Dot 04
 *  Uses Nano to check DHT22 and display on 8x8 dot matrix (x4) MAX7219.
 *  Meant to be used indoors.
 *  Has two brightness settings, 4 and 15 (on scale of 0-15)
 *  Runs off 5V USB.
 *  MAX7219 controlled by MD_Parola and MD_MAX72xx libraries
 *  DHT22 using SimpleDHT
 *  PINS:
 *  DHT22 data: D2
 *  MAX7219 clock: D13, data: D11, CS: D10
 *  Intensity: D4
 *  Uses a MAX7219 32x8 LED module from Banggood. Hardware type is MD_MAX72XX::ICSTATION_HW, 4 devices
 *  Puts temp and RH on display at same time

 * MAKE SURE YOU RUN THE MD_MAX72XX_HW_Mapper to confirm the hardware setting for your particular display!
 * The results I got for the display I have were:
 * Your hardware matches the setting for IC Station modules. Please set ICSTATION_HW.


#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SimpleDHT.h>
#include <SPI.h>

// Set up DHT22 vars for data TX/RX
#define h_w 8
#define h_h 8
static unsigned char h_w_bits[] = {
   0x3c, 0x42, 0xa5, 0x81, 0xa5, 0x99, 0x42, 0x3c };

#define s_w 8
#define s_h 8

static unsigned char s_w_bits[] = {
   0x3c, 0x42, 0xa5, 0x81, 0x99, 0xa5, 0x42, 0x3c };

// Create instance for the DHT22 using pin 2 for data xfer
SimpleDHT22 dht22(2);

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW  // Found using the MD HW mapping program

#define MAX_DEVICES 4 // Four 8x8 modules on this particular board

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

#define BRIGHT_PIN 4

// Hardware SPI connection

byte CountUp = 0;

void setup() {

  delay(500); // Need this because display doesn't seem to start up right away.

  P.begin(2); // Using 2 zones, one for temp, one for humidity

  P.displayZoneText(0, "Hi!", PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);
  P.displayZoneText(1, "Hi!", PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);

  P.setZoneEffect(0, 1, PA_FLIP_UD);  // Need this because I glued the display in upside down >:-(
  P.setZoneEffect(1, 1, PA_FLIP_UD);  // Need this because I glued the display in upside down >:-(
  P.setZoneEffect(0, 1, PA_FLIP_LR);  // Need this because I glued the display in upside down >:-(
  P.setZoneEffect(1, 1, PA_FLIP_LR);  // Need this because I glued the display in upside down >:-(

void loop() {


  // If touch sensor is active, cycle through the 16 levels of brightness until sensor is inactive.
  int brightness_change = digitalRead(4);
  while (brightness_change == 1){
    if (CountUp == 16){
      CountUp = 0;
    P.setIntensity(0, CountUp);
    P.setIntensity(1, CountUp);
    CountUp = CountUp + 1;
    brightness_change = digitalRead(4);

  float temperature = 0;
  float humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    // If we're here, there was a problem reading the DHT22. Show an error then try again.
    P.displayZoneText(0, "Dht", PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);
    P.displayZoneText(1, "Err", PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);
    goto jumpback;  // I know, I know. Don't say it...

  // Convert the float to a string to display
  char temp_result[6];

  // Convert the float to a string to display
  char hum_result[6];

  P.displayZoneText(1, hum_result, PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);
  P.displayZoneText(0, temp_result, PA_CENTER, 75, 0, PA_PRINT, PA_NO_EFFECT);

  delay(3500);  // DHT22 max sample rate is about 2 seconds.

If you are using a MAX7219-based display, save yourself some time and frustration by connecting it and running the MD_MAX72XX_HW_Mapper program that comes with the MD_MAX72XX library before you do anything else. It will tell you how your display is set up, regardless of how it actually looks.

After doing some testing, I found that the capacitive touch sensor I was using could reliably detect my finger out to about 5mm away. That was great because then I could hide it inside the case and there’d be no switch, no pad… just a “magic” spot on the back that changes the brightness if you put your finger there.

I designed a case for this particular project, including the specific display and touch sensor I had on hand. It’s vented, has a hole for a USB cable, and is closed up with four 6mm M3 screws:

Arduino DHT22 MAX7219
Fresh off the printer… with a bit of over-extrusion.
Arduino DHT22 MAX7219
The capacitive touch sensor in its dedicated spot right in the middle of the back panel.

With everything wired up and tested, I hot-glued everything… and I mean everything. Every connector, every module (except the Nano’s mini-USB port – never know if I’ll want or need to reprogram it) … it’s all quite secure inside the case. I glued put a piece of plastic on the back of the display just in case any other parts work their way loose and came in contact with it. I’m still a little wary of doing things this way, but it sure beats drawing up and etching boards for this kind of stuff!

Once the glue had cooled and I confirmed everything was stuck good and tight, I closed up the case and plugged the cable into a 5V USB power supply. The LEDs flashed, and then… everything was upside down. I’d glued the display in upside down.

So… another 45 minutes or so of pondering and looking and I found how to flip the display in software so it looked right again. If you run into this problem, check out setZoneEffect() in the MD_PAROLA documentation.

Here it is, from the back:

Arduino DHT22 MAX7219

And from the front, display pointing the right way:

Arduino DHT22 MAX7219

The STL files for the case are available at https://www.thingiverse.com/thing:4202464

Yes, You Can Print TPU On A CR-10s With No Mods (Part 2)

In my previous post, I showed that it was indeed possible to print TPU on a plain old CR-10s. That was with a couple of sample packs that had no name on them but had the following recommendations:

  • Nozzle: 220-240C
  • Bed: 75-85C

With that sample TPU, I had success printing at around 20mm/s with a nozzle temperature of 240C and a bed temperature of 75C.

I ordered the a spool of the cheapest black TPU I could find on Amazon, sold by a company named Priline. The recommendations for this TPU were different than the other stuff I’d used:

  • Nozzle: 190-230C
  • Bed: 50-80C

I thought I’d print the same nut and bolt models that I’d done before to compare. I made the temperature changes in Cura, then sent it off to print, first with a nozzle temperature of 220C and a bed temperature of 75C.

Right off the bat I could see there was a problem. The lines weren’t adhering to each other as they were being printed. I tried bumping up the flow rate, which only made things lumpier. Then I turned up the temperature a few degrees at a time until it looked like things were working better. Unfortunately, the print failed on the second layer when it didn’t stick to the first layer and became a blob on the nozzle.

I ran another print with the temperature set to 230C and with the flow rate still higher. The first layer went down a lot better and I thought things were going to work but the fourth layer didn’t stick to the third and it ended up all over the nozzle again. I thought that might’ve been a fluke, so I leveled the bed again and tried again but had the same results on the sixth layer.

Another print started at 235C and was working pretty well but once there were about a dozen layers put down, it didn’t look right. I cancelled the print, let everything cool down, and then took a look at the parts. With a bit of pulling, I was able to separate some of the layers. Still no good.

Despite the recommendations being only up to 230C, I tried bumping it up one more time to 240C, just like the TPU from the sample packs. That extra five degrees made a world of difference. There was some over-extrusion so I turned the flow rate back down a bit.

Here’s what I ended up with. You can see there’s a bit of stringing between the models just like last time:

TPU nut and bolt
TPU nut and bolt
TPU nut and bolt
They thread together quite nicely.

Here are two comparison pictures of the nut and bolt printed with the sample TPU on the left, and the Priline TPU on the right:

TPU nut and bolt
TPU nut and bolt

Both had some stringing, but it’s pretty obvious that the Priline printed cleaner than the sample packs did. From the look of it, I probably should’ve dried the sample TPU before I used it.

After the print, I compared my notes and found that the settings that had finally worked for the Priline were exactly the same as I’d used when printing with the sample filament:

  • Speed: 19mm/s
  • Nozzle temperature: 240C
  • Bed temperature: 75C
  • Flow rate: 105%
  • Retraction: OFF

These results make me even more confident in saying that yes, a stock CR-10s can print TPU and do a decent job at it.

Yes, You Can Print TPU On A CR-10s With No Mods

A good friend of mine has a dad who’s suffering from dementia. He’s a farmer and spent decades building and fixing things, and he still likes tools and things he can manipulate with his hands. Unfortunately, there are times when he throws things.

I printed him up some big nuts and bolts in PLA but realized that if they were all screwed together they’d make a pretty hefty projectile. So I wasn’t entirely sure what to do. Then, I remembered there were some 30g sample packs of TPU sitting around and collecting dust, so I figured I’d see if I could do something with them.

Having never printed TPU before, it was a few hours worth of DuckDuckGoing (I know it doesn’t roll off the tongue as well) before I’d learned that yes, it was possible to print TPU on a CR-10. I’d also learned that no, it wasn’t possible to print TPU on a CR-10. Interestingly, it was also possible to print TPU on a CR-1o, but only if you installed anywhere from $0.50 to $250 worth of modifications.

I opened one of the packages and played with the filament. Rubbery, stretchy, a little squishy… definitely different from the PLA and PETG I’m used to. So, I loaded it into the printer, started a print, and sat there for the entire thing so I could dial the settings in while it printed (thank you Octoprint!!!).

Here’s a bendy wrench:

TPU wrench
Before [model by triffid_hunter , see https://www.thingiverse.com/thing:11647]
TPU wrench
TPU wrench
… and it springs back on its own

I then fused what was left of one pack with the other pack I had (and set off the smoke alarm, whoops). After things calmed down, I drew up and printed a nut and bolt, which came out really well:

TPU nut and bolt
TPU nut and bolt

I did this on my CR-10s with a 0.4mm nozzle and no modifications, and the TPU I used had the following recommendations listed on the pack:

  • Colour: Black
  • Material: TPU
  • Dia: 1.75mm
  • Nozzle: 220C-240C
  • Bed: 75C-85C

After a bit of experimentation, here’s what I found worked for me. Again, this is on a stock CR-10s with a 0.4mm nozzle:

  • Level your print bed. Actually, go level it now even if you’re not going to print TPU. It fixes sooo many problems.
  • Clean the outside of the nozzle before you print.
  • Purge whatever was in there before. Do not mix TPU with another material, even if it’s “just a bit”. Trust me.
  • Bed surface: Glass with two layers of Elmer’s all-purpose glue stick, applied after the bed is at temperature.
  • Bed temperature: 75C (all layers).
  • Nozzle temperature: 240C (all layers).
  • Fan: 0% for first layer, 100% for rest of print.
  • Flow rate: 105% (all layers).
  • Retraction OFF.
  • Print speed: 18-21mm/s.
  • Layer height: 0.2mm for first layer, 0.25mm for rest of print.
  • Print with a skirt, at least 7-10 lines wide.
  • After the hotend and bed are heated up and just before you’re ready to print, raise the hotend 100-150mm and wait until the nozzle stops drooling TPU. Clean up the debris, carefully wipe the excess TPU from the nozzle, then start the print. It will take a while for the hotend to fill up again – print with a skirt to give it time to fill back up (see above point).

With these settings on this printer and with that particular flavour of TPU, I was able to get good strong prints that looked pretty good. There is some stringing between parts, but it cuts away easily with a small pair of scissors or snips.

I lobbed the wrench at my wife, who reported that it didn’t hurt. I screwed the nut onto the bolt and threw it at the front door and it bounced nicely without leaving a dent. I think these might work for my friend’s dad.

I’ve ordered some more TPU, and of course I couldn’t find stuff with the same temperature recommendations as the sample packs. I will give it a shot and do up another post with what I find out. At this point, though, I’m pretty comfortable with saying that yes, you can print TPU on an unmodified CR-10s and it can turn out well. Just go slow. And level the print bed!

This Is Why They Talk About Drying Your Filament

I went to start up a print today and loaded an old half-full spool of black PETG into the printer. I ran the filament through the nozzle to purge what was left of the previous filament and, as the white plastic faded to grey and then black, I heard an odd ticking sound coming from the nozzle.

I store my filament in zipper bags with a pack or two of desiccant, but even with those precautions, it only slows moisture down – it doesn’t stop it. It’ll make its way in through any tiny hole in the plastic, and water molecules can slowly make their way between the molecules of the plastic bag. You can’t see it or feel, it but with enough time and the right conditions, it’s enough to saturate the desiccant and start working its way into the filament.

In this case, the bag containing the filament spool had been sitting long enough and had gone through enough temperature/moisture cycles (I store it in the basement) that the filament had absorbed some moisture. The moisture was evaporating and creating bubbles and little pops in the plastic as it went through the nozzle at about 220° Celsius:

Bubbled Filament
You can easily see and feel the bubbles even though the diameter of the filament is only 1.75mm.

If I really wanted to, I could probably still print with it, but the printed surface will probably be rough and adhesion wouldn’t be as good.

Fortunately, drying filament is pretty simple. Machines dedicated to drying filament are available, and while they have trays and covers made to fit filament spools, I found them to be a bit too expensive for my budget. I ended up buying a cheap food dehydrator from my local hardware store and drilling a couple of holes in an old Tupperware container to use as a lid:

Now I just need to let it sit for a while and the filament will be good to go!

Signs Of A Clogged Printer Nozzle

I’ve been fighting with my printer for a couple of days now because the nozzle keeps clogging. After changing out the nozzle and cleaning the hotend, it would run fine for a while and then start to plug up again. The printer has seen a lot of heavy use with different materials over the past six months, so I suppose I don’t blame it.

I think I’ve got it fixed now, but you can’t ever really have 100% confirmation that the crud is all gone. It may print well for the next one, two, or twenty prints, then clog again.

Signs that your printer is developing a clog:

  • You find you have to make changes to feed rate or flow settings that you didn’t before.
  • Extrusion (particularly first layer) doesn’t look consistent.
  • There is a roughness to horizontal and vertical skins that wasn’t there before.
  • Printed parts are more fragile than usual.
  • Lots of horizontal, “dotted” lines along the sides of the print.
  • You can hear an odd scraping sound coming from the extruder (the extruder gear is grinding plastic because it can’t push it in fast enough).
  • There is a lot more dust than usual around the extruder gear/motor (same reason as above point).
  • The motor driving the extruder keeps “thumping” or “popping” and jumping backwards because it can’t keep up with the electronics that make it turn.
  • The filament spool is not turning.

If you’re suspicious that there’s a clog, level your print bed and do a test print (you would be amazed at how many things can be fixed just by levelling the bed). If it’s still not printing properly, raise the nozzle from the bed (the further, the better), and extrude a bunch of filament, making sure to keep cutting it so it doesn’t touch the print bed and make the filament bend or twist. If the extruded plastic is pointed straight down, is consistent along its length, and is the appropriate thickness, things may be okay. Here are some samples from a test extrusion I did that showed there was definitely some junk stuck in there somewhere:

Filament with a lot of moisture in it can extrude like this. I dry my filament regularly and use a lot of dessicant so it’s probably junk in the nozzle.
This looks more like a clog.
Again, could be damp filament… could be junk floating around in the nozzle.
This is DEFINITELY a clog.

Another thing I do to help me keep an eye on things is mark one or two spokes on the filament spool with a colour that stands out (silver on a black spool, black on a white spool, etc). That way, I can note where the marked spokes are, leave the room, and come back later to see if they’ve moved.

I hope I’ve got it cleared out. If there is still any junk in there, it would be nice if it either melts or is small enough to fit through the nozzle. I have a spare (brand new) hotend, so if I need to I can swap it out and give the used one an even more thorough cleaning.