ecran-i2c-lcd.ino
A 16x2 LCD fitted with a PCF8574 I2C backpack uses only two pins (SDA/SCL). The sketch shows the voltage measured on A0 and the uptime, refreshed twice per second.
Hardware
An Arduino Uno R3 (ATmega328P, 5 V, 16 MHz) powered over USB or a 7-12 V barrel jack. 1 16x2 LCD with PCF8574 I2C backpack (address 0x27 or 0x3F).
Wiring
SDA to A4, SCL to A5 (I2C pins of AVR boards), VCC 5V, GND. Verify the I2C address with a scanner (e.g. i2c_scanner).
How it works
Wire drives the I2C bus; LiquidCrystal_I2C translates print() into LCD commands. setCursor moves the cursor, trailing spaces erase leftovers.
Running it
In the Arduino IDE, select the « Arduino Uno » board and the matching serial port, then click Upload. Open the serial monitor at 9600 baud to follow the messages.
Variants
Change the address (0x3F) if nothing shows, or stack several sensors with automatic page scrolling every 5 s.
ecran-i2c-lcd.ino
// LCD 16x2 + convertisseur I2C PCF8574 : affichage de mesures.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // adresse usuelle 0x27 (0x3F sur certains)
void setup() {
Serial.begin(9600);
Wire.begin();
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, monde !");
delay(1500);
lcd.clear();
}
void loop() {
// Exemple : tension d'alimentation mesuree sur la reference interne.
analogRead(A0); // rechauffe de l'ADC
long brut = analogRead(A0);
float tension = brut * 5.0 / 1023.0;
lcd.setCursor(0, 0);
lcd.print("A0:");
lcd.print(tension, 2);
lcd.print("V "); // efface les chiffres residuels
lcd.setCursor(0, 1);
lcd.print("Uptime:");
lcd.print(millis() / 1000);
lcd.print("s ");
delay(500);
}