
New stuff you need
Second micro:bit and battery DHT11 environmental sensor
LAST week it was rain. This week, our mini weather station will measure temperature and humidity. And by using a second BBC micro:bit, we can get the readings before heading outside.
Advertisement
First, we need a DHT11 sensor, and to check whether it works using one micro:bit. To do this, we must teach the MakeCode editor new tricks. Go to 鈥淓xtensions鈥, type in 鈥淒HT11鈥 and click on the DHT11/DHT22 result.
Under the new menu option, select the block that is five lines tall and clip it into forever. This one communicates with the sensor. The default settings are fine. Under that block, clip two 鈥渟how number鈥 blocks from 鈥淏asic鈥 and clip into these two 鈥淩ead humidity鈥 blocks from the 鈥淒HT11/DHT22鈥 menu, using the drop-down to change the first to 鈥淩ead temperature鈥. Lastly, add a 鈥減ause鈥 from 鈥淏asic鈥 to 鈥渙n start鈥 to give this sensor a moment to fire up before we start quizzing it.
Connect the sensor鈥檚 Vcc connection to the micro:bit鈥檚 3V pin, its ground to ground and out to pin 0. Attach the battery and check the readings seem sensible for temperature and humidity.
Now, we can transmit the data to another micro:bit via radio. In , replace the 鈥渟how number鈥 blocks with two 鈥渞adio send value name = 0鈥 blocks from the 鈥淩adio鈥 menu. Where these say 鈥0鈥, clip two 鈥渞ound鈥 blocks from 鈥淢ath鈥, then into the 鈥0鈥 of each clip a 鈥淩ead humidity鈥 block from 鈥淒HT11/DHT22鈥, using the drop-down to change the first one to 鈥淩ead temperature鈥. In the first 鈥渘ame鈥 oval, enter 鈥淭:鈥 and put 鈥淗:鈥 in the second. Then, clip a 2-second 鈥減ause鈥 between the blocks and another 鈥減ause鈥 after. The second 鈥減ause鈥 will determine how often this micro:bit sends data. I went for 10 seconds.
Finally, take 鈥渞adio set group 1鈥 from 鈥淩adio鈥 and clip it into 鈥渙n start鈥. The radio group establishes a comms channel so micro:bits using the same one can recognise messages from each other.
Now for the receiver. Start a and add the same 鈥渞adio set group 1鈥 to 鈥渙n start鈥. Next, grab an 鈥渙n radio received name value鈥 from 鈥淩adio鈥. Into this, clip a 鈥渟how string鈥 block and a 鈥渟how number鈥 block from 鈥淏asic鈥. Then, click and drag the 鈥渘ame鈥 oval from the top of the 鈥渙n radio received鈥 block and drop it into your 鈥渟how string鈥 block. Do a similar thing for 鈥渧alue鈥 and 鈥渟how number鈥. This code will make your receiver micro:bit show 鈥淭:鈥, followed by the temperature, and 鈥淗:鈥 followed by the humidity on the screen.
Now, stash your transmitter in a waterproof container and poke a hole so air can get in, but the electronics are safe. The radio range is up to 70 metres in an open area without interference, so get creative with the placement!
For next week
Large plastic drinks bottle
Cardboard
Zip ties
Servo motor
Zip
Glue
Nuts (the edible kind)
Next in the series
2 Moisture and temperature-sensing plant
8 Mini weather station
9 Remote controlled pest-proof bird feeder part 1
10 Bird feeder part 2
To download a printable version of this page click here
Email: maker@newscientist.com