My dorm's version of an HVAC system is a cool water radiator. We have no heating and a box that lets us turn a fan to one of four familiar settings: off, high, medium, and low. The complete lack of normal temperature control made me extremely annoyed at the start of the semester as temperatures would rise like a boiling frog, and by the time I had noticed, changing it to high lowered the room to below humane temperatures. After thinking against tearing the whole control system out and soldering in my own fan controller, I thought that the best solution would be a device that calculates the best setting to keep the temperature around our goal and pester the users in the room until they change it.
Thankfully, from a previous project where I tried to develop a comfortable outdoor house for my girlfriend's cat, I had a Raspberry Pi Zero W and two DHT22 temperature sensors. With these as my core components, I developed a summary of how the system would work:
The temperature sensor(s) would constantly check the temperature and keep a running log of how the current setting changed the room temperature every minute.
If it deems that another setting would be better for dealing with keeping the room within normal ranges, it would try to change the setting.
Due to wanting to keep my housing contract, I could not directly wire the board into the cooling unit so it would instead start blinking a light corresponding to the desired temperature change.
When a change is requested, the user may press a button to accept the change, at this point, they would change the dial settings. From the button press, the program knows that the instruction was followed.
For ease of use, the user should be able to shift the target temperature up and down via physical buttons.
To create the circuits I planned I need a few extra things.
4x LEDs of different colors
3x press buttons
A 7-segment display
A lot of wiring
The 7-segment display I was able to get is the Adafruit 7-segment LED HT16K33 Backpack with a Luckylight M1510037 soldered display. This interface can be communicated with by the Linux I2C package. This was a learning curve, but with some former knowledge of Linux filesystems, was relatively easy after decoding the command structure of the driver. For this system, every command is either 1 byte or 2 bytes. One-byte commands do tasks such as initializing the display, enabling blinking, and setting brightness. Two-byte commands send data to the driver with a location (that I had to find out for myself) and a byte containing the on/off value of each led in the location. For example, sending a command to write an eight to the 2nd digit on the display would be 0x027F; this hex code means set location 2 to value 01111111 meaning everything but the decimal light. This code is handled by 7segment.c and 7segment.h in the repo.
As previously mentioned, I had DHT22 temperature sensors left over from an abandoned previous project. As one of my goals was to use C for the entire project, the use of libraries for the common sensor was practically out of the question. Instead, after searching for a while, I adapted a common snippet of C code which handles the bit alignment and decoding process to remove humidity data as it was unnecessary for my application. I did briefly try to decode the datasheet, however I began to run short on time. If you want to look at it, you can see it here.
In putting together the device I had to learn soldering and some extra resourcefulness after burning two DHT22 temperature sensors (thank you Matthew for the replacement) by accidentally cross-soldering two through-pin connectors. Additionally, due to a lack of ground and 3.3V rails on the Raspberry Pi, I had to solder together multiple wires. My biggest regret in construction was deciding to free-hand solder loose copper wire to buttons and LEDs that were designed for through-hole mounts. These mistakes led to many failures and a lot of pain.
As I briefly mentioned, one of my goals was to learn C with this project. That goal was achieved, with some help from working on HexChess, but not without significant obstacles. Apart from the rocky process of dealing with cross-compiling for Raspberry Pi, not understanding "extern" variable descriptors for header files, and needing to deal a lot with file manipulation, the process was rather easy. However, in hindsight, many parts of the code could be radically improved and I will add any updates to the code beneath this. However, all of the goals that I originally set out to accomplish we met with the final product with the device keeping a 30-minute history of the room temperature changes and determining the best course of action automatically. The Git repository can be seen here.
A Raspberry Pi was frankly overkill for such a simple project
A breadboard basis or designing a PCB that would use a simpler temperature sensor would have worked better and been more polished
C code is surprisingly enjoyable once all of the pain of Raspberry Pi's are traversed
I really enjoy embedded systems development and will target it in the future as an ideal path
Set aside more time for creating a chassis next time
People do get very confused when you pull out a mess of wires in the middle of class or at a restaurant