BASIC4MCU | 질문게시판 | 토양습도센서 이용시LCD 오류
페이지 정보
작성자 윤던 작성일2023-05-23 17:43 조회42회 댓글5건본문
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD I2C 주소와 크기 설정
SoftwareSerial bluetooth(10, 11); // 블루투스 모듈의 RX, TX 핀 설정
const int soilMoisturePin = A0; // 토양 습도 센서의 아날로그 핀 설정
const int moistureThresholdLow = 300; // 습도 부족 경계값
const int moistureThresholdHigh = 700; // 습도 과다 경계값
void setup() {
lcd.begin(16, 2); // LCD 초기화
lcd.backlight(); // LCD 백라이트 활성화
Serial.begin(9600);
bluetooth.begin(9600); // 블루투스 시리얼 통신 속도 설정
lcd.print("Soil Moisture"); // LCD에 표시
lcd.setCursor(0, 1);
lcd.print("Monitoring");
delay(2000);
lcd.clear();
}
void loop() {
int soilMoisture = 1023 - analogRead(soilMoisturePin); // 토양 습도 센서 값 읽기
lcd.setCursor(0, 0);
lcd.print("Moisture: ");
lcd.print(soilMoisture);
Serial.print("Moisture: ");
Serial.println(soilMoisture);
// 습도 범위에 따라 LCD에 메시지 표시
if (soilMoisture < moistureThresholdLow) {
lcd.setCursor(0, 1);
lcd.print("Moisture: Low");
bluetooth.print("Moisture: Low\r\n");
} else if (soilMoisture > moistureThresholdHigh) {
lcd.setCursor(0, 1);
lcd.print("Moisture: High");
bluetooth.print("Moisture: High\r\n");
} else {
lcd.setCursor(0, 1);
lcd.print("Moisture: Optimal");
bluetooth.print("Moisture: Optimal\r\n");
}
delay(1000);
}
이상태로 실행 했을 시에 LCD모니터가 전원은 들어오나 글씨가 표시되지 않습니다. 저항 돌려봤는데도 뜨지않고 컴파일 오류도
아닌데 혹시 해결방법이 있을까용?
댓글 5
조회수 42master님의 댓글
master 작성일
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD I2C 주소와 크기 설정
0x27은 I2C 어드레스인데요 제조사마다 어드레스가 몇종류가 되니 잘 체크해보세요
어드레스는 변경도 가능합니다. 메뉴얼 잘 살펴보세요
윤던님의 댓글
윤던
I2C 주소 확인했을때 0x27 맞네요.. 이래도 안되면 LCD자체의 고장일까요?
master님의 댓글
master
주소확인은 사이트에서 찾았나요?
웹검색하면 i2c 주소를 찾아주는 예제도 있습니다.
https://www.google.com/search?q=%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8+i2c+lcd+%EC%96%B4%EB%93%9C%EB%A0%88%EC%8A%A4&oq=%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8+i2c+lcd+%EC%96%B4%EB%93%9C%EB%A0%88%EC%8A%A4&aqs=chrome..69i57j33i160l2.8608j0j7&sourceid=chrome&ie=UTF-8
윤던님의 댓글
윤던
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int devices = 0;
Serial.println("Scanning...");
for (address = 1; address < 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.print(address, HEX);
Serial.println(" !");
devices++;
}
}
if (devices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
delay(5000); // 5초마다 스캔을 반복
}
아뇨 인터넷에서 아두이노 LCD 주소 찾는 코드를 통해서 찾은 주소입니다!
master님의 댓글
master
LCD라이브러리 설치하면 예제도 설치됩니다.
예제로 동작하지 않으면 다른 LCD 라이브러리를 설치해서 예제로 다시 테스트 해보세요