Unit B · Things that move, things that show
What we are making: a thermometer that shows temperature and humidity on your screen. Two modules working at once, for the first time.
The DHT11 is a sensor that already knows the answer. You do not have to convert a voltage or work out a formula — you ask it for a temperature and it hands you a number in degrees Celsius. Sensors like this are called digital sensors, and they are the easy kind.
The interesting part of today is not the sensor. It is that two modules are sharing the same board: the screen on A4 and A5, the sensor on pin 2, both drawing power from the same 5V and GND. That is how every machine you build from now on will be arranged.
int cannot hold that."Humidity: " to "Hum: " and see how much room that frees.delay(2000) and not less? The DHT11 physically cannot produce a new reading faster than about once a second. Ask it more often and it hands you the old number, or nan — which means ‘not a number’ and is the sensor's way of saying you rushed it.| What you see | Why | What to do |
|---|---|---|
nan on the screen | Read too fast, or the data wire is loose. | Check pin 2 is firmly in, and that the delay is at least 2000. |
| Temperature never changes | The DHT11 only reports whole degrees. | Not a fault. It is a coarse sensor; breathe on it to see it move. |
| The screen went blank when I added the sensor | A power wire came out. | Reaching in to add the sensor usually pulls the 5V wire. Reseat it. |
| Old digits left behind new ones | Shorter text does not erase longer text. | Print two or three trailing spaces after each value. |
In this session