/*
-Using IR receive to control LED and Servo motor.
The motor conrol the feeder.
IR Library by Ken S.
*/
#include <Servo.h> // add the Servo library
#include <IRremote.h> // add IR remote library
#include <LiquidCrystal.h> // add the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int recvPin = 13; // set the pin to receive the signal on
int blueLed = 9;
int greenLed = 8;
int yellowLed = 7;
IRrecv irrecv(recvPin); // defone the pin as a recv pin
decode_results results;
Servo myservo;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Fish feeder");
lcd.setCursor(0, 1);
lcd.print("Press 0 to start");
Serial.begin(9600); // starts the serial monitor
irrecv.enableIRIn(); // starts the receiver
pinMode(blueLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
}
/*
* Please get the IR Remote key values for button
* 1, 2 and 3 before continuing to the loop section.
* Tutorials on the IT Remote control LED lab on this site
* You can use the Hex values or convert them to binary
*/
void loop() {
//decodes the infrared input
if (irrecv.decode(&results)) {
Serial.println(results.value);
//switch case to use the selected remote control button
switch (results.value) {
case 16738455: //when button 0 is pressed
myservo.attach(10);
digitalWrite(blueLed, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Press 1 to feed"); // prints to LCD
Serial.println("start"); // prints to Serial monitor
break;
case 16724175: //when button 1 is pressed
myservo.write(180);
digitalWrite(greenLed, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Feeding...");
lcd.setCursor(0, 1);
lcd.print("Press 2 to stop");
break;
case 16718055: //when button 2 is pressed
myservo.write(-180);
digitalWrite(yellowLed, HIGH);
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fish fed...");
lcd.setCursor(0, 1);
lcd.print("Hit 0 to reset");
break;
default:
//digitalWrite(blueLed, HIGH);
digitalWrite(yellowLed, LOW);
break;
}
irrecv.resume(); // continue to the next value
}
delay(10);
}