float Vin = 5.0; // Input voltage (5V)
float R_fixed = 1000; // Fixed resistor value in ohms
void setup() {
Serial.begin(9600);
}
void loop() {
// Simulate changing R_var values in increments, from 0 ohms to 10,000 ohms
for (int R_var = 0; R_var <= 10000; R_var += 1) { // Increment R_var by 500 ohms each time
// Calculate the output voltage based on the variable resistor
float Vout = Vin * (R_var / (R_var + R_fixed)); // Voltage based on voltage divider equation
// Print the results
Serial.print("Variable Resistor: ");
Serial.print(R_var);
Serial.print(" ohms | Voltage: ");
Serial.print(Vout, 2); // Display voltage with two decimal places
Serial.println(" V");
delay(500); // Wait half a second before the next increment
}
// Optional: Add a delay at the end of the loop before starting again
delay(2000); // Wait 2 seconds before repeating the loop
}