0

I'd like to trigger my relay to turn on my lamp when the humidity level measured is greater than 85. Here's the code I've been using.

import Adafruit_DHT
import RPi.GPIO as GPIO
import time

sensor = Adafruit_DHT.DHT11

gpio.setmode(gpio.BOARD)
gpio.setup(26, gpio.OUT)

print("Lendo os valores de temperatura e umidade");

while(1):
   umid, temp = Adafruit_DHT.read_retry(11, 4);

   if umid is not None and temp is not None:
     print ("Temperatura = {0:0.1f}  Umidade = {1:0.1f}n").format(temp, umid);
     print ("Aguarda 2 segundos para efetuar nova leitura...n");
     time.sleep(2)

     if umid >= 86:

       gpio.output(26, 1)
       time.sleep(2)
       gpio.output(26, 0)

   else:

     print("Falha ao ler dados do DHT11 !!!")

I'm getting smalls pulses but not enough to trigger the relay. What should I do? Thanks in advance.

PS: all the pins are correctly connected.

3
  • Could you explain what you mean by "I'm getting smalls pulses but not enough to trigger the relay."
    – joan
    Nov 28 '18 at 12:47
  • The GPIO pins probably will be unable to supply enough current for the relay coil. The coil can also damage the Pi when the stored field energy is released back through the circuit... Please update your question with the precise electrical circuit used to activate the relay as well as the relay specifications. Nov 28 '18 at 13:52
  • What is the part number of the relay/relay module? If there is no diode built in then you will have major issues.
    – justinjt
    Feb 27 '20 at 8:17
0

Are you able to read temperature and humidity?

Try this: Adafruit_DHT.read_retry(sensor, 4)

When you connect LED diode instead of relay, will it light?

Do you have 3V or 5V relay?

1
  • Please don't ask questions in an answer.
    – Ingo
    Feb 26 '20 at 20:56
0

You need a transistor between the raspberry pi and the relay. Use a reverse bias diode accross the relay coil. Try connecting the relay to 5v. If it's not too beefy the current consumption and voltage dropout should be such that the pi doesn't shutdown and reboot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.