IR remote control issue

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

IR remote control issue

Post by BartSr »

Hi.
I found an interesting article about IR remote control with Samsung protocol.

http://techiesms.blogspot.nl/2016/01/ir ... iting.html

As the frequency of transmission is around 38 kHz I tried with several values (see the "x" in the code down below).
I hardcoded for this purpose the adress and data for switching TV ON/OFF.
Commands are sent continuously with timedelay in between.

This works; but sometimes yes, sometimes no.

Any suggestions how to get this more reliable?
I use the Arduino supplied from USB as well as 12V DC adapter

TIA
-Bart

code:

//#include <EEPROM.h>
int eaddr = 0;
#define ir_led 8
int address;
int data;
boolean bin[8], Data[32];
int k = 0;

int x = 0;

void setup()
{
Serial.begin(9600);
pinMode(ir_led, OUTPUT);
// address = EEPROM.read(0); // address is stored at address 0 of EEPROM
address = 7;
dec_to_bin(address); //convert the address into binary
for (int i = 0; i < 8; i++)
{
Data = bin;
Data[i + 8] = bin;
}
}

void loop()
{
for (int r = 1; r < 4; r++) // sending data from address 1 of EEPROM ; This loop will transmit 3 buttons data through IR
{
// data = EEPROM.read(eaddr + r);
data = 2;
dec_to_bin(data); //convert data into binary
for (int i = 0; i < 8; i++)
{
Data[i + 16] = bin;
Data[i + 24] = !bin;
}

for (int i = 0; i < 32; i++)
{
Serial.print(Data);
}
Serial.println();
x=115;
transmit(); //transmit
x=116;
transmit(); //transmit

x=117;
transmit(); //transmi
x=118;
transmit(); //transmit
x=119;
transmit(); //transmit

x=120;
transmit(); //transmit


delayMicroseconds(3100);
// delay(1000); // sending next data after 1 s
delay(8000); // sending next data after 1 s
}
}

void dec_to_bin(int dec) // converting decimal to binary
{
for (int i = 0; i < 8; i++)
{
bin = dec % 2;
dec = dec / 2;
}
}

void transmit()
{
Serial.print(x);

Serial.println();

burst(x); // start bit = 4500/26=173 --> 4500/38=118

digitalWrite(ir_led, LOW);
delayMicroseconds(4500); //start bit
for (int i = 0; i < 32; i++)
{
if (Data == 1)
{

burst(15);


digitalWrite(ir_led, LOW);
delayMicroseconds(1690); //high bit
}
else
{
burst(15);
digitalWrite(ir_led, LOW);
delayMicroseconds(560); //low bit
}
}
burst(15);
digitalWrite(ir_led, LOW); //stop bit
delayMicroseconds(560);

}



void burst(int pulses)
{
for (int i = 0; i < pulses; i++)
{
// 9 17
digitalWrite(ir_led, 1);
delayMicroseconds(9);
digitalWrite(ir_led, 0);
delayMicroseconds(17);
}



}
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest