// Définition des variables et des constantes
const int out1 = 5; // Arduino pin 5 connecté au relay 1
const int out2 = 6;
const int out3 = 7;
const int out4 = 8;
void setup(){
pinMode(out1, OUTPUT); // initialize the digital pin as an output
pinMode(out2, OUTPUT); // initialize the digital pin as an output
pinMode(out3, OUTPUT); // initialize the digital pin as an output
pinMode(out4, OUTPUT); // initialize the digital pin as an output
Serial.begin(9600); // Serial Port initialization
}
Projet 4 – Domotique lumineuse
Le code :
int sensorPin = 0; //analog pin 0
// Définition des variables et des constantes
const int out1 = 5; // Arduino pin 5 connecté au relay 1
const int out2 = 6;
const int out3 = 7;
const int out4 = 8;
void setup(){
pinMode(out1, OUTPUT); // initialize the digital pin as an output
pinMode(out2, OUTPUT); // initialize the digital pin as an output
pinMode(out3, OUTPUT); // initialize the digital pin as an output
pinMode(out4, OUTPUT); // initialize the digital pin as an output
Serial.begin(9600); // Serial Port initialization
}
void setRelay(int relay, int value)
{
if(relay > 0 && relay < 5) digitalWrite((relay + 4), value);
}
void loop(){
int val = analogRead(sensorPin);
Serial.println(val);
//délai d’attente
delay(100);
if(val<30){
setRelay(1, 1); // on active le relai n°1
Serial.print(« Relay 1: actif « ); // quand le relais 1 est en »1 », le courant passe
}
else{
setRelay(1, 0); // on désactive le relai n°1
Serial.print(« Relay 1: inactif « ); // quand le relais 1 est en »1 », le courant passe
}
}
Ressources :
http://www.microbot.it/en/product/62/Relay-Shield.html
http://www.microbot.it/documents/mr007-002_datasheet.pdf
http://www.microbot.it/sketches/Relay_Shield_test_sketch.ino
http://www.glacialwanderer.com/hobbyrobotics/?p=9