some problem in my code that i cant figure out

so here is my code

int red = 1;
int green =2;
int blue =3;

int relay = 4;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
float temp = 0;
temp = (5.0* analogRead(2)*100.0)/1024;

Serial.println ("temperature= ");
Serial.println(temp);
Serial.println("* C");

   float voltage = analogRead(1)*(5.0/1023.0);

   Serial.println ("voltage=");
   Serial.println(voltage);
   delay(1);

while(voltage >=4.30)
{ 
  digitalWrite(red,HIGH);
  digitalWrite(green,LOW);
  digitalWrite(blue,HIGH);
if(temp >=43)
{
  digitalWrite(relay,HIGH);
 
  delay(4000);
  }

else{digitalWrite(relay,LOW);}
  
}
while(2.25<voltage<=4.29)
{
  digitalWrite(red,LOW);
  digitalWrite(green,HIGH);
  digitalWrite(blue,LOW);
 if(temp >=40)
 {digitalWrite(relay,HIGH);
 
 delay(4000);
 }
 else{digitalWrite(relay,LOW);} 
}

while(2.25>voltage>0.0)

{digitalWrite(red,LOW);
  digitalWrite(green,LOW);
  digitalWrite(blue,HIGH);
if(temp>=39)
{digitalWrite(relay,HIGH);
delay(4000);}

else
{digitalWrite(relay,LOW);}

}}

You haven't mentioned what the issue with your code is. One thing I see is that you're using digitalWrite on pin one as well as printing things on serial. Use another pin for whatever the red thing is.

More seriously, your while loops have no way of terminating. If the voltage measured is in the range specified, they will loop forever because you don't check it again in the body of the while loop.

while(2.25>voltage>0.0)

Oops

while(2.25<voltage<=4.29)

And again

sorry i forgot to mention the problem so here it is as first of all when i open the serial monitor i just get one initial reading like temperature=27.66*C voltage=0.0 the problem here is that the program is executing a break which i have'nt written anywhere in code cause i dont get any reading after the first value .

the problem here is that the program is executing a break which i have'nt written anywhere in code cause i dont get any reading after the first value .

Bad assumption. Any while() loop that fails to exit has the same effect.

The problem(s) have already been pointed out. You need to re-read the previous posts about the tests in your while() blocks and stop thinking about about non-existent break statements.

We could better correct your coding mistakes - if you explained what your code is supposed to do.

avr_fred:
We could better correct your coding mistakes - if you explained what your code is supposed to do.

so i am using a pot meter and a temperature sensor lm35.I want to use three cases of voltage as given in if brackets (initially while loops) that as soon voltage reaches case 1 red led turns on and that specific case has its threshold value for temperature that after that value relay turns on and so on case 2 green led case 3 blue led and different thresholds .

i again tried out with this code which is showing another problem

int red = 3;
int green =4;
int blue =7;

int relay = 6;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
float temp = 0;
temp = (5.0* analogRead(2)*100.0)/1024;

Serial.println ("temperature= ");
Serial.println(temp);
Serial.println("* C");

   float voltage = analogRead(1)*(5.0/1023.0);

   Serial.println ("voltage=");
   Serial.println(voltage);
   delay(1000);

if(voltage >=4.30)
{ 
  digitalWrite(red,HIGH);
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
while(temp >=43)
{
  digitalWrite(relay,HIGH);
 
  delay(4000);
  }

}
 else if(2.25<voltage<=4.29)
{
  digitalWrite(red,LOW);
  digitalWrite(green,HIGH);
  digitalWrite(blue,LOW);
 while(temp >=40)
 {digitalWrite(relay,HIGH);
 
 delay(4000);
 }}
 

else 

{digitalWrite(red,LOW);
  digitalWrite(green,LOW);
  digitalWrite(blue,HIGH);
while(temp>=39)
{digitalWrite(relay,HIGH);
delay(4000);}


}}

the problem here is that first only the green led turns on in either any case
secondly the blue led turns on once the relay turns on
thirdly (as i was only trying that whether this would work or not therefore i just simply attached lm 35 without even trying to keep it a bit near to something hot or etc ) the code shows almost the right room temperature until it suddenly shows 56*C

