Problem Arduino (328P) with Temperature Sensor(LM35D) and LCD (16*2)

Hello everyone, i've got a problem, i've have to do for my homework, a simulation on proteus of an arduino link to a sensor temperature, a button and a LCD.

It has to appear on the LCD screen, the temperature recieves by the sensor temperature. If you button is not push, the LCD screen has to print the temperature in celsius.
But if the button is pushed, it has to print the temperature in Fahrenheit.
I realise this code:

#include "LiquidCrystal.h"
const int buttonPin=6;
int sensorPin=7;
int buttonState=0;

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

void setup()
{
  pinMode(buttonPin,INPUT);
  lcd.begin(16,2);
 
}

void loop()
{
  int reading = analogRead(sensorPin);
  float voltage = reading* 5.0 / 1024.0;
  float temperatureC = voltage / 10*1000;
  float temperatureF = temperatureC*1.8 + 32;
  if(buttonState==LOW)
  {
    lcd.write(temperatureC);
  }
  if(buttonState==HIGH)
  {
    lcd.write(temperatureF);
  }
}

But the LCD screen print only "~~~~~~~~"

Thanks for your help!

Where do you assign a value to buttonState, other than zero?

I'm sorry, we don't have a section for Proteus questions - did you mean "LCD.print"?

Hey, thanks for answering! :slight_smile:

I'm a beginner, it has been only one week since i'm programming on Arduino, so it's difficult for me to understand...

So the Arduino doesn't detect if the button is pushed or not? Because I thought the value to Button state was just here to intialize the state of the Button...

Do I have to put a buttonState = digitalRead (buttonPin); in my code to dectect the actual state of the button?

And yes, i would like to print the value of the temperature on the LCD on Proteus.

So I need to use a LCD.print? There is no difference between a Lcd.print and a lcd.write,no?

Thanks :smiley:

There is no difference between a Lcd.print and a lcd.write,no?

Why would anyone create two methods to do exactly the same thing?

Do I have to put a buttonState = digitalRead (buttonPin); in my code

The great thing about Arduino is you can very easily try stuff in the five minutes you've got between forum posts.
I don't know anything about Proteus.