Tortoise vivarium controller

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
}

‘’’

Typical opto isolated relay.

If you are messing with line voltages get qualified help. It may even be the law.

I will look at the code once it is formatted and posted properly. >>>>> How to get the best out of this forum

1 Like

You're going to want to change this in a project that has the Arduino monitoring and doing more than one thing. When you use delay(600000) for example, the Arduino will be stuck there for 10 minutes and can do nothing else at all, potentially missing other important events like temperature or such.
I would think about adding an RTC into a project like this and using that real time clock for all your timing. They're only a couple of bucks and pretty easy to incorporate into projects like these.
EDIT: just noticed you DO use an RTC in this project (can you please repost your code using code tags?) and yeah, ditch the delay() and just use the RTC. There's no need for delay() if you have one.

or consider using a product such as

https://www.adafruit.com/product/2935

which makes switching AC loads a breeze with Arduino.

Bookmarked, thanks.

1 Like

I actually bought that because I thought it was going to work but I’m not sure it will. 3 of the 4 plugs are switched at the same time. It’ll work for the lamp switching on and off but other than that I can’t plug other things in the switched sockets as it’ll mess up the lamp by switching it on and off for the misters or what not that’s plugged in as well. Unless I’m misunderstanding how it works. I guess I could just buy another one? That would prolly make this whole thing a lot easier I believe and they’re relatively cheapish.

So when I replace the “delays” do I need to call in the rtc instead to check/monitor the time delays?

Depends on your needs. You have Always On, Normally On, two Normally Off and one Arduino signal input.
Or, yeah, buy another one if that's the best solution for you.

Well you'd have Arduino note the time of the event, then make a future time based on some math added into now, as long as you Have Arduino monitoring the time throughout the sketch, if performs some action once the future time is reached.

Alternatively, you could use the millis() function to do what you were doing with those delay() calls.

Yes. I would however stick with the RTC even if your source of power is uninterruptible.

It's not too hard to use as has been said, and a combination of using millis() based timing and real time from the RTC can be effective.

Like "start a 30 second misting" at 12:42 PM. Clock to start it, millis() for noticing that thirty seconds has gone by since starting kinda thing.

Search these fora, ppl alla time want to turn things on and off based on time of day.

Here's one thread

HTH

a7

1 Like

Post a link to the datasheet or brand name and exact part number or the seller's web page.

So, I decided to do away with the mains and SSR module as I didn't feel comfortable playing with invisible death. So I bought another IoT relay for this project, which is fine with me, it simplifies it. But I've added some things to the code including LED's for a visual sign things are working. I also realized I hate the heater pad and 12hr lamp called out as well as the relays, since I only need to the relays to kick on when the temp/humidity falls below certain parameters, I took those out. I wanted the menu to change between the different parameters and I think? I have that worked out. I also changed the joystick out for 3 buttons, up, down, and enter. I also added a buzzed for sound if something is out of whack. The code is below of what I have now. It all verifies on the IDE program. I should be getting my second dht22 sensor today, I had to buy a replacement as my other one fails to read anything. The thing I'm not sure how to do is create a menu, I'm not sure if I really need a menu or not so I'm open to suggestions. ideally I'd want this to be as simple as possible and my thoughts are if the LCD blinks through various temps/humidity, water pump run time and frequency would be ideal, and SD card storage also ideal. The SD card is just for monitoring the data. I have a calibrated sensor I'm going to keep in the vivarium to compare temp and humidity readings, as I believe I can change some parameters to make the DHT more accurate, correct me if I'm wrong please. What do you all think? I hope I attached the code correctly, I clicked the little button.

