1
4
5#include <LiquidCrystal_I2C.h>
6#include <LCD.h>
7
8#define analogInput A0
9#define R1 220
10#define vin 5
11#define BACKLIGHT_PIN 3
12#define En_pin 2
13#define Rw_pin 1
14#define Rs_pin 0
15#define D4_pin 4
16#define D5_pin 5
17#define D6_pin 6
18#define D7_pin 7
19
20LiquidCrystal_I2C lcd(0x27, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
21
22void setup() {
23
24 Serial.begin(9600);
25
26}
27
28void loop() {
29 int sensorValue=analogRead(analogInput);
30 float voltage=sensorValue*(5.0/1023.0);
31 screen(String(resistance(voltage)));
32 delay(3000);
33}
34
35int resistance(float vout){
36 return R1*(1/(vin/vout-1));
37}
38
39void screen(String text){
40
41 lcd.begin (16,2);
42
43
44 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
45 lcd.setBacklight(HIGH);
46
47
48 lcd.setCursor(0,0);
49
50
51 lcd.print("Resistor value is: ");
52
53
54 lcd.setCursor(0,1);
55 lcd.print(text);
56 lcd.print(" ohm");
57
58}