Generate 38KHz ...


I'm trying to make a service for manage infrared remote code, And i need do generate pulse at 38KHz.

I've tryed to do this ( see the code ) , but it's really slow . Can someone give me a method to do that ?

private void sendIr(int period){
		if (irOutIsConnected){
			int time = (int)((1.0 / frequency) * 1000 / 2);
			int currentPeriod = 0;
			while (currentPeriod < period){ 
				try {
					arduino.digitalWrite(irOutPin, 1);
				} catch (InterruptedException e1) {
					// TODO Auto-generated catch block
				try {
					arduino.digitalWrite(irOutPin, 0);
				} 	catch (InterruptedException e) {
					// TODO Auto-generated catch block
				currentPeriod += (2 * time);
				System.out.println("currentPeriod" + currentPeriod);
			System.out.println("ERROR : IR Out Pin isn't connected !");

Frequency = 38 ( in Khz ), and Period is a int that containt duration of the pulse in microseconds .

So for 38KHz, i must do during the period time, loop "pin high for 13 microseconds, pin low for 13 microseconds"

Thx for your help


GroG's picture

Hi BeetleJuice !You always

Hi BeetleJuice !

You always come up with great ideas !  But yes - Java control of the 38Khz is not very effecient.

It would be better to have a function in MRLComm to pulse a digital line @ 38 Khz - and use the Java to send data to encode over the 38Khz !

What IR device are you trying to control first?

beetlejuice's picture

Hi, I want to control all IR


I want to control all IR device !

I would like to make a service like the irRemote library for arduino . The goal is to make a king of universal remote that can send IR code for different frequency with different protocols .

For exemple, my adsl TV box use the protocol NEC at 38Khz , My robosapiens (v1 and v2 ) work with their own protocol at 39,2Khz .

I can already add few protocol because they are in the irRemote library for arduino ...

The service must also be able to receive IR signal for learn IR codes that we don't know ( raw codes )

This is very nice for control home hifi,tv,ect ... But also if we want to use personal signal on marker in a room  to help mobile robot to localise where he is ( triangulation ) ...

Before try to make the service, i've tested directly in the arduino, and it work very well .

I put that i've made at this time, in my home folder on gitub . Chek the files "" and . For now, just robosapien protocol is wrote ...


beetlejuice's picture

I think the good way is to

I think the good way is to put the functions mark() and space() in MRLcomm.ino , or better, we can send to MRLcomm.ino, the raw datas ( int[] data ) buid like this " period, 1 or 0, period, 1 or 0, etc " .

1 or 0 mean HIGH or LOW .

The next step will be in the way arduino -> MRL . So MRLcomm.ino will also need a function to return raw value from the ir receiver .

And why not finish with make a gui .... ( But i know nothing about that . I will learn ! )

GroG's picture

This is a great idea

This is a great idea Beetlejuice !

I like it a lot.  I will help, but I have a few things on the TODO list before.  

The big thing is to finish the MRL API - which will be the base of all future WebGUI and remote communicaton with MRL.

Brilliant Beetlejuice.

PS - learn JQuery & Angular :)