Hi all, my first project here. Quite confused but learning. I got 2 questions
-
When I plug my DHT22 to my Nano (GND to GND, VCC to 5V pin, DAT to Pin2) everything is fine. But if I try to switch the power suppler to my DHT22 from my MB102 that is connected to the breadboard, It can't read the data anymore. What's wrong there ?
I'm using a basic library for DHT22 readings. -
I added a simple if / else statement to power on or off a 5 v relay according to the humidity reading. It seems that the output from my Pin3 to the S of the relay isn't strong enough i.e. the ''on'' led on the relay module is only dimly lit and no click (whereas if I connect the S to the 5V on the arduino it's working fine).
I read that I need to get a resistor to amplify the I/O output ? is that correct ?
Also I can't seem to power the + and - of the relay module from the MB102 as previously stated for the DHT sensor
Thanks !
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define RELAY_PIN_3 3 // humidity relay
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
Serial.begin(9600);
// Initialize device.
dht.begin();
Serial.println(F("DHTxx Unified Sensor Example"));
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.println(F("Temperature Sensor"));
Serial.print(F("Sensor Type: "));
Serial.println(sensor.name);
Serial.print(F("Driver Ver: "));
Serial.println(sensor.version);
Serial.print(F("Unique ID: "));
Serial.println(sensor.sensor_id);
Serial.print(F("Max Value: "));
Serial.print(sensor.max_value);
Serial.println(F("°C"));
Serial.print(F("Min Value: "));
Serial.print(sensor.min_value);
Serial.println(F("°C"));
Serial.print(F("Resolution: "));
Serial.print(sensor.resolution);
Serial.println(F("°C"));
Serial.println(F("------------------------------------"));
// Print humidity sensor details.
dht.humidity().getSensor(&sensor);
Serial.println(F("Humidity Sensor"));
Serial.print(F("Sensor Type: "));
Serial.println(sensor.name);
Serial.print(F("Driver Ver: "));
Serial.println(sensor.version);
Serial.print(F("Unique ID: "));
Serial.println(sensor.sensor_id);
Serial.print(F("Max Value: "));
Serial.print(sensor.max_value);
Serial.println(F("%"));
Serial.print(F("Min Value: "));
Serial.print(sensor.min_value);
Serial.println(F("%"));
Serial.print(F("Resolution: "));
Serial.print(sensor.resolution);
Serial.println(F("%"));
Serial.println(F("------------------------------------"));
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
}
void loop() {
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
} else {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
} else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
}
if (event.relative_humidity < 80) {
digitalWrite(RELAY_PIN_3, HIGH); // Turn on relay 2
} else {
digitalWrite(RELAY_PIN_3, LOW); // Turn off relay 2
}
}






