help! having trouble with programming in sensor LM35.

im creating a program where in if the reading of the temperature sensor reaches 30 degrees C, the pin3 will be high no matter if the temperature sensor goes down 30 or goes up, the pin 3 will be high, the problem is that after the temperature sensor reaches 30 deg C,, it cools down the normal room temperature and the pin3 will be LOW. any help will be appreciated. heres my schematic.

void setup() { Serial.begin(9600); pinMode(pin3, OUTPUT); pinMode(tempPin, INPUT); }

void loop() { val=analogRead(tempPin); float voltage=val*5.0; voltage/=1024.0;

Serial.print(voltage); Serial.print(" volts ");

float temperatureC=(voltage)*100; Serial.print(temperatureC); Serial.println(" degrees C");

if (temperatureC>=30) {

digitalWrite(pin3, HIGH);



if (temperatureC>=30) digitalWrite(pin3, HIGH);
else if (temperatureC<29.9) digitalWrite(pin3, LOW);  // add .2 deg hysteresis to avoid blinking