Need help with displaying Serial Monitor onto LCD Screen

Indeed. It should look more like this:

Those two pins A4 and A5 (plus power and ground) are all you need for an I2C display, shown here:

(Ignore the blue connector on the left. I’m using it to control the backlight brightness, so if yours has a jumper block there, keep using it.)

Every connection is an opportunity for problems — even chips in sockets — so minimizing the number of connections minimizes the number of potential problems :slightly_smiling_face:

I did change lcd.home(); to lcd.clear();. This is my current code:

#include <MHZ.h>
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// pin for pwm reading
#define CO2_IN 10

// pin for uart reading
#define MH_Z19_RX 4  // D7
#define MH_Z19_TX 0  // D6

MHZ co2(MH_Z19_RX, MH_Z19_TX, CO2_IN, MHZ19B);

void setup() {
  Serial.begin(9600);
  pinMode(CO2_IN, INPUT);
  delay(100);
  Serial.println("MHZ 19B");

  lcd.begin(16,1);             // ***** 16 columns, 1 row
  lcd.clear();                 // ***** clear the display, cursor upper left
  lcd.print("hello, world!");  // ***** print something so we know it's working
  delay(5000);                 // ***** allow time to read it before proceeding
              // ***** get rid of the delay() when everything is working *****

  // enable debug to get addition information
  // co2.setDebug(true);

  if (co2.isPreHeating()) {
    Serial.print("Preheating");
    while (co2.isPreHeating()) {
      Serial.print(".");
      delay(5000);
    }
    Serial.println();
  }
}

void loop() {
  Serial.print("\n----- Time from start: ");
  lcd.clear();                  // ***** position the cursor at upper left
  lcd.print(millis() / 1000);
  Serial.println(" s");


  int ppm_pwm = co2.readCO2PWM();
  lcd.print("PPM:");        // ***** these will go right after the " s"
  lcd.print(ppm_pwm);

  Serial.println("\n------------------------------");
  delay(5000);

}

Also, I don't have access to a new LCD. I'm at the science project fair thing right now, and I don't have another one at home anyway.

Also also, I used to have one of those LCD screens that were pre-soldered! I thought I had the wrong one and returned it..

And.. No, neither of those were my random characters.

  • Careful, I said ioref is 5v not 3.5V .

What I meant was the uh.. Connection. Y'know? And, 5v works better than 3.5v on my lcd..

  • Your last image in post 16 looks okay. :roll_eyes:

That's when I moved the LCD's connection from the 3.5v to the ioref.

GAASSP! removing the lcd.display show millis or whatever removed the numbers from the screen! joyous occasion! my issues are solved and i am put to rest..

thanks to all of you guys for your help ahh

I can’t find where you did that but ok.

You have to remember that whatever you write to the lcd using is going to appear wherever it cursor happens to be. And, if whatever you print is not long enough to cover up whatever was there before, the characters that were already there will be unaffected.

So, if you are not certain where that will be, always position the cursor using lcd.setCursor(col, row) before writing something using lcd.print().

You can use lcd.home() to position the cursor at the upper left, or lcd.clear() which does that in addition to clearing the display. You changed lcd.home() to lcd.clear() in your most recent code, but you did not change the comment that accompanies it. I use comments primarily to prevent my own confusion, but the converse is also true… if my comments don’t match my code I’ll wind up confusing myself :face_with_spiral_eyes:

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// pin for pwm reading
#define CO2_IN 10

// pin for uart reading
#define MH_Z19_RX 4  // D7
#define MH_Z19_TX 0  // D6

MHZ co2(MH_Z19_RX, MH_Z19_TX, CO2_IN, MHZ19B);

Hi @red_aka_anxiety !

I was a little bit puzzled by the following observations:

  • The defined RX/TX pins (SoftwareSerial input and output used by the co2 sensor)
    • pin 0 is dedicated for HardwareSerial
    • pin 4 is connected to D5 of the LCD

The picture you posted shows that two lines go from the sensor board to D7 and D6 of the Arduino. Coincidently these pins have been commented out in the definition of MH_Z19_RX and MH_Z19_TX ...

Your latest code from post 22 does not comply to the wiring in post 9.

I assume you are using this library

https://github.com/tobiasschuerg/MH-Z-CO2-Sensors/tree/master

and the example provided there ...

Unfortunately that example already contains the issues regarding the wrong pin for SoftwareSerial on an Arduino where Serial is used for other purposes. Actually SoftwareSerial is not required at all when the data are only taken from a pwmPin.

It would be much cleaner to initialize the sensor class with this constructor so that the SoftwareSerial is not initialized at all and remove the wires from/to RX/TX of the sensor board.

//MHZ(uint8_t pwmpin, SensorType type, MeasuringRange range = RANGE_5K);
// should look like this
MHZ co2(CO2_IN, MHZ19B, RANGE_5K);