#include <LiquidCrystal.h>

// Initialize the LCD with the appropriate pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

const int analogPin = A0;
const int digitalPin = 8;


void setup() {
  lcd.begin(16, 2);  // Initialize the LCD with 16 columns and 2 rows
  lcd.setCursor(0, 0);
  lcd.print("Ohm Meter");

  pinMode(digitalPin, OUTPUT);
  digitalWrite(digitalPin, LOW);  // Set the digital pin LOW initially
}

void loop() {
  digitalWrite(digitalPin, HIGH);  // Apply 5V to the resistor
  delay(10);  // Allow the voltage to stabilize
  int rawValue = analogRead(analogPin);  // Read the analog voltage
  digitalWrite(digitalPin, LOW);  // Turn off the voltage source
  
  // Calculate resistance using the voltage divider formula
  float voltage = (5.0 * rawValue) / 1023.0;
  float resistance = (10.0 * voltage) / (5.0 - voltage);

  lcd.setCursor(0, 1);
  lcd.print("Resistance:       ");
  lcd.setCursor(12, 1);
  lcd.print(resistance, 2);  // Display resistance with 2 decimal places
  lcd.print(" Ohms     ");

  delay(1000);  // Delay before taking another reading
}
$abcdeabcde151015202530354045505560fghijfghij