Arduino Ladder · Bozoma Innovation Hub

Band 4  ·  Night Guard

Swap  The room monitor

A sensor that hands you degrees and a percentage, already meant. The one time somebody else did the calibrating.

Time
90 min
You need
DHT11, 2 LEDs, 2 resistors, 9 jumper wires (plus a 10k resistor if yours is the bare four-pin kind)
At once
One per DHT11
Before this
Finish Band 4 up to Part 9. This replaces the night guard in Part 10. It never uses analogRead, map or the division trap, so do not skip Parts 5 to 9.

Sketches for this project

Every file opens with a plain-English header saying what it does and how to wire it, hole by hole.

Why

The one sensor that answers in units

Every other sensor in this course hands you a number between 0 and 1023 and leaves the meaning to you. The knob, the light sensor, the rain plate: all of them make you go and find out what their numbers mean in your room.

This one hands you degrees. And a percentage. Already meant.

That is worth building precisely because it is the exception, and because of the question it raises.

What this Swap does not give youBecause the sensor answers in units, this build never uses analogRead, never uses map, and never meets the division trap in Part 9. Those are three of Band 4's four big ideas, and you will be asked about them in Check yourself. So do Parts 1 to 9 first and do not skip them. This page replaces Part 10, the night guard, and nothing earlier. What it adds instead is the question the night guard cannot ask: what do you do when somebody else has already decided what a number means?
Somebody else did the calibration, and you should still check it

Inside the DHT11 is a small sensor and a small chip. The chip does what you did by hand in the night guard: it takes a raw electrical reading and turns it into a number that means something, using a table put there at the factory.

So the calibration did not disappear. It moved somewhere you cannot see, done by somebody you cannot ask, for a room that is not yours.

That is a reason to check it, not a reason to relax. This build ends with you putting it next to a real thermometer and writing down the difference.

Build

Three wires

25 min
+ − − + j i h g f e d c b a 1 5 10 15 20 25 30 USB ARDUINO UNO DHT11 module DHT11 module + + 220 220 + + 220 220 a1 a1 a25 a25 a26 a26 a27 a27 a3 a3 a4 a4 a5 a5 a7 a7 a8 a8 b1 b1 b25 b25 b26 b26 b27 b27 b3 b3 b4 b4 b5 b5 b7 b7 b8 b8 SCL SCL SDA SDA AREF AREF GND GND 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 IOR IOR RST RST 3V3 3V3 5V 5V GND GND GND GND VIN VIN A0 A0 A1 A1 A2 A2 A3 A3 A4 A4 A5 A5
The three-pin module. Same warning: match each wire to the printing on your own board rather than counting positions.
Before you startUSB unplugged. Take the light sensor and its resistor off the board.
Which rails this page meansEverything on this page goes in rows a to e, so use the pair of rails along the bottom edge, the ones nearest row a. Band 4's own builds used the top pair, so move your two rail wires down: + rail to the Arduino's 5V pin, − rail to a GND pin, both on the bottom pair. On most boards the top rails and the bottom rails are not joined to each other, and mixing them means nothing works and nothing looks wrong.

Which DHT11 have you got?

Count the pins on yours. This decides whether you need a resistor.

Three pins, on a small circuit board

A module. The resistor it needs is already on the board.

→ Push its three pins into a25, a26, a27. Its pins fill those holes, so every wire goes into row b of the same column: b25, b26, b27. Then, reading the printing on your own board rather than counting positions: the ground pin, marked -, G, GND or −, gets its wire to the − rail; the power pin, marked +, V, VCC or 5V, to the + rail; and the data pin, marked S, OUT, DATA or DAT, to pin 4.

Different factories use different letters for the same three pins. Read the printing on your board rather than counting positions, because the order is not the same on every module either.

Four pins, bare, no board

The raw part. It needs a 10k resistor that the module version has built in.

→ Hold it with the holes facing you and push its four pins into a30, a31, a32, a33, left to right. Then: wire b30 to the + rail, wire b31 to pin 4, nothing at all in column 32, wire b33 to the − rail. Finally the 10k resistor from c30 to c31. Note the letters: b30 holds a wire so the resistor goes in c30, because a hole takes one leg.

The 10k resistor holds the data line up when nobody is talking,

