Fridge Temperature Control using a RPi and 433MHz Power Plug

 

This is my first blog in this category. I am a retired academic doctor who was previously a software engineer. So when I retired in 2016, I naturally moved back to my first love and started tinkering with tiny single board computers and various inexpensive electronic gadgets. I monitor a lot of things in my house. I display the captured data using a Raspberry Pi running InfluxDB, like this:

I will explain how that is done on another post.

Now for this post, it began when I noticed that my rather expensive bar fridge stopped regulating the temperature. My drinks were rather frozen! The fridge is no longer produced and the thermostat part is not available. So instead of buying another one I built this inexpensive project and it works! Here is how it is done.

Parts:

  1. Raspberry Pi 1 (like very old)

  2. DS18B20 temperature probe (can get from Amazon)

  3. A 433MHz remote control power plug, like this one:
  4. To figure out the transmit and receive codes from the remote you need to buy a set of these and follow the instructions from here:: https://www.instructables.com/RF-433-MHZ-Raspberry-Pi/

  5. You need to hook up the temperature probe to work with the Pi. This site is a good start:

    https://medium.com/initial-state/how-to-build-a-raspberry-pi-temperature-monitor-8c2f70acaea9

  6. You’ll need the following items to build this solution:
    -DSB18B20 Temperature Sensor
    -10K Resistor [Pull Up]
    Pi
    [Wiring]:
    Pin 1 - 3.3v [RED]
    Pin 7 - GPIO4 - signal [Yellow]
    Pin 9 - GND [BLK]

    sudo raspi-config
    [enable 1-wire system]
    [reboot]
    sudo nano /boot/config.txt
    [If the following line is not already in this file (if it is, it is likely at the bottom of the file), add it and save the file. This is for GPIO 4]
    dtoverlay=w1-gpio,gpiopin=4
    [reboot]
    sudo reboot

  7. [To start the temperature sensor read interface we need to run two commands]:
    $ sudo modprobe w1-gpio
    $ sudo modprobe w1-therm
    [The output of your temperature sensor is in]:
    $ ls /sys/bus/w1/devices
    [In this directory, there will be a sub-directory that starts with “28-“. ]

  8. The Bash shell file that does the whole thing is called taketemp.sh:

    [you might need to add the bc command to bash if this doesn't run]
    sudo apt update
    sudo apt install bc

    [taketemp.sh]
    #!/bin/bash
    modprobe w1-gpio
    SERVERLOC=192.168.9.3
    SERIALNUMBER=$(ls /sys/bus/w1/devices/w1_bus_master1/ | grep 28)
    tempC=$(cat /sys/bus/w1/devices/w1_bus_master1/$SERIALNUMBER/w1_slave | grep 't=' | awk -F= '{$2 = $2 / 1000; print $2}')
    #tempF=`echo "scale=4; $tempC*1.8 + 32" | bc`
    echo $tempC > tempC.txt

  9. [run it every 5 minutes]
    crontab -e
    */5 /home/pi/taketemp.sh

  10. I run another shell script to turn the fridge on and off. I named this file fridge.sh and it runs every 30 minutes.

    #!/bin/bash
    hightemp=8.0
    lowtemp=2.0
    read tempC < tempC.txt
    if (( $(echo "$tempC > $hightemp" | bc) ))
    then
         echo "$tempC is greater than $hightemp"
         ./turnon.sh
         ./turnon.sh
         ./turnon.sh
    elif (( $(echo "$tempC < $lowtemp" | bc) ))
    then
         echo "$tempC is less than $lowtemp"
         ./turnoff.sh
         ./turnoff.sh
         ./turnoff.sh
    else
         echo "Temperature is $tempC"
    fi
     

    That's it! It works!

    I also want to mention that I had attempted to use a Pico W in place of the Raspberry Pi without any luck. The problem is the rpi-rf library. I haven't found any specific library for the Pico W yet. Not even Chat-GPT can help me! Let me know if you have any luck with that.

    I also attempted to use a WiFi power plug instead of the 433MHz power plug, and again no luck. Apparently a more expensive WiFi plug would allow you to work with your own device by revealing all the integration codes you will need. I only tried the Globe Smart Plug and their technical help was not helpful at all. All the best!

Comments