// Servo Sweep example for the ESP32
// https://wokwi.com/arduino/projects/323706614646309460
#include <ESP32Servo.h>
#define temperature 33
Servo mainServo;
int position = 0;
int previousPosition;
void setup() {
pinMode(temperature, INPUT);
mainServo.attach(18);
Serial.begin(9600);
}
void loop() {
// Temperature analysis
int tempReading = analogRead(temperature);
// If using 5v input
float voltage = tempReading * 5.0;
// Divided by 1024
voltage /= 1024.0;
//Converting from 10mv per degree
float tempC = (voltage - 0.5) * 100;
// This maps temperature to degrees open for the flap
int position = map(tempC, 0, 50, 0, 180);
Serial.println(position);
if(previousPosition != position){
mainServo.write(position);
}
previousPosition = position;
}