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 !