Problem with code of program

Hi ! I need your help for my program. I'm a beginner and I don't know how to do:
I have components: 3 leds, 1 button and 1 temperature sensor.
When the development board is powered, the red led will light up, and when the user presses the button the following actions will happen: -The green led and blue led lights up and the red LED goes out and the Temperature will be displayed on Serial Monitor.I try to do it with tinkercad and i failed ! Please help me ! :frowning:

You show me yours, and then I'll show you mine. . . . . Code that is.

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags
[code]Paste your sketch here[/code]

We're quite good at helping with code when there is some code that we can see. No code, no help.

Steve

Thank you for replay.I have the circuit and code but its doesnt work :

int button=2;
int sensor1= A5;
int sensor2= A4;
int ledred=13;
int ledblue=12;
int ledverde =11;
int i=0;
void setup() {
Serial.begin(9600);
pinMode(ledred,OUTPUT);
pinMode(ledblue,OUTPUT);
pinMode(ledverde,OUTPUT);
pinMode(button,INPUT);
attachInterrupt(0,temp,RISING);

}

void loop()
{

if(button)
{
if(!(i==0))
{

int reading = analogRead(sensor1);
float voltage = reading * 4.89;
float Temp1 = (voltage - 500);

Temp1 /=10;
Serial.print ("Temp 1 is ");
Serial.print(Temp1);
Serial.println (" C ");

int reading2 = analogRead(sensor2);
digitalWrite(ledverde, HIGH);
delay(700);
digitalWrite(ledred, LOW);
digitalWrite(ledblue, HIGH);
delay(700);
}
}
}

void temp ()
{
if(button)
{

button = false;

digitalWrite(ledred,HIGH);
delay(700);
if(!(i==0))
{
Serial.println("");
Serial.println("Serial Monitor Stop");
}

}else
{i++;
button = true;
digitalWrite(ledverde,HIGH);
delay(700);
digitalWrite(ledblue,HIGH);
delay(700);

}
}

int button=2;
int sensor1= A5;
int sensor2= A4;
int ledred=13;
int ledblue=12;
 int ledverde =11;
int i=0;
void setup() {
  Serial.begin(9600);
  pinMode(ledred,OUTPUT);
 pinMode(ledblue,OUTPUT);
 pinMode(ledverde,OUTPUT);
 pinMode(button,INPUT_PULLUP);  // Torn on the internal PULLUP
attachInterrupt(0,temp,RISING);
  
}

void loop()
{ 

 if(button) // SHOULD BE if(digitalRead(button) == LOW)
 {
  if(!(i==0))
     {

  int reading = analogRead(sensor1);
float voltage = reading * 4.89;
float Temp1 = (voltage - 500);

Temp1 /=10;
Serial.print ("Temp 1 is ");
Serial.print(Temp1);
Serial.println (" C    ");

int reading2 = analogRead(sensor2);
digitalWrite(ledverde, HIGH);
delay(700);
  digitalWrite(ledred, LOW);
    digitalWrite(ledblue, HIGH);
delay(700);
     }
     }
}

void temp ()
{
 if(button)
 {
 

   button = false;
   
   digitalWrite(ledred,HIGH);
   delay(700);
 if(!(i==0))
 {
 Serial.println("");
 Serial.println("Serial Monitor Stop");
 }
   
 }else
 {i++;
  button = true;
   digitalWrite(ledverde,HIGH);
delay(700);
  digitalWrite(ledblue,HIGH);
delay(700);
 
}
}

And wire your button between pin 2 and GND.

is anybody who can help me ???

Did you bother looking at the modified code that missdrew posted for you? What other help do you need?

Steve

bassem123:
is anybody who can help me ???

Did you read reply #5?

if(!(i==0))akaif (i != 0)

Please remember to use code tags when posting code

Yes i saw and i checked but .... I must do it like that : The red led ... When the development board is powered, the red led will light up without press on button ...
And when i press on button for red the blue and verde remains still high

missdrew:

int button=2;