+ − − + j i h g f e d c b a 1 5 10 15 20 25 30 35 USB ARDUINO UNO DHT11, bare: + / data / nothing / - DHT11, bare: + / data / nothing / - 10k 10k + + 220 220 + + 220 220 a1 a1 a3 a3 a30 a30 a31 a31 a32 a32 a33 a33 a4 a4 a5 a5 a7 a7 a8 a8 b1 b1 b3 b3 b30 b30 b31 b31 b33 b33 b4 b4 b5 b5 b7 b7 b8 b8 c30 c30 c31 c31 SCL SCL SDA SDA AREF AREF GND GND 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 IOR IOR RST RST 3V3 3V3 5V 5V GND GND GND GND VIN VIN A0 A0 A1 A1 A2 A2 A3 A3 A4 A4 A5 A5
The bare part. Column 32 stays empty, and the 10k goes in row c because row b already holds a wire.
which is the same job the internal pull-ups did for your buttons in Band 3. The module has one soldered on; the bare part expects you to bring your own.

PartWiring
Green lightlong b3, short b4; resistor a3 to a1; wire b1 to pin 7; a4 to − rail
Red lightlong b7, short b8; resistor a7 to a5; wire b5 to pin 8; a8 to − rail
PowerOne wire from the + rail to the Arduino's 5V pin
GroundOne wire from the − rail to a GND pin

Install the library. Tools, then Manage Libraries, search SimpleDHT, install the one by Winlin. Once, on one machine.

Why this oneThere are several DHT libraries and some of them need a second library installed alongside. SimpleDHT needs nothing else, which is one less thing to go wrong on a slow connection.
If that computer has no internetLibrary Manager will simply find nothing, and the sketch will refuse to compile with a message ending No such file or directory. Nothing is broken. On any machine that does have a connection, search for the library, download it as a .zip, and carry it here on a phone or a USB stick. Then use Sketch, then Include Library, then Add .ZIP Library, and point it at the file. If your kit came with a folder of libraries on a stick or a disc, it is already in there. Do this before you wire anything, because without the library nothing you build can be tested.

Upload b4_07_room_monitor.ino and open the serial monitor at 9600.

If it says WARNING from the very first readingNothing is wrong, and near the coast this is likely. The sketch ships with tooHumid = 80, and in Aiyinasi the air sits above that most of the day. Open the sketch, set tooHumid to 95 for now so you can see the fine case and the green light working, then set both numbers properly from your own room in the Measure section below. Choosing those numbers is this build.
You should seeA line every two seconds: a temperature in degrees, a humidity percentage, and the word fine. The green light is on. Both numbers are whole numbers and the temperature should be somewhere plausible for the room you are sitting in.
If it says “could not read the sensor” every timeAlmost always the data wire on the wrong pin, or a bare four-pin part with no 10k resistor. Check both. The error number itself is not worth chasing.
If it reads once and then errorsSomething is asking it too fast. Check the delay(2000) at the bottom of loop is still there.
If the temperature is wildly wrong, like 0 or 80Check the wiring order. On the bare part, pin 3 really does go nowhere, and using it as ground gives nonsense rather than nothing.
If the part gets hot, or hot enough to be uncomfortable to touchUnplug immediately. Power and ground are the wrong way round, which happens easily on a module whose pins are in an order you assumed rather than read. Check the printing, put it right, and then test again: a DHT11 usually survives a few seconds of this and usually does not survive a minute.

Breathe on it, gently, from a few centimetres away, and watch.

You should seeThe humidity climbing fast, within a few seconds, and the temperature rising a degree or two more slowly. Then both drifting back down over half a minute or so. That lag is real and it is worth noticing: the part takes time to agree with the world.
Measure

Check the factory's work

30 min

You have been handed a number in units. Now find out whether to believe it.

Put it next to any other thermometer for five minutes: a wall thermometer, a kitchen one, the weather reading on a phone, or somebody else's DHT11 if a classmate built one. Working alone, a phone's weather reading for your town plus one indoor thermometer is enough for the table; note that the phone's number is for outside, and say in your log why that makes it a weak comparison rather than a useless one.

