- Get link
- X
- Other Apps
Connections:
Infrared Receiver+ > 5v rail
Infrared receiver- > GND rail
Infrared Receiver Data > pin 11
3 LEDs+ with 330ohm resistor each > on one row with pin 9
3LEDs- > negative rail
Green LED+ > resistor 330ohm > pin 7
Green LED- > negative rail
Red LED+ > resistor 330ohm > pin 8
Red LED- > negative rail
5V Arduino > positive rail
GND Arduino >GND Rail
Code:
#include <IRremote.h> int IR_RECEIVE_PIN = 11; // Receive on pin 11 decode_results results; int ledPin = 9; int ledState = 0; int ledBright = 0; int redPin = 6; int greenPin = 7; void setup() { Serial.begin(9600); IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver, enable feedback LED, take LED feedback pin from the internal boards definition pinMode(ledPin,OUTPUT); pinMode(greenPin,OUTPUT); pinMode(redPin,OUTPUT); } void loop() { if (IrReceiver.decode()) { Serial.println(IrReceiver.decodedIRData.decodedRawData); // Serial.println(ledState); Serial.println(ledBright); if (IrReceiver.decodedIRData.decodedRawData == 1621096200){ if (ledState == 1){ if(ledBright <255){ ledBright = ledBright + 85; analogWrite(ledPin,ledBright); }}} if (IrReceiver.decodedIRData.decodedRawData == 1754789640){ if (ledState == 1){ if(ledBright > 0){ ledBright = ledBright - 85; analogWrite(ledPin,ledBright); }}} if (IrReceiver.decodedIRData.decodedRawData == 1788213000){ if (ledState == 0){ digitalWrite(redPin,LOW); digitalWrite(greenPin,HIGH); ledState = 1; } } if (IrReceiver.decodedIRData.decodedRawData == 1721366280){ if (ledState == 1){ digitalWrite(greenPin,LOW); digitalWrite(redPin,HIGH); digitalWrite(ledPin,LOW); ledState = 0; ledBright = 0; } } IrReceiver.resume(); // Continue receiving } }
- Get link
- X
- Other Apps
Comments
Post a Comment