8 channel relay not working like expected

First off, Hey guys. I have a had search & alot of the time the answer to my problem appears to be 'common ground' I tired this. For whatever reason if I put the relay & the DHT22 board both on the Arduino 5v the DHT won't work. I tried powering the DHT via the power supply...that didn't work.

The Humidifer will either turn on & stay on, or not turn at all.

I've tried a bunch of things all night, can't get it to work, probably something simple, but i'm too dumb to understand.

Thanks guys,

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Temp Hum"
  https://create.arduino.cc/cloud/things/7caf35c3-13fd-429d-af66-89069e0e48e2 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudRelativeHumidity humidity;
  CloudTemperature temperature;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <DHT.h>
#define DHTpin 7
#define DHTTYPE DHT22
#define Humidifier 12

DHT dht(DHTpin,DHTTYPE);


void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  dht.begin();
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  float Humidity = dht.readHumidity();
  float Temperature = dht.readTemperature();
  
  Serial.print("Temperature");
  Serial.print(Temperature);
  delay(2000);
  Serial.print("Humidity");
  Serial.print(Humidity);
  delay(2000);

  humidity=Humidity;
  temperature=Temperature;

  if(Humidity<75){
    digitalWrite(Humidifier,HIGH);
  }else
  {
    digitalWrite(Humidifier,LOW);
  }

}

Hi @infineite ,

Welcome to the forum..
hmm.. the barrel connector needs more than 5vdc, this hits a regulator..
Probably need 6-7 vdc for it..
If you do have a regulated 5vdc supply and you are using a 5vdc board like uno, then go directly to the 5vdc pin..

good luck.. ~q

You don't mention which relay board you exactly have and it can be important.

But have a look at the wiring diagram in the image in this post: Relay module effecting Arduino

PS
You seem to have duplicated your code in your post? Please try to clean it up.

Thanks for that! its a 5v 'wall wart'. I'll wire it directly into the Arduino via the 'Vin'.

The Relay I have is

The page you recommanded is why I have the 3.33 to the relay. I did try the 5v but when I put both the relay & DHT22 (Below), I can't get either to work. Should I wire the DHT22 to 3.3 & the relay to the 5v? Can I power the DHT22 via the 5v external power supply?

Thanks for you're help, I edited the post to remove the double posted code.

which board..
on an uno from the website..

Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-20V

Vin is same as barrel, if you have a regulated 5vdc supply hit the 5v pin directly..

~q

Oh, sorry, I have the Uno R4 Wifi

This is the 'Wall wart'

that list as..

Input voltage (VIN) 6-24 V

but there is also the esp32 in there that needs 3.3, not sure if hitting the 5v pin will also get you the 3.3..
could try it and see, don't think it would damage anything, just won;t get wifi if the esp32 isn't powered up..
~q

The Arduino its self gets power, connects to wifi via the 'wall wart'.
But yea...I messed up. it needs more than 5v. Happy to connect via the USB c

it might, you're putting 5vdc into VIN, this gets regulated and there will be a small voltage drop..
if you have a meter probe the 5v pin, bet you it's like 4.7 or maybe less..
~q

just checked the schem..
you can just hit the 5v pin with you adapter, the 3.3v regulator is after the buck converter so all will work..
or like you say use the usb..

good luck.. ~q

Cool, I think that might answer my Q with why I can't put 2 things into the 5v pin. I have a 3 amp USB C, connected it. I can't read the DHT22, have I now created a 'common ground' issue as I have 2 different power supplies?

Thanks

What happens when only the DHT22 is hooked up??
~q

  • As always, show us a good schematic of your proposed circuit. Hand drawn schematics are acceptable.
  • Show us good images of your ‘actual’ wiring.

I unplugged the relay (pin 12) & the 3.3 volt...The DHT22 works

Good, now let's see how the relay module is hooked up..
Do you have an 8 ch or 4 ch??
As @LarryD has pointed out, a better schem, maybe some pics of relay module and we can all give some suggestions..
But there should be nothing hooked up to the 3.3, that's for sure..

Probably need to take that jumper off the relay module and feed it there..

Getting late for me, so might doze off, sorry..

~q

This is the relay i bought.

Ok...I might have an issue with the cable I made for the DHT22. Its about 3m long. It works...then doesn't. Its all soldered together. The standard jumper cables work fine.... Is it a length issue or did I make the cable badly?

Thanks for your help..Its nearly bed time for me also 8 am here = D

I suggest you get a ESP32S3 board to prototype with. If you toast a low cost board your out of pocket cost is <$5

Looks like you are powering the DHT at 3.3v..
This will reduce greatly how long the cable can be..
Might try some Cat5 network cable..
Use one pair for vcc and another pair for ground and data..
Lower impedance cable may do the trick and you really don't want any joints..
Could also power the dht at 5v and get a logic level conveter 5 to 3.3, could also use this for the relay too..
Work on each piece separately and make sure it functions properly before moving to the next..

pretty sure i've used that relay module too..

~q