|
| 1 | +# 16x2 LCD Display with I2C Module |
| 2 | + |
| 3 | +This repository provides setup instructions and example code for using a **16x2 LCD display with an I2C module** on an Arduino. |
| 4 | + |
| 5 | +## 📌 Features |
| 6 | +- Uses I2C interface (SDA, SCL) to communicate with the LCD |
| 7 | +- Requires only two pins, saving digital pins for other components |
| 8 | +- Supports 16 characters per row and 2 rows |
| 9 | +- Adjustable backlight and contrast |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## 🛠 Requirements |
| 14 | +### 🔹 Hardware: |
| 15 | +- Arduino Board (Uno, Mega, Nano, etc.) |
| 16 | +- 16x2 LCD Display with I2C Module |
| 17 | +- Jumper Wires |
| 18 | + |
| 19 | +### 🔹 Software: |
| 20 | +- **Arduino IDE** (Download: [https://www.arduino.cc/en/software](https://www.arduino.cc/en/software)) |
| 21 | +- **LiquidCrystal I2C Library** (Install from Arduino Library Manager) |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## ⚡ Wiring Diagram |
| 26 | +Connect the LCD module to the Arduino as follows: |
| 27 | + |
| 28 | +| **LCD Pin** | **Arduino UNO Pin** | |
| 29 | +|------------|----------------| |
| 30 | +| **VCC** | **5V** | |
| 31 | +| **GND** | **GND** | |
| 32 | +| **SDA** | **A4** | |
| 33 | +| **SCL** | **A5** | |
| 34 | + |
| 35 | +📌 **For Arduino Mega:** |
| 36 | +- **SDA → Pin 20** |
| 37 | +- **SCL → Pin 21** |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## 📥 Library Installation |
| 42 | +1. Open **Arduino IDE** |
| 43 | +2. Go to **Sketch → Include Library → Manage Libraries** |
| 44 | +3. Search for **LiquidCrystal I2C** |
| 45 | +4. Install the library by **Frank de Brabander** |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 🚀 Example Code |
| 50 | +Upload the following code to test your LCD module: |
| 51 | + |
| 52 | +```cpp |
| 53 | +#include <Wire.h> |
| 54 | +#include <LiquidCrystal_I2C.h> |
| 55 | + |
| 56 | +LiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 if needed |
| 57 | + |
| 58 | +void setup() { |
| 59 | + lcd.init(); |
| 60 | + lcd.backlight(); |
| 61 | + lcd.setCursor(0, 0); |
| 62 | + lcd.print("Hello, World!"); |
| 63 | +} |
| 64 | + |
| 65 | +void loop() { |
| 66 | +} |
| 67 | +``` |
| 68 | +
|
| 69 | +🔹 If the LCD does not display anything: |
| 70 | +- Run an **I2C Scanner** to check the address (might be `0x3F` instead of `0x27`) |
| 71 | +- Adjust the **blue contrast potentiometer** on the back of the module |
| 72 | +
|
| 73 | +--- |
| 74 | +
|
| 75 | +## 🔍 I2C Address Scanner (Debugging) |
| 76 | +Use this code to find the correct I2C address: |
| 77 | +
|
| 78 | +```cpp |
| 79 | +#include <Wire.h> |
| 80 | +
|
| 81 | +void setup() { |
| 82 | + Serial.begin(9600); |
| 83 | + Serial.println("Scanning for I2C devices..."); |
| 84 | + Wire.begin(); |
| 85 | +} |
| 86 | +
|
| 87 | +void loop() { |
| 88 | + byte error, address; |
| 89 | + int nDevices = 0; |
| 90 | + |
| 91 | + for (address = 1; address < 127; address++) { |
| 92 | + Wire.beginTransmission(address); |
| 93 | + error = Wire.endTransmission(); |
| 94 | + |
| 95 | + if (error == 0) { |
| 96 | + Serial.print("I2C device found at address 0x"); |
| 97 | + Serial.println(address, HEX); |
| 98 | + nDevices++; |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + if (nDevices == 0) Serial.println("No I2C devices found"); |
| 103 | + delay(5000); |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## 📌 Notes |
| 110 | +- If you see **garbled characters** or **no display**, try adjusting the **contrast**. |
| 111 | +- Double-check **wiring connections** and **I2C address**. |
| 112 | +- Ensure **LiquidCrystal I2C library** is installed. |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## 📜 License |
| 117 | +This project is open-source and available under the **MIT License**. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## 🙌 Credits |
| 122 | +- Developed by **Your Name** |
| 123 | +- Based on the work of **Arduino Community** |
| 124 | +- GitHub Repository: [Your Repo Link](#) |
| 125 | + |
| 126 | +🚀 **Happy Coding!** 🎉 |
0 commit comments