Rafael Lozano
Published © GPL3+

ESP32 PLC for home and small industries appliances

The ESP-32 PLC is a home and small industry automation solution designed to simplify control and monitoring tasks.

IntermediateWork in progress20 hours2,647
ESP32 PLC for home and small industries appliances

Things used in this project

Hardware components

ESP32
Espressif ESP32
×1

Software apps and online services

Flux.ai
PCBWay

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering

Story

Read more

Code

Arduino code to read the temperature and turn ON/OFF a relay

Arduino
#define ADC_VREF_mV 3300.0 // in millivolt
#define ADC_RESOLUTION 4096.0
#define PIN_LM35 12 // ESP32 pin GPIO12 (ADC0) connected to LM35
#define PIN_RELAY 38 // ESP32 pin GPIO38 connected to relay

void setup() {
  Serial.begin(9600);
  pinMode(PIN_RELAY, OUTPUT);
}

void loop() {
  // read the ADC value from the temperature sensor
  int adcVal = analogRead(PIN_LM35);
  // convert the ADC value to voltage in millivolt
  float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
  // convert the voltage to the temperature in °C
  float tempC = milliVolt / 10;
  // convert the °C to °F
  float tempF = tempC * 9 / 5 + 32;
  // print the temperature in the Serial Monitor:
  Serial.print("Temperature: ");
  Serial.print(tempC); // print the temperature in °C
  Serial.print("°C ~ "); // separator between °C and °F
  Serial.print(tempF); // print the temperature in °F
  Serial.println("°F");
  delay(500);

  // turn on/off the relay based on the temperature
  if (tempC > 25) { // if the temperature is above 25°C
    digitalWrite(PIN_RELAY, HIGH); // turn on the relay
  } else { // if the temperature is below or equal to 25°C
    digitalWrite(PIN_RELAY, LOW); // turn off the relay
  }
}

Credits

Rafael Lozano
1 project • 2 followers
Contact

Comments

Please log in or sign up to comment.