Raspberry Pi
DHT11 Temperature Sensor
“Read the real world. Temperature. Humidity. Live data from thin air.”
This is Lesson 18 of 18.
You’ve come a long way. From a bouncing ball in a browser to reading live data from the physical world. This is the final lesson — and it’s the most powerful one. Let’s finish strong.
What you will need
Your Raspberry Pi, Thonny, and a DHT11 sensor.
DHT11 Sensor
A small blue sensor that reads temperature and humidity. Available for about £2-5 on Amazon or eBay.
Hardware needed
Jumper Wires
Three jumper wires — one for power, one for data, one for ground.
Hardware needed
adafruit-circuitpython-dht
A Python library that reads the DHT11. Install with one command in the terminal.
Free library
What you will have
A Python script that reads real temperature and humidity from the DHT11 sensor and prints live readings every 2 seconds.
Breathe on the sensor. Watch the humidity rise. Hold it in your hands. Watch the temperature climb.
Install the library first
One command in the terminal.
Open a terminal on your Raspberry Pi and type this command exactly:
📋 Terminal Command
pip3 install adafruit-circuitpython-dht
✅ Copied!
Wire it up
Three connections — power, data, ground.
1
Connect VCC to 3.3V (physical pin 1)
The DHT11 has 3 pins — VCC, DATA, GND.
2
Connect DATA to GPIO 4 (physical pin 7)
Connect the DATA pin of the DHT11 here.
3
Connect GND to any GND pin
Physical pin 6 or 9 on the Pi header.
Your prompt
Copy this. Paste it into your AI. Hit Enter.
📋 Your Prompt — Copy Everything Below
Write a Python script for Raspberry Pi that reads temperature and humidity from a DHT11 sensor connected to GPIO pin 4. Use the adafruit_dht library. Print the temperature in Celsius and the humidity percentage every 2 seconds. Include a try/except block to handle read errors gracefully. Stop cleanly on Ctrl+C. Add comments explaining how the sensor reading works.
✅ Copied! Now paste it into your AI.
What to do after
Paste, save, run, breathe.
1
Paste the AI code into Thonny
New file → paste → save as sensor.py.
2
Press F5 to run
Temperature and humidity readings print every 2 seconds.
3
Breathe on the sensor
Watch the humidity percentage climb in real time. That’s your breath being measured by your code.
4
Press Ctrl+C to stop
The program exits cleanly.
🛠️ Didn’t work?
Check these first:
1 Did the pip3 install command complete successfully?
2 Is VCC connected to 3.3V (not 5V)?
3 Copy any error from Thonny and paste to your AI: “This didn’t work. Here’s the error: [paste]. Please fix it.”
Vibe Tweak
Add Fahrenheit.
Find the line that prints the temperature. Add a second line that converts Celsius to Fahrenheit and prints that too.
The formula
F = C * 9/5 + 32
→
Print like this
f”{temp_f:.1f}°F”
Extra Credit
Want to go further?
📋 Extra Credit Prompt
Update the DHT11 sensor script to log readings to a CSV file. Every 10 seconds write a new row to sensor_log.csv with the timestamp, temperature in Celsius, temperature in Fahrenheit, and humidity. Print a confirmation message each time a row is saved.
✅ Copied!
Final Reflection
You finished all 18 lessons. Think about this.
“Lesson 1 you made a ball bounce in a browser. Lesson 18 you read live temperature data from the atmosphere. You built browser games, console programs, Windows desktop apps, physical hardware projects, and a sensor that reads the real world. All by describing what you wanted. That is vibe coding.”
🏆
All 18 Lessons Complete.
HTML. Python. C# Console. WPF. Arduino. Raspberry Pi. You did all of it. You are a vibe coder.
Back to Home →