bug in my code?

hi i am new to this stuff, im also 54 yrs old so hit me easy huh? anyway im using an uno r3 to control the fans on my car. i get wierd messages on the 16x2 display and it freezes. the display does the fan control still works flawlessly.

this is the code i am using

#include <Wire.h> // For I2C
#include <LCD.h> // For LCD
#include <LiquidCrystal_I2C.h> // Added library*

//Set the pins on the I2C chip used for LCD connections

LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the default I2C bus address of the backpack-see article

int val;
int tempPin = 0;
int relay =7;

void setup()
// Set off LCD module
lcd.begin (16,2); // 16 x 2 LCD module
lcd.setBacklightPin(3,POSITIVE); // BL,BL_POL
void loop()
val = analogRead(tempPin);
float mv = ( val/1024.0)5000;
float cel = mv/10;
float farh = (cel
9)/5 + 32;

Serial.print(“TEMPRATURE = “);

Serial.print(“TEMPRATURE = “);

if (cel >74) {
lcd.setCursor ( 0, 1 );
lcd.print (“fan on”);
} else {
lcd.setCursor ( 0, 1 );
lcd.print (“fan off”);

lcd.home (); // go home
// go to the next line

delay (1000 );


see any trouble there?

20161212_145642 (640x360).jpg

i get wierd messages on the 16x2 display

Examples would be interesting

Welcome youngster. Hope you have fun with the Arduino platform.

Is your LCD display I2C or is it parallel?

There are simple examples for the LCD on the Arduino web site. Try one of these without making any changes to it to see if things work.


If you disconnect the relay from pin 7, do you ever see the weird messages and freezing? Can you determine if it freezes when the relay closes or releases?

Do you see the problem in the car, or at your desk?

Try deleting the statement lcd.print(farh), and/or changing it to lcd.print((int)farh);

I suspect your 'new' library may be choking on the print method for a parameter of type float.

the lcd is i2c with a backpack attatched

when i had it on the desk it worked great maybe noise in the cars power supply causing problems? i used a lm7812 voltage regulator chip so it would not overvoltage the arduino

tried lcd.print((int)farh); still have the same output posted a pic of the display

posted a pic of the display

Where ?

its attatched to the first post or it should be lol

ok i think i fixed it i changed the code to exclude the serial print stuff as i am using the i2c module on the lcd also added spaces to the end of the print line which i think blanked the unused characters in the display anyway it worked