Código
//Projeto Relés por controle remoto
//EduArduino
#include <Servo.h>
#include <IRremote.h>
Servo motor;
int RECV_PIN = 11;
const int Rele1 = 2;
const int Buzzer = 12;
const int Rele2 = 3;
const int Rele3 = 4;
const int Rele4 = 5;
const int Rele5 = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
motor.attach(8);
pinMode(Rele1, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(Rele2, OUTPUT);
pinMode(Rele3, OUTPUT);
pinMode(Rele4, OUTPUT);
pinMode(Rele5, OUTPUT);
irrecv.enableIRIn(); // Inicia o receptor IR
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if (results.value == 0xFFA25D) {
digitalWrite(Rele1, HIGH);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);
}
if (results.value == 0xFF629D) {
digitalWrite(Rele1, LOW);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);
}
if (results.value == 0xFF22DD){
digitalWrite(Rele2, HIGH);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);
}
if (results.value == 0xFF02FD){
digitalWrite(Rele2, LOW);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);
}
if (results.value == 0xFFE01F){
digitalWrite(Rele3, HIGH);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);}
if (results.value == 0xFFA857){
digitalWrite(Rele3,LOW);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);}
if (results.value == 0xFF9867){
digitalWrite(Rele4, LOW);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);}
if (results.value == 0xFF6897){
digitalWrite(Rele4, HIGH);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);}
if (results.value == 0xFF18E7){
digitalWrite(Rele5, LOW);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);}
if (results.value == 0xFF30CF){
digitalWrite(Rele5, HIGH);
digitalWrite(Buzzer, HIGH);
delay(100);
digitalWrite(Buzzer, LOW);}
if(results.value == 0xFF42BD){
motor.write(0);
delay(100); }
if(results.value == 0xFF4AB5)
{
motor.write(90);
delay(100);
}
if(results.value == 0xFF52AD)
{
motor.write(180);
delay(100);
}
irrecv.resume(); // Receber o próximo valor
}
0 Comentários:
Postar um comentário
Assinar Postar comentários [Atom]
<< Página inicial