Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This code designed to control the volume and power of an old stereo system via IR with an Arduino
- Compiled on Arduino 1.6.4
- Created with IRecord example of IRemote Library
- ALEXSHU.COM
- */
- #include <IRremote.h>
- int RECV_PIN = 10;
- int motor_A = 11;
- int motor_B = 12;
- int power_relay = 13;
- long last_vol_time = 0;
- long vol_timeout = 100;
- IRrecv irrecv(RECV_PIN);
- IRsend irsend;
- decode_results results;
- void setup()
- {
- Serial.begin(9600);
- irrecv.enableIRIn(); // Start the receiver
- pinMode(motor_A, OUTPUT);
- pinMode(motor_B, OUTPUT);
- pinMode(power_relay, OUTPUT);
- }
- // Storage for the recorded code
- int codeType = -1; // The type of code
- unsigned long codeValue; // The code value if not raw
- unsigned int rawCodes[RAWBUF]; // The durations if raw
- int codeLen; // The length of the code
- int toggle = 0; // The RC5/6 toggle state
- // Stores the code for later playback
- // Most of this code is just logging
- void storeCode(decode_results *results) {
- codeType = results->decode_type;
- int count = results->rawlen;
- // Serial.println(results->value, DEC);
- codeValue = results->value;
- codeLen = results->bits;
- }
- void vol_up(){
- digitalWrite(motor_A ,HIGH);
- digitalWrite(motor_B ,LOW);
- }
- void vol_down(){
- digitalWrite(motor_A ,LOW);
- digitalWrite(motor_B ,HIGH);
- }
- void vol_stop(){
- digitalWrite(motor_A ,LOW);
- digitalWrite(motor_B ,LOW);
- }
- void loop() {
- if (irrecv.decode(&results)) {
- storeCode(&results);
- if((codeValue == 2148467803) || (codeValue == 2148500571) || (codeValue == 379359532) || (codeValue == 2835546320) || (codeValue == 2964084060)){
- Serial.println("RED | Power");
- digitalWrite(power_relay ,HIGH);
- delay(100);
- digitalWrite(power_relay ,LOW);
- delay(400);
- }
- if((codeValue == 2148500572) || (codeValue == 2148467804) || (codeValue == 1064865324) || (codeValue == 1408794736) || (codeValue == 1064865324) || (codeValue == 104438857)){
- Serial.println("Green | Vol -");
- vol_down();
- last_vol_time = millis();
- }
- if((codeValue == 2148500573) || (codeValue == 2148467805) || (codeValue == 4223161638) || (codeValue == 2384381130) || (codeValue == 2467765715)){
- Serial.println("Yellow | Vol +");
- vol_up();
- last_vol_time = millis();
- }
- irrecv.resume(); // resume receiver
- }
- // Volwatchdog
- if(millis() - last_vol_time > vol_timeout) {
- vol_stop();
- codeValue = 0;
- }
- codeValue = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement