New programmer here. I am trying to make an LCD display analog data from sensors. However, when I run my code, everything but the LCD turns on. Attached is a schematic of the circuit, and my code is below
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int blueLed = 10;
int greenLed = 11;
int yellowLed = 12;
int redLed = 13;
int MQ2A3 = A3;
int MQ5A2 = A2;
int MQ7A1 = A1;
int MQ135A0 = A0;//ammonia gas, sulfide, benzene, smoke + toxic gases
//The threshold value
int sensorThres0 = 750;
int sensorThres1 = 800;
int sensorThres2 = 800;
int sensorThres3 = 1000;
//Smoke Threshold is 1000 ← MQ2
//Methane is 800 for flame, higher for gas leaks ← MQ5
//Carbon Monoxide is <200 for good, 200 - 800 is normal, 800-1800 for high, >1800 VERY high ← MQ7, MQ9 measures same thing, but also flammable gases
//Hydrogen 18 - 59% is explosive ← MQ8
//Ammonia, Sulfide and Benze 750 is good, 750-1200 is slightly elevated, 1200 is baddddd ← MQ135yyyyyyyyy
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(MQ7A1, INPUT);
pinMode(MQ5A2, INPUT);
pinMode(MQ2A3, INPUT);
pinMode(MQ135A0, INPUT);
Serial.begin(9600);
lcd.begin(16,2);
}
void loop() {
lcd.print("HEy!!!");
int analogSensor3 = analogRead(MQ2A3);//combustible gas and smoke
int analogSensor2 = analogRead(MQ5A2);//propane, butane, methane
int analogSensor1 = analogRead(MQ7A1);//carbon monoxide
int analogSensor0 = analogRead(MQ135A0);//ammonia gas, sulfide, benzene, smoke + toxic gases
/*Serial.print("Pin A0: ");
Serial.println(analogSensor);*/
lcd.print("MQ2: ");//Smoke
lcd.print(analogSensor3);
lcd.print("MQ5: ");//H2, LPG, CH4, CO, Alcohol
lcd.print(analogSensor2);
lcd.print("MQ7: ");//carbon monoxide
lcd.print(analogSensor1);
lcd.print("MQ135: ");////ammonia gas, sulfide, benzene, smoke + toxic gases
lcd.print(analogSensor0);
// Checks if it has reached the threshold value
if (analogSensor0 > sensorThres0)
{
digitalWrite(redLed, LOW);
lcd.setCursor(0, 2);
lcd.print("");
}else
{
digitalWrite(redLed, HIGH);
}
if (analogSensor1 > sensorThres1)
{
digitalWrite(yellowLed, LOW);
lcd.setCursor(0, 2);
lcd.print("");
}else
{
digitalWrite(yellowLed, HIGH);
}
if (analogSensor2 > sensorThres2)
{
digitalWrite(greenLed, LOW);
lcd.setCursor(0, 2);
lcd.print("");
} else
{
digitalWrite(greenLed, HIGH);
}
if (analogSensor3 > sensorThres3)
{
digitalWrite(blueLed, LOW);
lcd.setCursor(0, 2);
lcd.print("");
} else
{
digitalWrite(blueLed, HIGH);
}
delay(500);
lcd.clear();
}
I even tried printing a random phrase, and it didn't print to the LCD. However, when I connected the LCD only to the Arduino, it worked. I think it might be a problem with the voltage, so I found you can use a transistor to increase voltage, but I don't know how to connect the LCD to the transistor.
Any help would be appreciated!