I have 12V adapter powering the relay, both 5V connected to 5V on RPi, and both ground on relay connected to GND on RPi.
So far I am only connecting one temperature probe on channel 1 on the relay to the GPIO 20 (RPi), but when I tried to read the temperature on RPi, it will not detect the probe.
On the terminal I did:
Code: Select all
sudo nano /boot/config.txt
Code: Select all
dtoverlay=w1-gpio
Saved and exit, then:
Code: Select all
sudo reboot
Code: Select all
sudo modprobe w1-gpio
sudo modprobe w1-therm
cd /sys/bus/w1/devices
ls
It worked find when I connected the probe directly to the RPi and I could get the temperature reading and all.


And I also tried this python code:
Code: Select all
import os
import glob
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
relay=20
GPIO.setup(20,GPIO.OUT)
GPIO.output(20, GPIO.HIGH)
print "Relay should be off"
base_dir = "/sys/bus/w1/devices/"
device_folder = glob.glob(base_dir + "28*")[0]
device_file = device_folder + "/w1_slave"
def read_temp_raw():
f = open(device_file, "r")
lines = f.readlines()
f.close()
return lines
def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != "YES":
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find("t=")
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
return temp_c,
while True:
result = (read_temp())
if (result <= 24):
GPIO.output(relay, GPIO.HIGH)
Print "Relay should be off"
else:
GPIO.output(relay, GPIO.LOW)
Print "Relay should be on"
time.sleep(5)
Can you all help me check what's wrong? I am suspecting maybe I connected wrong on the probe and relay, or I need to somehow call RPi to read the device on channel 1 of the relay (GPIO 20) but I don't know how.
Any advice would be appreciated!