#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// WiFi credentials (not used in simulation)
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
// Define sensor pins
#define VOLTAGE_PIN 34
#define CURRENT_PIN 35
#define TEMP_PIN 14 // DS18B20 data pin connected to GPIO 14
#define RELAY_PIN 13
// Voltage divider constants
const float R1 = 10000.0; // 10kΩ
const float R2 = 1600.0; // 1.6kΩ
// DS18B20 setup
OneWire oneWire(TEMP_PIN);
DallasTemperature sensors(&oneWire);
// Thresholds for warnings
const float VOLTAGE_THRESHOLD = 12.0; // Example threshold
const float CURRENT_THRESHOLD = 5.0; // Example threshold
const float TEMP_THRESHOLD = 40.0; // Example threshold
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // Initially off
sensors.begin();
}
void sendSensorData() {
// Read voltage
int voltageRaw = analogRead(VOLTAGE_PIN);
float voltage = voltageRaw * (3.3 / 4095.0) * ((R1 + R2) / R2);
// Simulate current using potentiometer
int currentRaw = analogRead(CURRENT_PIN);
float current = currentRaw * (3.3 / 4095.0); // Simulated current value
// Read temperature from DS18B20
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
// Check for warnings
if (voltage > VOLTAGE_THRESHOLD) {
Serial.println("High Voltage");
}
if (current > CURRENT_THRESHOLD) {
Serial.println("High Current");
}
if (temperature > TEMP_THRESHOLD) {
Serial.println("High Temperature");
}
// Control relay based on conditions (not implemented in this example)
}
void loop() {
sendSensorData();
delay(1000); // Send data every second
}