if(2.25<voltage<=4.29) The first expression “2.25 < voltage” will evaluate to true (aka 1) or false (aka 0).
Thus the second expression will be “(true or false) <= 4.29” which will always be true, so overall, the expression will always be true.
You need to research the logical AND operator, aka &&.

AWOL:

i  <= 4.29" which will always be true, so overall, the expression will always be true.

You need to research the logical AND operator, aka &&.
[/quote]
i am sorry AWOL i am not able to understand how this would be true

false, aka 0, is always less than 4.29. true, aka 1, is always less than 4.29.

The expression will always be true.

But voltage where it is more than 2.25 but less than or equal to 4.29 ....... I think that this is what i meant by case 2 Pls let me know if i am wrong.

if((2.25<voltage) && (voltage<=4.29))

AWOL:

if((2.25<voltage) && (voltage<=4.29))

i tried this out and it was compiled correctly but when i uploaded the code problem 3 arises first reading of the temp sensor is all fine ie almost the room temperature but either next time it suddenly reaches 56 or even a high temp then i get no reading at serial monitor.i havent provided any raise in temp in either condition.

I can't see your code

int red = 3;
int green =4;
int blue =7;

int relay = 6;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
float temp = 0;
temp = (5.0* analogRead(2)*100.0)/1024;

Serial.println (“temperature= “);
Serial.println(temp);
Serial.println(”* C”);

float voltage = analogRead(1)*(5.0/1023.0);

Serial.println (“voltage=”);
Serial.println(voltage);
delay(1000);

if(voltage >=4.30)
{
digitalWrite(red,HIGH);
digitalWrite(green,LOW);
digitalWrite(blue,LOW);
while(temp >=43)
{
digitalWrite(relay,HIGH);

delay(4000);
}

}
else if((2.25<voltage) && (voltage<=4.29))
{
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
digitalWrite(blue,LOW);
while(temp >=40)
{digitalWrite(relay,HIGH);

delay(4000);
}}

else

{digitalWrite(red,LOW);
digitalWrite(green,LOW);
digitalWrite(blue,HIGH);
while(temp>=39)
{digitalWrite(relay,HIGH);
delay(4000);}

}}

while(temp >=40)
{digitalWrite(relay,HIGH);

delay(4000);
}

How does that while loop ever exit?

(Did you see what I did with the code tags there? You should do that too when you post code)

so what should i do i want to make a pot meter controlled temp threshold changing circuit where relay would be used . i need two conditions as i uses if and while .pls help.

i think that theres some problem in my temp sensor lm35 as i uploaded this given code and the same thing happened the fourth sentence at serial monitor showed temp 44c whereas other showed 29c and after that the serial monitor wasnt showing any reading.

int red = 3;
int green =4;
int blue =7;



void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(7,OUTPUT);


}

void loop() {
  // put your main code here, to run repeatedly:
float temp = 0;
temp = (5.0* analogRead(2)*100.0)/1024;

Serial.println ("temperature= ");
Serial.println(temp);
Serial.println("* C");

   float voltage = analogRead(1)*(5.0/1023.0);

   Serial.println ("voltage=");
   Serial.println(voltage);
   delay(1000);

if(voltage >=4.30)
{ 
  digitalWrite(red,HIGH);
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);

}
 else if((2.25<voltage) && (voltage<=4.29))
{
  digitalWrite(red,LOW);
  digitalWrite(green,HIGH);
  digitalWrite(blue,LOW);
 
 }
 

else 

{digitalWrite(red,LOW);
  digitalWrite(green,LOW);
  digitalWrite(blue,HIGH);



}}

The symptoms you describe are hard to explain given the code you have. Are you sure that code was successfully loaded to the arduino? As it is, it sounds like you still have a version with a while loop that can’t end.

Add a serial print in setup so you can verify that the latest version has been loaded.

ill again re make the code and will then reply but i have a question that in this code given below as an example ....would this while code work

while(condition) {

   while(condition) {
      statement(s);
   }

   statement(s);
}

Malti: ill again re make the code and will then reply but i have a question that in this code given below as an example ....would this while code work

while(condition) {

  while(condition) {       statement(s);   }

  statement(s); }

Define "work"