const int sensorPin = A0; // Analog input pin for the sensor
const int ledPin = 13; // Pin for the LED
void setup() {
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(sensorPin); // Read the analog sensor value
float voltage = sensorValue * (5.0 / 1023.0); // Convert the sensor value to voltage (assuming a 5V Arduino)
// Map the voltage to degrees (assuming a 0-5V range)
float degrees = map(voltage, 0, 5, 0, 180);
Serial.print("Sensor Voltage: ");
Serial.print(voltage);
Serial.print("V, Degrees: ");
Serial.println(degrees);
if (degrees >= 45) {
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(1000); // Wait for 1 second (you can adjust this)
digitalWrite(ledPin, LOW); // Turn off the LED
delay(1000); // Wait for 1 second (you can adjust this)
}
}