/* ----------------------- Macros -------------------- */
#define GREEN_LED 23
#define POT 36
/* ------------------- Initialization ---------------- */
void setup() {
Serial.begin(115200); // Initialize the serial connection
Serial.println("Hello, ESP32!"); // Print on Serial Monitor "Hello, ESP32" to check its working status
pinMode(GREEN_LED, OUTPUT); // Initialize LED as output (ESP: Sets GPIO 23 as Output)
pinMode(POT, INPUT); // Initialize Potentiometer as input (ESP: Sets GPIO 36 as Input)
Serial.println("-------- Initialization is done --------"); //Show the end of initialization (ESP: Sends message to serial monitor)
}
/* ------------------ Program Execution ---------------*/
void loop() {
int PotValue = analogRead(POT); // read the sensor reading (ESP: Get the value of 12-bit ADC)
float PotFloatValue = PotValue * 5.0 / 4096; // Convert the reading to value between 0 and 5
Serial.println("Voltage Value:"); // print reading of ADC
Serial.println(PotValue);
Serial.println("Analog Value:"); // print value after calibration
Serial.println(PotFloatValue);
/* Decision: IF Potfloatvalue less than 3.5 turn on led else turn off led */
if(PotFloatValue<3.5){
/* Turn on the Green LED process */
digitalWrite(GREEN_LED, HIGH); // Turn on the LED by setting GPIO 23 to HIGH (ESP: Sends 5V to the LED to power it on).
Serial.println("LED is ON"); // Show on Monitor that is turned on (ESP: Sends message to serial monitor)
} else {
/* Turn off the Green LED process */
digitalWrite(GREEN_LED, LOW); // Turn off the LED by setting GPIO 23 to LOW (ESP: Sends 0V to the LED to power it off).
Serial.println("LED is OFF"); // Show on Monitor that is turned off (ESP: Sends message to serial monitor)
}
}