Âé¶ą´«Ă˝

Make a weather station with BBC micro:bits and a sensor

Get up-to-the-minute weather reports by turning an environmental sensor and two BBC micro:bits into a mini weather station

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.

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 “Extensions”, type in “DHT11” 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 “show number” blocks from “Basic” and clip into these two “Read humidity” blocks from the “DHT11/DHT22” menu, using the drop-down to change the first to “Read temperature”. Lastly, add a “pause” from “Basic” to “on start” to give this sensor a moment to fire up before we start quizzing it.

Connect the sensor’s Vcc connection to the micro:bit’s 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 “show number” blocks with two “radio send value name = 0” blocks from the “Radio” menu. Where these say “0”, clip two “round” blocks from “Math”, then into the “0” of each clip a “Read humidity” block from “DHT11/DHT22”, using the drop-down to change the first one to “Read temperature”. In the first “name” oval, enter “T:” and put “H:” in the second. Then, clip a 2-second “pause” between the blocks and another “pause” after. The second “pause” will determine how often this micro:bit sends data. I went for 10 seconds.

Finally, take “radio set group 1” from “Radio” and clip it into “on 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 “radio set group 1” to “on start”. Next, grab an “on radio received name value” from “Radio”. Into this, clip a “show string” block and a “show number” block from “Basic”. Then, click and drag the “name” oval from the top of the “on radio received” block and drop it into your “show string” block. Do a similar thing for “value” and “show number”. This code will make your receiver micro:bit show “T:”, followed by the temperature, and “H:” 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

1 Moisture-sensing plant

2 Moisture and temperature-sensing plant

3 Plant auto-waterer

4 Tweeting wildlife cam

5 Pest scarer

6 BBQ thermometer

7 Rain alarm

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

Topics: Electronics / weather