Good morning all! I’m going to start off by saying thanks for the help. A little background of the project: I have a tortoise and want to set up a controller to monitor temps, humidity, control the lights/warmers and the misting pump with the possibility to expand if needed. So I arrived at the Arduino. I’ve got the code started but still have to work on the menu functionality and such. My real question is relays. I understand the basic functionality of a relay, I’m just not sure how to calculate and wire what I need. I have this IoT relay: IoT Relay Frequently Asked Questions - FAQs. This particular relay is controllable but not each individual plug, which I believe I need as one heat lamp stays on 24/7 and the other lamp runs 12hrs a day and the heat pad kicks on when temps fall below 73*.
So I’m here to try and figure out how to use a 4 module relay bank instead of using the IoT relay.
I understand there’s a power and ground and a control wire into the relay. But how does the relay get the required 120v? Does it come from the Arduino? Or do I need to provide power for the relays via a different circuit?
The specs for the 4 module relay module is below:
4 Channel SOLID-STATE ELECTRONICS MODULES
Power supply voltage:5V 12V
Trigger:high level trigger/low level trigger
Static voltage:0 mA Load voltage:AC:250V/10A DC:30V/10A
Maximum working current:79.6mA module life:10 million times
The ad states It has an optocoupler, if that helps. I believe they are knock offs of the “songle” relays. Anywho, if I understand things correctly, I would need to have a 120v source coming into the relay for power, but where do the wires from the relay to the lamps/heating pad go? Maybe I’m overthinking how things are wired but I really don’t want to screw anything up. Any and all help would be appreciated.
Below is my code I’ve written this far, again not complete but I believe the basic functions are there.
‘’’
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <RTClib.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#define DHTPIN1 2 // Pin for DHT sensor 1
#define DHTPIN2 3 // Pin for DHT sensor 2
#define DHTTYPE DHT22 // DHT sensor type
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
#define RELAY_PIN 4 // Pin for IoT relay
#define PUMP_PIN 5 // Pin for water pump
#define HEATING_PAD_PIN 6 // Pin for heating pad
#define BASKING_LAMP_PIN 7 // Pin for basking lamp
#define DAY_NIGHT_LAMP_PIN 8 // Pin for day/night lamp
#define HUMIDITY_THRESHOLD 40 // Humidity threshold for misters to turn on
#define TEMP_THRESHOLD 73 // Temperature threshold for heating pad to turn on
#define JOYSTICK_X A0 // Pin for joystick X axis
#define JOYSTICK_Y A1 // Pin for joystick Y axis
#define JOYSTICK_BUTTON 9 // Pin for joystick button
#define SCREEN_RS 10 // Pin for LCD screen RS
#define SCREEN_EN 11 // Pin for LCD screen EN
#define SCREEN_D4 12 // Pin for LCD screen D4
#define SCREEN_D5 13 // Pin for LCD screen D5
#define SCREEN_D6 A2 // Pin for LCD screen D6
#define SCREEN_D7 A3 // Pin for LCD screen D7
LiquidCrystal lcd(SCREEN_RS, SCREEN_EN, SCREEN_D4, SCREEN_D5, SCREEN_D6, SCREEN_D7);
RTC_DS3231 rtc;
Adafruit_VC0706 cam = Adafruit_VC0706(&Serial);
void setup() {
Serial.begin(9600);
dht1.begin();
dht2.begin();
pinMode(RELAY_PIN, OUTPUT);
pinMode(PUMP_PIN, OUTPUT);
pinMode(HEATING_PAD_PIN, OUTPUT);
pinMode(BASKING_LAMP_PIN, OUTPUT);
pinMode(DAY_NIGHT_LAMP_PIN, OUTPUT);
pinMode(JOYSTICK_X, INPUT);
pinMode(JOYSTICK_Y, INPUT);
pinMode(JOYSTICK_BUTTON, INPUT_PULLUP);
lcd.begin(16, 2);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!SD.begin(4)) {
Serial.println("SD Card initialization failed!");
return;
}
if (!cam.begin()) {
Serial.println("Failed to start camera!");
return;
}
// Initialize camera
cam.setImageSize(VC0706_640x480); // Set image size
cam.setCompression(95); // Set JPEG quality
}
void loop() {
// Read sensor data
float humidity1 = dht1.readHumidity();
float humidity2 = dht2.readHumidity();
float temp1 = dht1.readTemperature(true);
float temp2 = dht2.readTemperature(true);
// Check if any sensor reading failed
if (isnan(humidity1) || isnan(temp1) || isnan(humidity2) || isnan(temp2)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Control misters
if (humidity1 < HUMIDITY_THRESHOLD && humidity2 < HUMIDITY_THRESHOLD) {
digitalWrite(PUMP_PIN, HIGH); // Turn on misters
delay(30000); // Run pump for 30 seconds
digitalWrite(PUMP_PIN, LOW); // Turn off misters
delay(600000); // Wait for 10 minutes before next activation
}
// Control heating pad
if (temp1 < TEMP_THRESHOLD || temp2 < TEMP_THRESHOLD) {
digitalWrite(HEATING_PAD_PIN, HIGH); // Turn on heating pad
} else {
digitalWrite(HEATING_PAD_PIN, LOW); // Turn off heating pad
}
// Control day/night lamp
int hour = rtc.now().hour(); // Get current hour from RTC
if (hour >= 7 && hour < 19) {
digitalWrite(DAY_NIGHT_LAMP_PIN, HIGH); // Turn on day lamp
} else {
digitalWrite(DAY_NIGHT_LAMP_PIN, LOW); // Turn off day lamp
}
// Control basking lamp
digitalWrite(BASKING_LAMP_PIN, HIGH); // Always keep basking lamp on
// Display data on LCD screen
displayData(temp1, temp2, humidity1, humidity2);
// Handle joystick menu
handleMenu();
}
void displayData(float temp1, float temp2, float humidity1, float humidity2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp 1: ");
lcd.print(temp1);
lcd.print(" C ");
lcd.setCursor(0, 1);
lcd.print("Humidity 1: ");
lcd.print(humidity1);
lcd.print("%");
delay(2000); // Delay to stabilize display
}
void handleMenu() {
int xVal = analogRead(JOYSTICK_X);
int yVal = analogRead(JOYSTICK_Y);
int buttonState = digitalRead(JOYSTICK_BUTTON);
// Your menu logic here
}
‘’’