#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Sesuaikan pin yang Anda gunakan
void setup() {
lcd.begin(16, 2); // Inisialisasi LCD dengan ukuran 16x2
Wire.begin();
Serial.begin(9600);
while (!Serial);
Serial.println("\nI2C Scanner");
lcd.print("I2C Scanner"); // Tampilkan pesan di LCD
lcd.setCursor(0, 1);
lcd.print("Scanning...");
}
void loop() {
byte error, address;
int nDevices;
nDevices = 0;
for (address = 1; address < 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("I2C device found");
lcd.setCursor(0, 1);
lcd.print("at address 0x");
if (address < 16)
lcd.print("0");
lcd.print(address, HEX);
lcd.setCursor(0, 2);
lcd.print("!");
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX);
Serial.println(" !");
nDevices++;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX);
}
delay(100); // Jeda kecil antara pemindaian
}
if (nDevices == 0) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("No I2C devices");
lcd.setCursor(0, 1);
lcd.print("found");
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
delay(5000);
}