Hello all,
I am building an Arduino project like this one: Temperature Based Fan Speed Controller project | Arduino Uno - IOT - YouTube
The temperature sensor works, and the fan spins as it should, etc. The only thing that is not working is the 1602A LCD Display that I purchased to use with my Arduino Uno (by Sparkfun).
My code is as below, and I have quadruple-checked the wiring; it's all 100% correct. I'm thinking it's some code problem? I've attached a snapshot of the schematic I'm using, made with TinkerCad. Even when I click "Start Simulation" on TinkerCad, the LCD Display just stays blank.
Please let me know, thanks in advance.
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 11, 12); //Naming the pins on the Arduino to which the LCD Display is connected to.
int tempSensor = A0;
int fanControl = 9;
float tempReading;
#define fan 10;
void setup() {
pinMode (fanControl, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(3, 1);
lcd.print("Welcome!");
delay(1000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Initializing...");
delay(1000);
lcd.clear();
lcd.print("Go Blue!!");
delay(2000);
lcd.clear();
}
void loop() {
lcd.setCursor(3, 0);
lcd.print("Reading");
lcd.setCursor(2, 1);
lcd.print("Temperature...");
delay(3000);
lcd.clear();
lcd.setCursor(0, 2);
tempReading = analogRead(tempSensor);
tempReading = tempReading * 0.48828125; //Converting temperature into °C
lcd.setCursor(0, 0);
lcd.print("Temp = ");
lcd.setCursor(5, 1);
lcd.print(tempReading); //Prints the temperature reading from the sensor
delay(2000);
lcd.clear();
if (tempReading < 20){
analogWrite(9, 0);
lcd.print("Fan Off");
delay(2000);
lcd.clear();
}
else if (tempReading <= 22){
analogWrite(fanControl, 55);
lcd.print("Fan Speed: 20%");
delay(2000);
lcd.clear();
}
else if (tempReading <= 24){
analogWrite(fanControl, 110);
lcd.print("Fan Speed: 40%");
delay(2000);
lcd.clear();
}
else if (tempReading <= 26){
analogWrite(fanControl, 165);
lcd.print("Fan Speed: 60%");
delay(2000);
lcd.clear();
}
else if (tempReading <= 28){
analogWrite(fanControl, 220);
lcd.print("Fan Speed: 80%");
delay(2000);
lcd.clear();
}
else if (tempReading >= 30){
analogWrite(fanControl, 255);
lcd.print("Fan Speed: 100%");
delay(2000);
lcd.clear();
}
}
Please let me know if I am missing any necessary information. This is my first time using the Arduino Community Forum.