Tinkercad Arduino温控器LCD无显示故障求助
恒温器设备故障排查(LCD无显示)
一、设备预期功能
- 检测环境温度,实时显示当前温度与设定温度
- 通过高/低按钮调整设定温度值
- 当实际温度高于设定值时,自动启动风扇,同时扬声器触发一次提示音
二、故障现象
代码编译运行无报错,扬声器、温度传感器(TMP)、风扇电机(MOTOR)均工作正常,但LCD显示屏无任何显示
三、设备运行代码
#include <Wire.h> #define TEMP_ADDR 72 #include <LiquidCrystal.h> LiquidCrystal lcd(2, 3, 4, 5, 6, 7); byte degree[8] = { B00110, B01001, B01001, B00110, B00000, B00000, B00000, B00000, }; byte fan_on[8] = { B00100, B10101, B01110, B11111, B01110, B10101, B00100, B00000, }; byte fan_off[8] = { B00100, B00100, B00100, B11111, B00100, B00100, B00100, B00000, }; const int SPEAKER=8; const int DOWN_BUTTON =9; const int UP_BUTTON=10; const int FAN =11; const int T0=0; boolean lastDownTempButton = LOW; boolean currentDownTempButton = LOW; boolean lastUpTempButton = LOW; boolean currentUpTempButton = LOW; int set_temp = 23; boolean one_time = false; void setup() { pinMode(FAN, OUTPUT); //Create a wire object for the temp sensor Wire.begin(); //Set up the LCD's number of columns and rows lcd.begin(16, 2); //Make custom characters lcd.createChar(0, degree); lcd.createChar(1, fan_off); lcd.createChar(2, fan_on); //Print a static message to the LCD lcd.setCursor(0,0); lcd.print("Current:"); lcd.setCursor(10,0); lcd.write((byte)0); lcd.setCursor(11,0); lcd.print("C"); lcd.setCursor(0,1); lcd.print("Set:"); lcd.setCursor(10,1); lcd.write((byte)0); lcd.setCursor(11,1); lcd.print("C"); lcd.setCursor(15,1); lcd.write(1); } boolean debounce(boolean last, int pin) { boolean current = digitalRead(pin); if (last != current) { delay(5); current = digitalRead(pin); } return current; } void loop() { /* Wire.beginTransmission(TEMP_ADDR); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(TEMP_ADDR, 1); while(Wire.available() == 0); int c = Wire.read(); */ // for LM35 temperature sensor (Chapter3. 아날로그 신호와 센서값) int c = analogRead(T0); c = c*5.0 /1024.0 * 100; Serial.println(c); lcd.setCursor(8,0); //Move the cursor lcd.print(c); //Print this new value lcd.setCursor(8,0); lcd.print(c); currentDownTempButton = debounce(lastDownTempButton, DOWN_BUTTON); currentUpTempButton = debounce(lastUpTempButton, UP_BUTTON); if (lastDownTempButton== LOW && currentDownTempButton == HIGH) { set_temp--; } //Turn up the set temp else if (lastUpTempButton== LOW && currentUpTempButton == HIGH) { set_temp++; } //Print the set temp lcd.setCursor(8,1); lcd.print(set_temp); lastDownTempButton = currentDownTempButton; lastUpTempButton = currentUpTempButton; if (c >= set_temp) { if (!one_time) { tone(SPEAKER, 400); delay(500); one_time = true; } else { noTone(SPEAKER); } digitalWrite(FAN, HIGH); lcd.setCursor(15,1); lcd.write(2); } else { noTone(SPEAKER); one_time = false; digitalWrite(FAN, LOW); lcd.setCursor(15,1); lcd.write(1); } }
针对性排查建议
既然其他模块都正常工作,问题大概率集中在LCD的硬件连接或初始化环节,你可以按以下步骤排查:
- 核对LCD接线:确认
LiquidCrystal lcd(2, 3, 4, 5, 6, 7)里的引脚是否和实际硬件的RS、EN、D4-D7引脚一一对应,别接错顺序 - 检查电源与对比度:确保LCD的VCC接5V、GND接地,同时调节对比度电位器(如果有)——电位器拧到极端会导致屏幕全黑
- 简化测试LCD:暂时注释掉自定义字符和动态显示代码,只保留
lcd.begin(16,2)和lcd.print("LCD Test"),看屏幕是否能显示基础文本,快速区分是代码逻辑还是硬件问题 - 调整初始化顺序:尝试把
lcd.begin(16,2)移到Wire.begin()之前执行,排除I2C总线对LCD初始化的干扰
内容的提问来源于stack exchange,提问作者Regina Kang




