#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int potPin = A0;
const int greenLed = 9;
const int yellowLed = 10;
const int redLed = 11;
const int buzzerPin = 8;
const float voltage = 5.0;
const float lowCurrent = 0.01;
const float highCurrent = 0.02;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(greenLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(buzzerPin, OUTPUT);
lcd.begin(16, 2);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Ohm Meter By SCB");
delay(2000);
lcd.clear();
}
void loop() {
int potValue = analogRead(potPin);
float resistance = (voltage / (potValue / 1023.0));
float current = voltage / resistance;
lcd.setCursor(0, 0);
lcd.print("Resistansi: ");
lcd.print(resistance, 1);
lcd.print(" Ohm ");
digitalWrite(greenLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(redLed, LOW);
digitalWrite(buzzerPin, LOW);
lcd.setCursor(0, 1);
if (current <= lowCurrent) {
digitalWrite(greenLed, HIGH);
lcd.print("Status: Aman ");
} else if (current <= highCurrent) {
digitalWrite(yellowLed, HIGH);
lcd.print("Status: Waspada ");
} else {
digitalWrite(redLed, HIGH);
digitalWrite(buzzerPin, HIGH);
lcd.print("Status: Bahaya ");
}
// Cetak arus dalam mA untuk debugging
delay(500);
}