ADVERTISEMENT
Infrared extender over Ethernet with arduino |
This is an extension of my previous post on IR blasters with raspberry pi and many general points like increasing the power output with a transistor is applicable here as well. So basically this circuit picks up infrared signals from any remote controls and send these raw data to the remote end and the arduino over there will emit it to control the target device. To make it simple and universally applicable, i used raw infrared patters and is relayed. The library involved can decode different popular formats which can add extra feature. Furthermore in this design, the target transmitter can be accessed with a browser and by passing ir codes as a url parameter, any infrared device can be controlled from a simple web browser as well. So there is a lot of possibilities to play around.
To get it running, you need two arduinos and ethernet shields. The first one acts as a server which is placed near the device to be controlled. The output is taken from pin 3 of the arduino and is connected to the IR led ( or via a transistor as shown here)
The source code for the ir extender is available here.
Load this sketch to the server arduino
/Sending ir codes over ethernet
//This sketch accept IR from an IR sensor connected to Pin 6 and sends over IP
// parts of the code for storing ir in to buffer is from Ken Shirriff's ir recorder http://arcfn.com
//
// THIS ONE PICKS IR FROM A REMOTE
//
#include <IRremote.h>
#include <SPI.h>
#include <Ethernet.h>
int RECV_PIN = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;
// Network settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC
byte gateway[] = { 192,168,0,1 };// Gateway
byte ip[] = { 192,168,0,123 }; //ip if dhcp fails
// IP of the Target arduino with ir emitter
IPAddress server(192,168,0,102);
EthernetClient client;
unsigned int rawCodes[RAWBUF]; // The durations if raw
int codeLen; // The length of the code
//Get the infrared codes from remote
void storeCode(decode_results *results) {
int count = results->rawlen;
Serial.println("Received code");
codeLen = results->rawlen - 1;
for (int i = 1; i <= codeLen; i++) {
if (i % 2) {
// Mark
rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
Serial.print(" m");
}
else {
// Space
rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
Serial.print(" s");
}
Serial.print(rawCodes[i - 1], DEC);
}
Serial.println("");
}
void setup()
{
// For debug
Serial.begin(9600);
// Start ethernet
Ethernet.begin(mac, ip, gateway);
Serial.println("Initialised");
}
//sending the raw IR code over the ether net
void sendIR()
{
// Send over HTTP
if (client.connect(server, 80))
{
client.print("GET /");
for (int i = 0; i < codeLen; i++) {
client.print(rawCodes[i]);
}
client.println(" HTTP/1.1");
client.println("Host: 192.168.0.101");
client.println();
client.println();
client.stop();
}
}
void loop()
{
if (irrecv.decode(&results))
{
storeCode(&results);
sendIR();
irrecv.resume(); // Receive the next value
}
}
Now make sure that you set the ip address as a value which mach your sub-net i.e first three groups. Now navigate with your browser to make sure that the transmit end is up and running.
To make the IR accepter, a second arduino is hooked with an ir receiver to pin 6 (refer to previous post for pin connection) and load the receiver sketch and point your remote to it. The signals will be send to the server and will be relayed over there to target ir device.
//Sending ir codes over ethernet
//This sketch accept IR from an IR sensor connected to Pin 6 and sends over IP
// parts of the code for storing ir in to buffer is from Ken Shirriff's ir recorder http://arcfn.com
//
// THIS ONE PICKS IR FROM A REMOTE
//
#include <IRremote.h>
#include <SPI.h>
#include <Ethernet.h>
int RECV_PIN = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;
// Network settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC
byte gateway[] = { 192,168,0,1 };// Gateway
byte ip[] = { 192,168,0,123 }; //ip if dhcp fails
// IP of the Target arduino with ir emitter
IPAddress server(192,168,0,102);
EthernetClient client;
unsigned int rawCodes[RAWBUF]; // The durations if raw
int codeLen; // The length of the code
//Get the infrared codes from remote
void storeCode(decode_results *results) {
int count = results->rawlen;
Serial.println("Received code");
codeLen = results->rawlen - 1;
for (int i = 1; i <= codeLen; i++) {
if (i % 2) {
// Mark
rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
Serial.print(" m");
}
else {
// Space
rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
Serial.print(" s");
}
Serial.print(rawCodes[i - 1], DEC);
}
Serial.println("");
}
void setup()
{
// For debug
Serial.begin(9600);
// Start ethernet
Ethernet.begin(mac, ip, gateway);
Serial.println("Initialised");
}
//sending the raw IR code over the ether net
void sendIR()
{
// Send over HTTP
if (client.connect(server, 80))
{
client.print("GET /");
for (int i = 0; i < codeLen; i++) {
client.print(rawCodes[i]);
}
client.println(" HTTP/1.1");
client.println("Host: 192.168.0.101");
client.println();
client.println();
client.stop();
}
}
void loop()
{
if (irrecv.decode(&results))
{
storeCode(&results);
sendIR();
irrecv.resume(); // Receive the next value
}
}
Hello
ReplyDeleteif you can help me to decode. I load the sketch IRrecvDump and i catch this signal
Raw: (31) 3028, -1024, 1048, -2968, 968, -3024, 964, -3028, 2948, -1024, 1044, -2972, 964, -3028, 964, -21156, 3024, -1028, 1052, -2964, 960, -3032, 968, -3024, 2940, -1032, 1048, -2972, 964, -3028, 964,
Now how to replay this with Arduino and IR Led ?
Please help
thanks
Hello
ReplyDeleteI can' get the IR LED to send the code. On the repeater side the serial monitor prints:
Tester ethernet
Testing IR over ethernet
GET /8009501700185080095017001850170095080095080095080095085018001700 HTTP/1.1
0
Sent IR signals from LED at Pin 3 (PWM)
The variable "counter" remains on 0.
Can anybody help me?