getting some troubles of assembly

Hello everyone ! I'm new in the world of computing, and i'm also not english, so I will probably make some mistakes of language !

I've got a project to realise for my school, it is a skylight window which is supposed to close or open itslef according to the weather.

I've got few sensors; a position sensor, a rain sensor, a temperature sensor and a button.

the program that i've made is supposed to execute the following functions :

  • open the window when the inside temperature is over 28°c (= 5,1V)
  • close the window when it's raining
  • close the window when the inside temperature is less than 15°c (=3.6V)
  • open or close the window when someone press the button.

All these 4 sensors are input, and as the output i've got a relay which is supposed to power a skylight window engine (IT work pretty well, it has only 1 button, a pressure for openning it, another one during the move will stop the motion, and a third pressure will close it)

the 90 000ms delay is used to make a full move of the motor ( it makes about 1 min 20 to do a full move)

So, here is my program :

const int bouton = 2;
const int cpos = 4;
const int cpluie = 5;
const int relais = 12;
const int ctemp = 0;
boolean etatbouton;
boolean etatcpluie;
boolean etatcpos;
float temperature;



void setup()
{
  pinMode(0, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(12, OUTPUT);
  
}

void loop()

{
 etatbouton = digitalRead(bouton);
 etatcpos = digitalRead(cpos);
 etatcpluie = digitalRead(cpluie);
 temperature = analogRead(ctemp);
 //////////////////////////////////////////////////////////////////////////
 
 if((etatcpos == HIGH ) && (etatcpluie == HIGH ) )
 
 {
    digitalWrite(relais, HIGH);
    delay(90000);
 }
 
 else
 
 {
     digitalWrite(relais, LOW);
 }
 //////////////////////////////////////////////////////////////////////////
 if(etatbouton == HIGH)
 
 {
    digitalWrite(relais, HIGH);
    delay(90000);
 }
 
 else
 
 {
    digitalWrite(relais, LOW);
 }
 //////////////////////////////////////////////////////////////////////////
 
 if((temperature >= 5.1) && (etatcpluie == LOW))
 
 {
     digitalWrite(relais, HIGH);
     delay(90000);
 }
  else if((temperature <= 3.8) && (etatcpos == HIGH) && (etatcpluie =! HIGH))
  
 {
     digitalWrite(relais, HIGH);
     delay(90000); 
 }

  else
  
 {
     digitalWrite(relais, LOW);
 }
//////////////////////////////////////////////////////////////////////////

}

I don't see any problems with it, so it seems to work really well, but when i try to put the components together, here start the troubles; I've followed this pan for the button, the positon sensor and the rain sensor because they all work like a simple button : gnd -------button---resistor------+5V
l
l
l
input pin

and it doesn't work, the relay work randomly, so if anyone can help me it would be awesome !

Why don't you get the sketch to tell you what it is doing?

Of course, you'll want to move your sensor away from pin 0.

(You've given your pins nice names, but you don't use them in setup() - why not?)

Pin numbers and those used in modes almost match.

const int bouton = 2;
const int cpos = 4;
const int cpluie = 5;
const int relais = 12;
const int ctemp = 0;

......

  pinMode(0, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(12, OUTPUT);

Oh yes, i didn't even notice that, i've worked on few versions of that "program", and u've sometimes changed the pind numbers to optimize the space on my breadboard, i will check that on wednesday, I apologize for disturbing people for someting stupid !

It would be better if you began by writing in words how you want the window to operate. Then begin coding. For example, it is usually better to have manual control over-ride automatic control (except when protection or safety are involved). So you would have...

If the button is pressed do manual control, otherwise do automatic control.

Also organize the logic to first decide if the window should be open or closed, then check if the window is in the desired position, and if not, operate the window.