/*Configuring Circuit to Open and close the Doors by using IR Remote, IR Receiver and Servo Motor.
Configuring circuit to Turn ON Lights of different rooms by using IR Remote and NeoPixel LED.
Configuring circuit to Turn ON the emergency Blinking Lights by using IR Remote, IR Receiver and NeoPixel LED.
First we will create a circuit and write a Program to perform action on Servo Motor by using IR Remote and IR Receiver in Wokwi.*/
//NOTE- Install few library in Library Manager
#include <IRremote.h> //Infrared remote library
#include <Servo.h>
#include <FastLED.h>
CRGB leds[0];//function of FastLED library which is used to define color as RGB format
int pin_receiver = 2;
int button_value = 0;
int bright = 20; //brightness of the lights
Servo myservo1;
IRrecv receiver(pin_receiver); //receiver is variable
void setup()
{
receiver.enableIRIn(); //for enabling the IR receiver functionality
myservo1.attach(10);//pin no. 10
Serial.begin(9600);
FastLED.addLeds<NEOPIXEL, 3>(leds, 1); //3 is the terminal(pin number); connected to 1st NeoPixel LED
}
void loop()
{
if (receiver.decode()) //to check the receiver's unique code from IR Receiver
{
translateIR();
receiver.resume(); //will help to continue listing the signals for the IR receiver.
}
}
void translateIR()
{ //below is variable with the unique code as per the button pressed on IR remote.
button_value = receiver.decodedIRData.command;
if(button_value == 226) //menu button
{
Serial.println("Forward - Driver Door opens, Backward - Driver Door Close, 1 - Lights ON in RED, 2 - Lights ON in Green, 3 - LIGHTS ON in Blue Color, 4 - Blinking LED, Play - Control LED Glow, 9 - All stops");
}
if(button_value == 224) //forward button
{
myservo1.write(0);
Serial.println("Door Closed");
}
if(button_value == 144) //backword button
{
myservo1.write(180);
Serial.println("Door Open");
}
if(button_value == 48) // button 1
{
leds[1] = CRGB::Red;
FastLED.show();
}
if(button_value == 24) // button 2
{
leds[1] = CRGB::Green;
FastLED.show();
}
if(button_value == 122) // button 3
{
leds[1] = CRGB(7, 7, 189);
FastLED.show();
}
if(button_value == 16) // button 4- blinking Neopixel
{
for (int i = 0; i<=20; i++)
{
leds[1] = CRGB(11, 142, 125);
FastLED.show();
delay(50);
leds[1] = CRGB(233, 255, 34);
FastLED.show();
delay(50);
leds[1] = CRGB(255, 0, 191);
FastLED.show();
delay(50);
}
}
if (button_value == 168) //play button- increase brightness on each click
{
bright = bright + 40;
FastLED.setBrightness(bright);
FastLED.show();
}
if(button_value == 162) // button 9
{
Serial.println("Application Stopped");
myservo1.write(90);
FastLED.clear();
FastLED.show();
}
}