1

Below is my code and a picture of the gibberish. It's different every time. If i pull out the temp sensor, i still get gibberish, sometimes. I'm at a loss as to what to even be looking at now. Any ideas?

gibberish

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//set capacities
int keg1_volume = 19;
int keg2_volume = 19;
const int temperaturePin = 0;

void setup() {
  //initial delay
  delay(1000);

  //set contrast
  pinMode(9, OUTPUT);
  analogWrite(9, 100);

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  // Print header to the LCD
  lcd.setCursor(6, 0);
  lcd.print("BeerView");
  lcd.setCursor(0,1);
  lcd.print("Keg (C)");
  lcd.setCursor(10,1);
  lcd.print("Keg (F)");

  //initialize serial for debugging
  Serial.begin(9600);

  //get voltage and calculate temp
  float voltage, degreesC, degreesF;
  voltage = getVoltage(temperaturePin);
  degreesC = (voltage - 0.5) * 100.0;
  degreesF = degreesC * (9.0/5.0) + 32.0;

  //display temp
  lcd.setCursor(0,2);
  lcd.print(degreesC);
  Serial.println(degreesC);  
  lcd.setCursor(10,2);
  lcd.print(degreesF);
  Serial.println(degreesF);

}

void loop() {   
}

float getVoltage(int pin)
{
  return (analogRead(pin) * 0.004882814);
}
  • Does problem still occur if you substitute a fixed voltage (eg use a voltage divider or pot) for the PWM'd contrast input? The PWM's sharp-cornered waveform might be introducing a lot of noise into the LCD. If fixed voltage fixes the problem, and you still want to use PWM, put a good low-pass filter between PWM and LCD pin 3 or whatever – James Waldby - jwpat7 Jan 20 '17 at 1:26
  • that was it. i had originally tried to use the pot, but couldn't get it to work (no clue why, hence using the PWM). just changed back to pot, and it's all beautiful now. thank you so much for the help!!!! – Charles Jan 20 '17 at 5:14
2

Used a pot instead of the PWM from pin 9. Thanks for the help!!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.