Faulty characters in LCD 16x2 on adjusting potentiometer.

Hi,
I was trying to make a set-up to control and measure the temperature and humidity in an incubator using an Arduino Uno, a JHD 16x2 LCD, 22k potentiometer, a 5V relay, a bulb and a DHT11 sensor.
On uploading the code (given below) the values of temperature and humidity are shown on the LCD, but if I try adjusting the pot the characters change.
CODE:

#include <dht.h>     // Library for DHT11 Sensor

#include <LiquidCrystal.h>  // Library for LCD

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 

dht DHT;

const int pinLight = 6;

#define DHT11_PIN 7    // Assigned Pin for DHT11 Sensor

 

/* The setup() function is called when a sketch starts. It is used to initialize variables, pin modes, start using libraries, etc. This function will only run once, after each power up or reset of the Arduino board. */

 

void setup()

{

  lcd.begin(16, 2);

}

 

/* The loop() function executes the program repeatedly until Specified. */

 

void loop()

{

  int chk = DHT.read11(DHT11_PIN);  // Read the values of DHT11 from assigned Pin

  lcd.setCursor(0,0);           // Set cursor values

  lcd.print("Temp: ");           // Print the message

  lcd.print(DHT.temperature);  // Print the values

  lcd.print((char)223);        // Print the degree symbol on LCD

  lcd.print("C");                  // Print the Message

  lcd.setCursor(0,1);         // Set cursor values

  lcd.print("Humidity: ");    // Print the Message

  lcd.print(DHT.humidity);  // Print the values

  lcd.print("%");                 // Print the Message

  {
    if(DHT.temperature < 37)
     digitalWrite(pinLight, HIGH);
    else if(DHT.temperature > 37.5)
     digitalWrite(pinLight, LOW);
  }
  
  delay(1000);                  // Hold By 1000 ms

}

.incubator set-up.jpg
To take pictures of projects, you need to take the whole assembly outside into full daylight (but not direct sun), not in a dark room (on the dining table!).

tng-23:
On uploading the code (given below) the values of temperature and humidity are shown on the LCD, but if I try adjusting the pot the characters change.

Well, I am hardly surprised!

The reason for that will be that your assembly is so unstable that attempting to move the potentiometer physically interferes with the LCD connections and randomly alters it.

What have you used to make the connections to the LCD board insert into the breadboard? It does not appear to be a proper pin header and the soldering is completely dodgy!

The jumper wires to the potentiometer do not seem to be securely connected either. However, you would do well to remove the connection from the potentiometer to 5 V as this is a long-standing blunder propagated in projects. Removing that connection will make contrast setting easier and for a 10k potentiometer, connecting both ends to ground will be even better! :grinning:

I have also followed our tradition here by already giving you one "karma" point for reading the forum instructions and posting your code correctly! The unnecessary double spacing is however not too helpful, you only need extra spaces between functional blocks.

For a "real world" project such as this, a Nano - or for the final version with no computer connection, a Pro Mini - is the more practical Arduino version.

I've experienced the same effect you are talking about, but with different components. Cheaper breadboards sometimes don't make good contact with the wires. Soldering the components to a proto shield that could be stacked on top of the arduino solved my problem. I do not suggest you do this, but you should try maybe a new breadboard. More than likely, it's a connection issue with some of your wiring.

Anyway, my real reason for posting is to say you might not want to be switching the relay directly from a pin on your arduino. Relays draw a fair amount of current, and might exceed what the arduino can supply. I use a simple 2n2222 transistor as a switch to control relays.

Paul__B:
However, you would do well to remove the connection from the potentiometer to 5 V as this is a long-standing blunder propagated in projects. Removing that connection will make contrast setting easier and for a 10k potentiometer, connecting both ends to ground will be even better!

Hi Paul_B!

I've read this before, but what do you mean, connect both ends of the potentiometer to ground?

Randy

revolt_randy:
Anyway, my real reason for posting is to say you might not want to be switching the relay directly from a pin on your Arduino. Relays draw a fair amount of current, and might exceed what the Arduino can supply. I use a simple 2n2222 transistor as a switch to control relays.

If you take a look a the poorly taken photo, in the bottom left corner you will see that it is actually a relay module which already includes the switching transistor, so the connection to the Arduino pin is no problem.

In fact, there are two concerns here. If you attempt to connect one of those 5 V "Songle" relays which require 90 mA, directly to an Arduino pin, it is most unlikely to operate at all, so the complaint would be different. What is more commonly the problem, is some newbie imagining they can power the Arduino using "Vin" or the "barrel jack" and have relay modules using regulated power from the"5V" terminal. I am forever explaining that "Vin" and the "barrel jack" are basically useless hangovers from the time when (the early forms of) these boards were originated.

revolt_randy:
I've read this before, but what do you mean, connect both ends of the potentiometer to ground?

OK. Well, pin 3, "Vo" on the LCD module is the negative end of a resistor ladder of five 2k2 resistors totalling 11k which set the seven multiplex voltages for the LCD panel itself.

The positive end is connected to the Vcc terminal, so it is just stupid to connect "Vo" to Vcc externally in any way. You control the voltage by pulling "Vo" to ground with a variable resistor, the resistor ladder pulls itself to Vcc!

Now since the correct voltage for "Vo" is something between about 0 and 0.5 V corresponding to between 5 and 4.5 V across the contrast ladder, the maximum resistance required to pull down the ladder is about one tenth of its value - 1k. But the spuriously specified potentiometer is 10k, so only the lowest tenth of its range is usable, or one twentieth of its range if you have connected the top end to 5 V.

Using a proper 1k variable resistor between "Vo" and ground would be the most appropriate, but if you have a 10k potentiometer, then connecting both ends together and to ground with the wiper to "Vo" halves its effective value and makes more of its range actually usable for contrast setting.

I mean, it does work with the wrong potentiometer incorrectly wired, but with the potentiometer right down at one end of its range. This is no doubt why so many designs use a ten turn potentiometer - you actually can use about one 360˚ turn effectively. :roll_eyes: