#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int Vin=5; //voltage at 5V pin of arduino
float Vout=0; //voltage at A0 pin of arduino
float R1=3300; //value of known resistance
float R2=0; //value of unknown resistance
int a2d_data=0;
float buffer=0;
void setup() {
pinMode(0, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Ohm Meter");
lcd.setCursor(0,1);
lcd.print("R2 Value=");
Serial.begin(9600);
}
void loop() {
a2d_data=analogRead(0);
Serial.println(a2d_data);
buffer=a2d_data*Vin;
Vout=(buffer)/1024.0;
buffer=Vout/(Vin-Vout);
R2=R1*buffer;
lcd.setCursor(10,1);
lcd.print(R2);
}