{"id":14967233,"url":"https://github.com/sathya-ml/pico-temperature-control","last_synced_at":"2026-01-22T11:33:34.550Z","repository":{"id":253480357,"uuid":"842265225","full_name":"sathya-ml/pico-temperature-control","owner":"sathya-ml","description":"A simple temperature controller using a Raspberry Pi Pico, DHT22 sensor, and relay to manage heating in small enclosures.","archived":false,"fork":false,"pushed_at":"2024-08-17T12:29:41.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T09:44:36.737Z","etag":null,"topics":["dht22","heating-control","micropython","pico","raspberry-pi-pico","relay","temperature-control"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sathya-ml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-14T02:15:29.000Z","updated_at":"2024-08-28T06:48:37.000Z","dependencies_parsed_at":"2024-12-27T04:15:19.830Z","dependency_job_id":null,"html_url":"https://github.com/sathya-ml/pico-temperature-control","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":0.07692307692307687,"last_synced_commit":"2d353396b0dee77f4a8f40acb8ca21c1e1b595f9"},"previous_names":["sathya-ml/pico-temperature-control"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sathya-ml/pico-temperature-control","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sathya-ml%2Fpico-temperature-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sathya-ml%2Fpico-temperature-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sathya-ml%2Fpico-temperature-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sathya-ml%2Fpico-temperature-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sathya-ml","download_url":"https://codeload.github.com/sathya-ml/pico-temperature-control/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sathya-ml%2Fpico-temperature-control/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28662128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dht22","heating-control","micropython","pico","raspberry-pi-pico","relay","temperature-control"],"created_at":"2024-09-24T13:37:40.713Z","updated_at":"2026-01-22T11:33:34.536Z","avatar_url":"https://github.com/sathya-ml.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raspberry Pi Pico Temperature Controller\n\n⚠️ **Disclaimer**\n\nThis project involves working with electricity, which can be dangerous and potentially life-threatening if not done\ncorrectly.\nIt may include components or instructions that require working with both low-voltage circuits and higher voltages that\ncan be hazardous. **I am not an expert in electrical engineering or safety, and this project is provided solely for\neducational and informational purposes**. If you are not experienced or qualified to handle electrical components,\nparticularly those involving higher voltages, please seek assistance from a professional. **The author is not\nliable for any injury, damage, or loss of life resulting from following the instructions or\nusing the code provided in this repository. Proceed with caution and at your own risk.**\n\n## Description\n\nThis project implements a simple temperature controller using a Raspberry Pi Pico to control a heating device based on\ntemperature readings from a DHT22 sensor. It's designed to maintain the temperature in a small enclosure, such as\na small greenhouse or a microgreens growing space, whose outer environment is colder than the desired\ntemperature inside the enclosure. It achieves this by continuously reading the temperature from a DHT22 sensor,\nand controlling a relay that switches on or off an external heating device as needed.\n\nTo achieve the temperature control through a relay which can only take two states: on or off, it uses a [hysteresis\ncontrol](https://en.wikipedia.org/wiki/Bang%E2%80%93bang_control) approach similar for example to the approach used in\na storage water heater.\nGiven a target temperature, the heater is turned on when the temperature falls below the target minus a certain\ndeviation,\nand turned off when the temperature rises above the target plus that same deviation.\nHaving such a deviation tolerance has the benefit of avoiding the relay from turning on and off too frequently,\nwhich would case unnecessary wear on both the heating device and relay.\n\nNo assumptions are placed on the heating device and its power source, as long as it can be connected to and controlled\nby a relay. It is not the most efficient or safest way to control temperature, but it is a simple and cost-effective\nway.\nHowever, there is a risk that the relay could become stuck in the on position, which could cause the heating device to\noverheat and potentially cause a fire. For this reason, it is important to use a relay that is rated for the power of\nthe\nheating device, and to monitor the enclosure's temperature to ensure it remains within safe limits.\n\nAs a safety measure, the code will blink an LED to indicate that something is wrong if the\ntemperature exceeds a maximum deviation, while the LED will be on if the temperature is below the target.\nIn case of a sensor reading failure, the code will tolerate a certain number of consecutive failures before aborting.\n\nThe code is written in MicroPython, and is designed to be readable, modular and easily extensible.\nWhile this might somewhat impact performance, the effect is not expected to be significant given the simplicity of the\nproject,\nand the fact that the sampling interval of the sensor is 2 seconds.\nWhile for now it handles only temperature control, the functionality could be extended to humidity control, or to\ncontrol other components based on specific rules or sensor readings (lighting, watering, etc.).\n\nThis project was created as a personal learning exercise to explore embedded systems and working with the\nRaspberry Pi Pico and MicroPython. It is not intended as a professional or production-ready solution.\nAny feedback or suggestions for improvement are welcome.\n\n## Hardware and Wiring\n\nTo build this project, you will need the following components, most of which are readily available online\nor at local electronics stores:\n\n- Raspberry Pi Pico\n- DHT22 temperature and humidity sensor\n- A relay module and a power source for it.\n- A heating device\n- LED and the corresponding resistor to limit the current.\n- Breadboard and jumper wires\n\nThe wiring diagram is shown below:\n![Wiring Diagram](img/circuit.svg)\n\nThe Raspberry Pi Pico must have headers soldered onto it to be able to connect it to the breadboard.\nIt's possible to obtain the Pico with headers pre-soldered, but if you have one without headers, you'll need to solder\nthem on yourself.\n\nThe reason we're using a separate power supply for the relay is that the Raspberry Pi Pico can't provide enough voltage\nto trigger the relay. Most relays require 5V or higher to trigger, and the Pico can only provide 3.3V. It's also\nimportant to connect the ground of the relay power supply to the ground of the Pico to ensure that the relay can be\ntriggered correctly. The relay should also be rated for the heating device you are using.\n\nThe heating device you choose, its power supply and wiring it to the relay are up to you. Make sure to follow the\ncorrect safety procedures based on the specific device you choose.\n\nThe LED is optional and is used to indicate when something goes wrong, along with the onboard LED on the Pico.\nThe LED has to be connected in series with a resistor to limit the current, as the Pico's 3.3V output is likely\nhigher than the LED's forward voltage. Depending on the LED, the resistor value may vary.\nIt's up to you to calculate the correct value. There are many online calculators that can help you with this, see\nfor\nexample [this one](https://www.digikey.com/en/resources/conversion-calculators/conversion-calculator-led-series-resistor).\n\n## Installation\n\nFirst, install MicroPython on your Raspberry Pi Pico. You can find instructions on how to do this on the\nofficial Raspberry Pi website [here](https://www.raspberrypi.com/documentation/microcontrollers/micropython.html).\n\nThe [src/config.py](src/config.py) file contains the configuration parameters for the project.\nThe default values are already provided, but you should adjust them to match your specific setup:\n\n+ the GPIO number for the DHT22 sensor\n+ the GPIO number for the relay\n+ the GPIO number for the LED\n+ the sensor sampling interval, which for the DHT22 is 2 seconds minimum\n+ the number of tolerated sensor reading fails before aborting\n+ the target temperature\n+ the temperature deviation - how much the measured temperature can rise or fall before the relay is triggered\n+ the maximum temperature deviation - if the measured temperature exceeds the target by this value in any direction\n  something is wrong, so the LED is used to indicate this to the user\n+ whether the relay is active at high or low signal\n+ the LED blink interval\n\nAfter configuring the parameters, copy the files in [src/](src/), and the files in [test/](test/) to the Pico.\nThere are many ways to do this, but the\neasiest is using the Thonny IDE. Instructions are available on the official Raspberry Pi website\n[here](https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/2).\nThe files in *test/* are optional, and are intended to test the functionality of the connected components as they are\nconnected to the Pico, like the relay, the LEDs, and the DHT22 sensor.\nThe files in *src/* contain the main code that will run on the Pico.\n\nOnce the *src/* files are on the Pico, the `main.py` script will automatically run and execute the code the next time\nyou power on the Pico.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsathya-ml%2Fpico-temperature-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsathya-ml%2Fpico-temperature-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsathya-ml%2Fpico-temperature-control/lists"}