int sensor1= A5;
int sensor2= A4;
int ledred=13;
int ledblue=12;
int ledverde =11;
int i=0;
void setup() {
 Serial.begin(9600);
 pinMode(ledred,OUTPUT);
pinMode(ledblue,OUTPUT);
pinMode(ledverde,OUTPUT);
pinMode(button,INPUT_PULLUP);  // Torn on the internal PULLUP
attachInterrupt(0,temp,RISING);
 
}

void loop()
{

if(button) // SHOULD BE if(digitalRead(button) == LOW)
{
 if(!(i==0))
    {

int reading = analogRead(sensor1);
float voltage = reading * 4.89;
float Temp1 = (voltage - 500);

Temp1 /=10;
Serial.print ("Temp 1 is ");
Serial.print(Temp1);
Serial.println (" C    ");

int reading2 = analogRead(sensor2);
digitalWrite(ledverde, HIGH);
delay(700);
 digitalWrite(ledred, LOW);
   digitalWrite(ledblue, HIGH);
delay(700);
    }
    }
}

void temp ()
{
if(button)
{

button = false;
 
  digitalWrite(ledred,HIGH);
  delay(700);
if(!(i==0))
{
Serial.println("");
Serial.println("Serial Monitor Stop");
}
 
}else
{i++;
 button = true;
  digitalWrite(ledverde,HIGH);
delay(700);
 digitalWrite(ledblue,HIGH);
delay(700);

}
}




And wire your button between pin 2 and GND.

thank you, i am sorry but i didnt mention it i dont need sensor 2.... i will have only 1 temperature sensor :(((

thank you, i am sorry but i didnt mention it i dont need sensor 2.... i will have only 1 temperature sensor :(((

No problem, you have permission to change the code to do that.

Hi ! I need your help for my program. I'm a beginner and I don't know how to do:
I have components: 3 leds, 1 button and 1 temperature sensor.
When the development board is powered, the red led will light up, and when the user presses the button the following actions will happen: -The green led and blue led lights up and the red LED goes out and the Temperature will be displayed on Serial Monitor.I try to do it with tinkercad and i failed ! Please help me !

this is my code but is not working properly :
int button=2;
int sensor1= A5;
int ledred=13;
int ledblue=12;
int ledverde =11;
int i=0;
void setup() {
Serial.begin(9600);
pinMode(ledred,OUTPUT);
pinMode(ledblue,OUTPUT);
pinMode(ledverde,OUTPUT);
pinMode(button,INPUT);
attachInterrupt(0,temp,RISING);

}

void loop()
{

if(button)
{
if(!(i==0))
{

int reading = analogRead(sensor1);
float voltage = reading * 4.89;
float Temp1 = (voltage - 500);

Temp1 /=10;
Serial.print ("Temp 1 is ");
Serial.print(Temp1);
Serial.println (" C ");

}
}
}

void temp ()
{
if(button)
{

button = false;

digitalWrite(ledred,HIGH);
delay(700);
if(!(i==0))
{
Serial.println("");
Serial.println("Serial Monitor Stop");
}

}else
{i++;
button = true;
digitalWrite(ledverde,HIGH);
delay(700);
digitalWrite(ledblue,HIGH);
delay(700);

}
}

bassem123:
i failed ! Please help me !

How so?

It would help to edit your post and put the sketch inside code tags.

Have a look at the function digitalRead().

When a variable is for a pin, I like to put the word "pin" in it.
For example:

int buttonPin = 2;
int sensor1Pin = A5;
int ledredPin = 13;
int ledbluePin = 12;
int ledverdePin = 11;

When you use this code: if (button) then it is the same as if (2), because 'button' is 2.

Duplicate topics moved to a common location and merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

but i dont know who can help me and where .... to find solution ......because in my program i have leds and also temperature sensor and button :slightly_frowning_face: :slightly_frowning_face: :slightly_frowning_face: :cry: :cry: :cry:

Again, see reply #5

You've been given most of the answers you need in post#5 and again in #14. You have done nothing at all with those suggestions.

If the 'help' you're looking for is someone to write your complete program for you then you're in the wrong place. Here you will get helpful suggestions but you then need to do something with them not just ignore them.

Steve

That code from post number 5 , it doesnt help me at all ... is the same code with mine. I need another advice .And please, answer to this post only people who wants to help me !