Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_I2C.h>
- // Define the LCD module
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- // Set the voltage divider resistors values
- const float R2 = 1000.0; // Resistance value of R1 in ohms
- const float Vin = 5.0; // Input voltage to the voltage divider in volts
- void setup() {
- // Initialize the LCD module
- lcd.begin();
- lcd.backlight();
- lcd.print("Voltage Divider");
- lcd.setCursor(0, 1);
- lcd.print("R = Ohms");
- }
- void loop() {
- // Read the voltage across the resistor R2
- float Vout = analogRead(A0) * Vin / 1023.0;
- // Calculate the resistance R2 using the voltage divider formula
- float R1 = abs(-(R2 * (Vin - Vout)) / Vout);
- // Display the calculated resistance R2 on the LCD
- lcd.setCursor(4, 1);
- lcd.print(" ");
- lcd.setCursor(4, 1);
- lcd.print(R1);
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement