Python Forum
sensor code that starts heater
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sensor code that starts heater
#1
Hello,
i want to start the heater with the sensor, when the temperature is 0 dеgrees the heater start when the temperature becomes +3 degree heater stop.is it possible?
Can you tell me whats the sensor to buy and how i switch it in raspberry.I have relays 10A the heater is 1000w.
Thank you
Reply
#2
Hi, check this out:
https://github.com/szazo/DHT11_Python
As you can see in the example code, the "signal" pin is connected to pin 14 of raspberry pi.
The DHT11 has 3 pins though, the GND pin should be connected to GND, and VCC can be either connected to 3.3V or 5V (according to ebay description of the module).

The sensor:
https://www.ebay.co.uk/itm/DHT11-Tempera...2527049987
Reply
#3
(Jun-04-2019, 02:36 PM)michalmonday Wrote: Hi, check this out:
https://github.com/szazo/DHT11_Python
As you can see in the example code, the "signal" pin is connected to pin 14 of raspberry pi.
The DHT11 has 3 pins though, the GND pin should be connected to GND, and VCC can be either connected to 3.3V or 5V (according to ebay description of the module).

The sensor:
https://www.ebay.co.uk/itm/DHT11-Tempera...2527049987


I did not understand anything,where i put the dagrees?
Reply
#4
So the DHT11 is the sensor you could use. That's it:

[Image: 2MShDqG.jpg]

It has 3 metal pins. VCC, signal and GND. VCC and GND pins are used solely for powering the sensor. Signal pin is used to actually receive information about temperature from it.

Here's a pinout of the raspberry pi:

[Image: raspberry-pi-15b.jpg]

So the 3 metal pins from the sensor should be connected to the appropriate metal pins on the raspberry pi.
VCC of the sensor -> any of the 3.3V or 5V pins of Raspberry Pi
GND of the sensor -> any of the GND pins of RPi
Signal pin of the sensor -> GPIO 14 of RPi

After connecting it this way you can get the temperature from the sensor by manipulating pin 14 of the Raspberry Pi which is done by the library I mentioned. In this example code it is shown how it can be done:
import RPi.GPIO as GPIO
import dht11
import time
import datetime

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

# read data using pin 14
instance = dht11.DHT11(pin=14)

while True:
    result = instance.read()
    if result.is_valid():
        print("Last valid input: " + str(datetime.datetime.now()))
        print("Temperature: %d C" % result.temperature)
        print("Humidity: %d %%" % result.humidity)

    time.sleep(1)

Notice that it imports dht11, so you need to download and put the dht11.py in the same folder as your main python file will be or put it in the python/Lib/site-packages/ folder.

Here's example of what your code could look like (I didn't test it though because I don't have that sensor).

import RPi.GPIO as GPIO
import dht11
import time

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

# read data using pin 14
instance = dht11.DHT11(pin=14)

# pin 4 will be used to control the relay
relay_pin = 4
GPIO.setup(relay_pin, GPIO.OUT)

ON = 1
OFF = 0

def switch_relay(state):
    '''You may want to invert state here if your relay is normally high
    when its' input pin is low.'''
    GPIO.output(relay_pin, state)

while True:
    result = instance.read()
    if result.is_valid():
        if result.temperature <= 0: 
            switch_relay(ON)
        elif result.temperature >= 3:
            switch_relay(OFF)
            
    time.sleep(1)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Move column to the right if it starts with a letter mfernandes 0 681 Oct-25-2022, 11:22 AM
Last Post: mfernandes
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,824 Feb-18-2022, 01:29 PM
Last Post: pstein
  Regex: a string does not starts and ends with the same character Melcu54 5 2,432 Jul-04-2021, 07:51 PM
Last Post: Melcu54
  Code starts slowing down? MemoryError AshkanDev 1 2,158 May-19-2020, 11:38 PM
Last Post: AshkanDev
  Run a timer when a functions starts to see how long the function takes to complete Pedroski55 2 2,017 Apr-19-2020, 06:28 AM
Last Post: Pedroski55
  Code Wireless Temperature sensor and send sensor readings to google sheet jenkins43 0 2,198 Nov-29-2018, 12:44 PM
Last Post: jenkins43
  need help with ultrasonic sensor code mpmm366 6 4,022 Jun-28-2018, 08:41 PM
Last Post: gontajones
  RPi with IR Sensor pimlicosnail 1 2,202 Jun-24-2018, 08:53 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020