## Should the Air Conditioner be on?

🕓Sep 5, 2020 · ☕2 min read

While it’s neat to be able to turn the air conditioner on ahead of time to cool down the room, it would be better if I can get a reading of the temperature in the room. The RPiZ from the Raspberry Pi Zero remote for my air conditioner has plenty of GPIO ports left over, so this is a quick hack to install a temperature diode.

## Hardware

### The circuit board

1. IR blaster circuit from the previous post
2. 10KΩ resistor - diode for the temperature diode.
3. DS18B20 temperature sensor - I got mine from Amazon

## Software

### Check temperature

We are using one wire protocol to read from the DS18B20, and on GPIO port 22. We need to change the default one wire port on the raspberry pi with the following change to /boot/config.txt;

dtoverlay=w1-gpio,gpiopin=22


I added it beneath the other GPIO definitions, so that section looks like this;

dtoverlay=gpio-ir,gpio_pin=24
dtoverlay=gpio-ir-tx,gpio_pin=23

dtoverlay=w1-gpio,gpiopin=22


reboot the system, and then enter the following to enable the appropriate kernels;

 1 2  sudo modprobe w1-gpio sudo modprobe w1-therm 

now check the following directory for the sensor;

 1 2  ls /sys/bus/w1/devices 28-3c01a8165e2a w1_bus_master1 

In this case, my thermometer device is 28-3c01a8165e2a and I can get a reading by running the following command;

 1 2 3  cat /sys/bus/w1/devices/28-3c01a8165e2a/w1_slave cb 01 55 05 7f a5 81 66 bc : crc=bc YES cb 01 55 05 7f a5 81 66 bc t=28437 

The second line, t=28437 tells me that the temperature is 28.437C, or 83.1866F.
My air conditioner remote has the additional functionality of displaying current temperature;

82F is close to 83.1866F, which is within the ±0.5C as per the spec of DS18B20.

## Conclusion

I’ve been simply checking the weather from the web before turning the AC on, but this way, I get to know what the temperature inside the apartment.

The temperature might not be exactly correct, but it’s close enough that I can use it to determine if I should turn the AC on and off.

WRITTEN BY
Minuk
💻Software Engineer 🤖Technophile