const int voltageSensorPin = 1; // Pin for the voltage sensor
float sensorReading; // Analog reading from the voltage sensor
const float maxAdcCount = 4095.0; // Maximum ADC count (assuming 12-bit ADC)
float voltageValue; // Calculated voltage based on sensor reading
const float lowVoltageThreshold = 3.0; // Threshold for low voltage
//Pin for Voltage sensor can be the reg_out_sns pin in battery booster
#include "DHT.h"
#define DHTTYPE 22
const int DHTPin = 3; // Pin for the DHT sensor
float temperature;
float humidity;
DHT DHTObject(DHTPin, DHTTYPE);
void reactToTemperature(float temp) {
if (temp < 0) {
Serial.println("Alert! Low Temperature");
} else if (temp > 65) {
Serial.println("Alert! High Temperature");
}
}
void reactToLowVoltage() {
Serial.println("Alert! Low Voltage");
}
void reactToHumidity(float hum) {
if (hum > 75) {
Serial.println("Alert! High Humidity");
}
}
void setup() {
Serial.begin(115200);
Serial.println("Hello World");
DHTObject.begin();
pinMode(voltageSensorPin, INPUT); // Set the pinMode for the voltage sensor pin to INPUT
}
void loop() {
Serial.println("--------------------------------------");
// Read analog voltage from the voltage sensor
sensorReading = analogRead(voltageSensorPin);
// Convert analog reading to voltage value
voltageValue = (sensorReading / maxAdcCount) * 3.3 * 2;
// Check if the voltage is below the low voltage threshold
if (voltageValue < lowVoltageThreshold) {
reactToLowVoltage();
} else {
Serial.print("Voltage is: ");
Serial.print(voltageValue);
Serial.println(" V");
}
humidity = DHTObject.readHumidity();
temperature = DHTObject.readTemperature();
Serial.print("Temperature is: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity is : ");
Serial.print(humidity);
Serial.println(" %");
reactToTemperature(temperature);
reactToHumidity(humidity);
Serial.println("--------------------------------------");
Serial.println();
Serial.println();
delay(500);
}