int potPin1 = A0; // Analog pin where the sensor is connected
int potPin2 = A1;
int buzzPin = 10;
int ledPin = 9;
int brightness = 0;
int dt = 500; // Delay time in milliseconds
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
pinMode(potPin1, INPUT);
pinMode(potPin2, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzPin, OUTPUT);
}
void loop() {
int potValue = analogRead(potPin1);
int freqValue = analogRead(potPin2); // Read analog value from the sensor
// Convert the analog value to voltage (assuming a 5V reference)
float voltage = (potValue * 5.0) / 1023.0;
brightness = map(potValue, 0, 1023, 0, 255);
int freq = map(freqValue, 0, 1023, 0, 255);
analogWrite(ledPin, brightness);
analogWrite(buzzPin, freq);
tone(buzzPin, freq);
delay(dt);
noTone(buzzPin);
// Print the analog value and its corresponding voltage
Serial.print("Analog Value: ");
Serial.print(potValue);
Serial.println(" V");
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.println(" V");
Serial.print("Brightness = ");
Serial.println(brightness);
Serial.print("Frequency = ");
Serial.println(freq);
delay(dt); // Wait for 500 milliseconds before the next reading
// brightness = 255 * potValue / 1023;
}