`
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <RTClib.h>
#include <SD.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_1 4 // Pin for IoT relay 1
#define RELAY_PIN_2 5 // Pin for IoT relay 2
#define PUMP_PIN 6 // Pin for water pump

#define GREEN_LED_PIN 7 // Pin for green LED
#define BLUE_LED_PIN 8 // Pin for blue LED
#define RED_LED_PIN 9 // Pin for red LED
#define BUZZER_PIN 10 // Pin for buzzer

#define MENU_BUTTON_UP_PIN A0 // Pin for menu button UP
#define MENU_BUTTON_DOWN_PIN A1 // Pin for menu button DOWN
#define MENU_BUTTON_ENTER_PIN A2 // Pin for menu button ENTER

#define SCREEN_RS 13 // Pin for LCD screen RS
#define SCREEN_EN 12 // Pin for LCD screen EN
#define SCREEN_D4 5 // Pin for LCD screen D4
#define SCREEN_D5 6 // Pin for LCD screen D5
#define SCREEN_D6 7 // Pin for LCD screen D6
#define SCREEN_D7 8 // Pin for LCD screen D7
//#define TOUCH_PIN 2 // Pin for LCD touch

LiquidCrystal lcd(SCREEN_RS, SCREEN_EN, SCREEN_D4, SCREEN_D5, SCREEN_D6, SCREEN_D7);
RTC_DS3231 rtc;

unsigned long previousMillis = 0;
const long interval = 43200000; // 12 hours in milliseconds

void setup() {
Serial.begin(9600);
dht1.begin();
dht2.begin();
pinMode(RELAY_PIN_1, OUTPUT);
pinMode(RELAY_PIN_2, OUTPUT);
pinMode(PUMP_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(BLUE_LED_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(MENU_BUTTON_UP_PIN, INPUT_PULLUP);
pinMode(MENU_BUTTON_DOWN_PIN, INPUT_PULLUP);
pinMode(MENU_BUTTON_ENTER_PIN, INPUT_PULLUP);
lcd.begin(16, 2);
rtc.begin();
if (!SD.begin(10)) {
Serial.println("SD Card initialization failed!");
return;
}
}

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;
}

// Check temperature and humidity thresholds
checkThresholds(temp1, temp2, humidity1, humidity2);

// Control IoT relay 1 (for lamp)
controlRelay(RELAY_PIN_1);

// Control IoT relay 2 (for heating pad)
controlRelay(RELAY_PIN_2);

// Control water pump
controlWaterPump();

// Display data on LCD screen
displayData(temp1, temp2, humidity1, humidity2);

// Menu navigation
handleMenu();
}

void checkThresholds(float temp1, float temp2, float humidity1, float humidity2) {
// Check temperature thresholds
if (temp1 < 75 || temp2 < 75 || temp1 > 90 || temp2 > 90) {
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
} else {
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
}

// Check humidity thresholds
if (humidity1 < 40 || humidity2 < 40 || humidity1 > 60 || humidity2 > 60) {
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
} else {
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
}
}

void controlRelay(int pin) {
int hour = rtc.now().hour(); // Get current hour from RTC
if ((hour % 12) < 6) {
digitalWrite(pin, HIGH); // Turn on relay for 12 hours
digitalWrite(GREEN_LED_PIN, HIGH); // Turn on green LED when relay is active
} else {
digitalWrite(pin, LOW); // Turn off relay for 12 hours
digitalWrite(GREEN_LED_PIN, LOW); // Turn off green LED when relay is inactive
}
}

void controlWaterPump() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 3000) {
digitalWrite(PUMP_PIN, HIGH); // Turn on water pump for 3 seconds
digitalWrite(BLUE_LED_PIN, HIGH); // Turn on blue LED when water pump is active
delay(3000);
digitalWrite(PUMP_PIN, LOW); // Turn off water pump
digitalWrite(BLUE_LED_PIN, LOW); // Turn off blue LED when water pump is inactive
previousMillis = currentMillis;
}
}

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("%");

lcd.setCursor(10, 0);
lcd.print("Temp 2: ");
lcd.print(temp2);
lcd.print(" C ");
lcd.setCursor(10, 1);
lcd.print("Humidity 2: ");
lcd.print(humidity2);
lcd.print("%");

lcd.setCursor(0, 0);
//lcd.print(rtc.now().toString()); commented out this line to get code to work
}

void handleMenu() {
// Your menu logic here
}
`

Something to consider is the DHT 22 you are using. Some are complete modules which include a pullup resistor while others require an external pullup resistor between Data Line and Vcc. Typically a resistance of 4.7 K ohm or 10 K ohm is used. Just something to consider before sending a unit to the trash can. :slight_smile:

Ron

Most certainly not, at least until you have everything else working as intended first. Your tortoise can't read, so think of that as a nice-to-have for you once the other stages are working.
That's sort of my point though: it's far less frustrating trying to troubleshoot smaller projects and adding them together later than it is a large build with many unknowns.

So let's review:
What are the "essential" tasks?
What are the "nice-to-have" tasks?
What have you got working so far, exactly?
What's left after that?

Looks like you tried. Try this different way:

In the IDE use the Auto Format tool.

The in the IDE use the Copy for Forum tool.

Then come back here and just paste. You could paste that all over the not quite correct posting that you just did, no one will notice or care, or just make a barn new post for you sketch.

It should end up

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println("Happy Birthday Mom!");
}

looking like code in its own little grayish box.

BTW does it all function at this time? Is the broken sensor really broken, or was it a matter of not getting the two sensors to get along each other?

a7

interesting, maybe I had a dead resistor? I have a resistor from the 2nd pin to the power source and a wire to the Arduino. pin 1 is going straight to power and pin 3 is going to ground. pin 2 goes to board and has a 10k resistor inline going to power as well.

"essential" tasks- monitor temp and humidity, when out of parameters it needs to actuate a heater pad below 73, actuate a water pump when humidity is below 40%.
"nice to haves" actuate UVB lamp on 12hrs, off 12hrs, time keeping with an RTC.
"what's working so far" is the DHT sensor, only one at the moment as I believe my other is dead. I have some coming in the mail today. They read onto the serial monitor, but haven't got them reading on the LCD screen yet.

"left overs"- SD card logging, menu options.

1 Like

Okay copied for forum from the program. here we go lol.

#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <RTClib.h>
#include <SD.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_1 4 // Pin for IoT relay 1
#define RELAY_PIN_2 5 // Pin for IoT relay 2
#define PUMP_PIN 6 // Pin for water pump

