Advertisement
safwan092

Untitled

Jan 11th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <LiquidCrystal_I2C.h>
  2.  
  3. // Define the LCD module
  4. LiquidCrystal_I2C lcd(0x27, 16, 2);
  5.  
  6. // Set the voltage divider resistors values
  7. const float R2 = 1000.0; // Resistance value of R1 in ohms
  8. const float Vin = 5.0; // Input voltage to the voltage divider in volts
  9.  
  10. void setup() {
  11. // Initialize the LCD module
  12. lcd.begin();
  13. lcd.backlight();
  14. lcd.print("Voltage Divider");
  15. lcd.setCursor(0, 1);
  16. lcd.print("R = Ohms");
  17. }
  18.  
  19. void loop() {
  20. // Read the voltage across the resistor R2
  21. float Vout = analogRead(A0) * Vin / 1023.0;
  22.  
  23. // Calculate the resistance R2 using the voltage divider formula
  24. float R1 = abs(-(R2 * (Vin - Vout)) / Vout);
  25.  
  26.  
  27. // Display the calculated resistance R2 on the LCD
  28. lcd.setCursor(4, 1);
  29. lcd.print(" ");
  30. lcd.setCursor(4, 1);
  31. lcd.print(R1);
  32. delay(500);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement