const int potentiometerPin = A0; // Define the pin for the potentiometer
const int ledPin = 9;
void setup() {
// Serial.begin(9600); // Initialize serial communication for debugging
pinMode(ledPin,OUTPUT);
}
void loop() {
// Read the analog value from the potentiometer
int sensorValue = analogRead(potentiometerPin);
// Print the raw sensor value to the serial monitor
/* Serial.print("Sensor Value: ");
Serial.println(sensorValue); */
// You can also convert the sensor value to a voltage if needed
// For a 5V Arduino, the analogRead() function returns a value from 0 to 1023
// If the potentiometer is connected to 5V, the voltage range is 0 to 5 volts
float voltage = sensorValue * (255.0 / 1023.0);
// Print the voltage to the serial monitor
/* Serial.print("Voltage: ");
Serial.println(voltage); */
analogWrite(ledPin,voltage);
}