#define GREEN_LED_PIN 7 // Pin for green LED
#define BLUE_LED_PIN 8 // Pin for blue LED
#define RED_LED_PIN 9 // Pin for red LED
#define BUZZER_PIN 10 // Pin for buzzer

#define MENU_BUTTON_UP_PIN A0 // Pin for menu button UP
#define MENU_BUTTON_DOWN_PIN A1 // Pin for menu button DOWN
#define MENU_BUTTON_ENTER_PIN A2 // Pin for menu button ENTER

#define SCREEN_RS 13 // Pin for LCD screen RS
#define SCREEN_EN 12 // Pin for LCD screen EN
#define SCREEN_D4 5 // Pin for LCD screen D4
#define SCREEN_D5 6 // Pin for LCD screen D5
#define SCREEN_D6 7 // Pin for LCD screen D6
#define SCREEN_D7 8 // Pin for LCD screen D7
//#define TOUCH_PIN 2 // Pin for LCD touch

LiquidCrystal lcd(SCREEN_RS, SCREEN_EN, SCREEN_D4, SCREEN_D5, SCREEN_D6, SCREEN_D7);
RTC_DS3231 rtc;

unsigned long previousMillis = 0;
const long interval = 43200000; // 12 hours in milliseconds

void setup() {
  Serial.begin(9600);
  dht1.begin();
  dht2.begin();
  pinMode(RELAY_PIN_1, OUTPUT);
  pinMode(RELAY_PIN_2, OUTPUT);
  pinMode(PUMP_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(BLUE_LED_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(MENU_BUTTON_UP_PIN, INPUT_PULLUP);
  pinMode(MENU_BUTTON_DOWN_PIN, INPUT_PULLUP);
  pinMode(MENU_BUTTON_ENTER_PIN, INPUT_PULLUP);
  lcd.begin(16, 2);
  rtc.begin();
  if (!SD.begin(10)) {
    Serial.println("SD Card initialization failed!");
    return;
  }
}

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;
  }

  // Check temperature and humidity thresholds
  checkThresholds(temp1, temp2, humidity1, humidity2);

  // Control IoT relay 1 (for lamp)
  controlRelay(RELAY_PIN_1);

  // Control IoT relay 2 (for heating pad)
  controlRelay(RELAY_PIN_2);

  // Control water pump
  controlWaterPump();

  // Display data on LCD screen
  displayData(temp1, temp2, humidity1, humidity2);

  // Menu navigation
  handleMenu();
}

void checkThresholds(float temp1, float temp2, float humidity1, float humidity2) {
  // Check temperature thresholds
  if (temp1 < 75 || temp2 < 75 || temp1 > 90 || temp2 > 90) {
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(BUZZER_PIN, HIGH);
  } else {
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
  }

  // Check humidity thresholds
  if (humidity1 < 40 || humidity2 < 40 || humidity1 > 60 || humidity2 > 60) {
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(BUZZER_PIN, HIGH);
  } else {
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
  }
}

void controlRelay(int pin) {
  int hour = rtc.now().hour(); // Get current hour from RTC
  if ((hour % 12) < 6) {
    digitalWrite(pin, HIGH); // Turn on relay for 12 hours
    digitalWrite(GREEN_LED_PIN, HIGH); // Turn on green LED when relay is active
  } else {
    digitalWrite(pin, LOW); // Turn off relay for 12 hours
    digitalWrite(GREEN_LED_PIN, LOW); // Turn off green LED when relay is inactive
  }
}

void controlWaterPump() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= 3000) {
    digitalWrite(PUMP_PIN, HIGH); // Turn on water pump for 3 seconds
    digitalWrite(BLUE_LED_PIN, HIGH); // Turn on blue LED when water pump is active
    delay(3000);
    digitalWrite(PUMP_PIN, LOW); // Turn off water pump
    digitalWrite(BLUE_LED_PIN, LOW); // Turn off blue LED when water pump is inactive
    previousMillis = currentMillis;
  }
}

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("%");

  lcd.setCursor(10, 0);
  lcd.print("Temp 2: ");
  lcd.print(temp2);
  lcd.print(" C  ");
  lcd.setCursor(10, 1);
  lcd.print("Humidity 2: ");
  lcd.print(humidity2);
  lcd.print("%");

  lcd.setCursor(0, 0);
  //lcd.print(rtc.now().toString()); commented out this line to get code to work
}

void handleMenu() {
  // Your menu logic here
}

That's what I was getting at and you have it covered.

Ron

Just reading your code casually now.

In checkThresholds()

  • if the temperature is bad, raise the alarm, otherwise shut it off.

  • if the humidity is bad, raise the same alarm, otherwise shut it off.

So a good humidity will immediately take away the alarm raised over the bad temperature.

Maybe you want (pseudocode here)

reset the alarm no matter it was already.

if the temperature is bad, raise the alarm.

if the humidity is bad, raise the alarm no matter it was already

This lets the bad conditions raise the alarm, but take no responsibility for lowering it.

a7