Hi! Everyone.
#include <Servo.h>
#include <IRremote.h>
#define RECV_PIN 8 //IR Receiver
boolean turnon;
IRrecv irrecv(RECV_PIN);
decode_results results;
int lightPin = 0; //Photoresistor
int ledPin1 = 7; //Kitchen
int ledPin2 = 6; //Bedroom 1
int ledPin3 = 5; //Bedroom 2
int ledPin4 = 4; //Corridor
int ledPin5 = 3; //Living
Servo window;
Servo door;
Servo elevator;
int position;
void setup()
{
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
turnon=0;
irrecv.enableIRIn();
window.attach(0);
door.attach(1);
elevator.attach(2);
}
void loop()
{
if (irrecv.decode(&results))
{
switch(results.value)
{
case 0x1FE708F:
window.write(180);
Serial.print("Window open");
break;
case 0x1FE9867:
window.write(0);
Serial.print("Window close");
break;
case 0x1FEF00F:
door.write(90);
Serial.print("Door close");
break;
case 0x1FEB04F:
door.write(0);
Serial.print("Door open");
break;
case 0x1FE30CF:
elevator.write(0);
Serial.print("Elevator up");
break;
case 0x1FE00FF:
elevator.write(180);
Serial.write("Elevator down");
break;
case 0x1FE48B7:
digitalWrite(ledPin1,HIGH);
digitalWrite(ledPin2,HIGH);
digitalWrite(ledPin3,HIGH);
digitalWrite(ledPin4,HIGH);
digitalWrite(ledPin5,HIGH);
Serial.print("Lights on");
break;
case 0x1FE7887:
digitalWrite(ledPin1,LOW);
digitalWrite(ledPin2,LOW);
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,LOW);
digitalWrite(ledPin5,LOW);
Serial.print("Lights down");
break;
}
}
if (irrecv.decode(&results))
{
delay(10);
irrecv.resume();
}
int reading = analogRead(lightPin);
if(reading < 1000)
{
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
}
else if(reading >= 1000 && reading < 1300)
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
}
delay(100);
}
Help!
I have 2 problems with the code I wrote:
I've been trying to get the elevator to work, but I failed, when I connect my computer to the Arduino servo moves slowly without stopping, and when I press a button on the IR control is still moving but faster. I want to make the elevator go up and down by pressing a button with another. PS: The servo is continuous rotation / 360°.
I have a photoresistor, but I also want a LED to turn on when I pressed a button and disable or turn off the photoresistor.
Help, I've been a long time trying to make it work and I failed.
I use Arduino Leonardo, Breadboard, one servo continous rotation, two servo standard rotation, five leds 5v
Thank you.