Can someone help me write a code to run a relay module that will go on for one second and off after i press a button on any ir remote.im using an arduino uno,ir receiver and a relay module.i just need it to see any ir remote when i press a button to activate relay for a second then off again.im not good at writing code still and i have tried for days now.any help would be greatly appreciated! thx
i have tried for days
Show us what you have tried.
here's my code i have tried
#include <IRremote.h>
int IRpin = 11; // pin for the IR sensor
int relay = 8; // LED pin
IRrecv irrecv(IRpin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(relay, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
}
if (results.value > 0) // change zero to your IR remote button number
{
digitalWrite(relay, HIGH);
delay(1000); // keeps the transistion smooth
}
else
{
digitalWrite(relay, LOW);
}
}
#include <IRremote.h>
int IRpin = 11; // pin for the IR sensor
int relay = 8; // LED pin
int flag;
IRrecv irrecv(IRpin);
decode_results results;
void setup()
{
flag=0;
irrecv.enableIRIn(); // Start the receiver
pinMode(relay, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results)) {
if (results.value =0xFF42BD) // replace the 0xFF42BD with the result you get
{ if (flag==0)
{ //your code here
flag = 1;
}
else
{
// your code here
flag = 0;
}
}
irrecv.resume();
}
}
Upload the following code, point your remote control at your receiver
to get the hex code
after that, replace it with 0xFF42BD above
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}