WhatSaysDifference from yours
Your DHT11—
Another thermometer
Somebody else's DHT11
If you are working alone, and offlineLeave the third row blank rather than inventing something for it. Then write in your log what a second DHT11 would have told you that one cannot: two of the same part disagreeing is evidence about the part, while your part disagreeing with a wall thermometer could be either of them. Knowing which question a measurement can answer is worth more than the measurement.
You should seeAgreement within about two degrees, and probably not exact agreement. A DHT11 is specified to about two degrees and about five percentage points of humidity, and it reads in whole numbers only. That is fine for “is this room too hot” and useless for anything scientific. Notice what that means: if it says 60 percent, the honest reading is “somewhere between 55 and 65”. A number printed to the unit is not a number known to the unit, and that gap catches people out for the whole of their careers.

Now choose your two thresholds, tooHot and tooHumid, by measuring your actual room over a day rather than by guessing.

Read it in the morning, in the afternoon and at night. Write the three pairs down. Then pick numbers that would have warned you at the right moment and not before.

The trap here is the same one as everywhere elseIf you pick 30 degrees because it sounds hot, and your room is 31 degrees all day every day, you have built a device that is always warning and therefore says nothing. The number has to come from the room.
Two questions for your log
  1. The night guard made you invent the meaning of a number. This build handed you the meaning. Which device would you trust more in a place you had never been, and why?
  2. This sketch has only one threshold for each value, not two. Given what the rain alarm and the night guard both taught you, what will happen when the room sits exactly on 32 degrees? What would you change?
Something to check yourself against

1. There is no right answer, but there is a better argument, and it is probably not the one you expect. The DHT11 is more convenient in a place you have never been, because it arrives already meaning something. The night guard is more trustworthy, because you calibrated it in the room it is standing in and you know exactly what it was compared against. The DHT11's factory table was made for an average room by somebody who has never seen yours. So: trust the DHT11 to be roughly right anywhere, and trust the night guard to be exactly right in one place. Say which of those your device actually needs, and you have answered the question properly.

2. The warning will flicker on and off as the reading wobbles between 31 and 32, because there is only one line and the reading sits on it. It needs two numbers: warn above 32, clear below 30. That is the same fix as wetLevel and dryLevel, and the same fix as the deadband in Band 6. Adding it is the best Bronze task on this page, and it is deliberately left undone in the sketch so that you can find it.

Change it

Make it yours

35 min
Bronze
Fix the flickering threshold you found in question 2, using two numbers instead of one for both temperature and humidity.
Silver
Remember the highest and lowest temperature since it was switched on, and print all four numbers every time. Then leave it running for a whole day and see what the room actually did.
Gold
Work out the heat index, which is how hot it feels once the humidity is high, and warn on that instead of on temperature. If you cannot get online, use this rule of thumb, which is close enough below about 40 degrees: add one degree for every ten percentage points of humidity above 40. So 32 degrees at 80 percent humidity feels like about 36. If you can get online, find the real formula, use it, and be honest in your log about how much of it you understood. Either way, say why a device that warns on how it feels rather than on the temperature might be the more useful one in Aiyinasi.
Done

You still owe Band 4 the same evidence

This Swap replaces the night guard. To claim Band 4 you still need:

  • A video of it working, including a warning happening
  • Your comparison table against another thermometer, and your day's readings
  • Your two chosen thresholds and a sentence on why those numbers
  • Your build log
  • Both analogRead and analogWrite in your glossary, with their different ranges. This build uses neither, so take them from Parts 5 to 9, which you did before coming here
  • Five or six correct answers in Part 14, the Check yourself questions, including question 6

The Check yourself questions are about analogRead and the 0 to 1023 range, which this sensor never gives you. Answer them anyway. If you cannot, spend twenty minutes with the light sensor and the knob before claiming the band, because that range is the thing almost every other sensor you meet will speak in.

Ship it

One video under sixty seconds, and one post of five lines. You built something different from the person next to you, so your video is the one nobody else in the room can post. Say in the post which build you chose and why — that choice is itself worth a line.

The four shots: three seconds of the thing still, fifteen of you doing something to it, fifteen of it responding all the way to the end, and ten of your measurement or the thing that went wrong first.

Show your work has the template and the three checks to make before anything goes public. Tag it #BozomaBuilds.