LED OOK modulation to send binary information

Hey everybody,

I'm working on a project for which I need to send binary information modulated in On-Off Keying (OOK) with an LED. I've found a lot of information about PWM, but very few related to OOK, which is actually simpler than PWM.

So, here's my question: how can I achieve OOK modulation with Arduino? Is it as simple as calling digitalWrite(pin, HIGH) and digitalWrite(pin, LOW) for binary 0s and 1s respectively?

If so, what's the maximum frequency I could get using this method?

Thanks in advance,

Pol

If you access the ports directly you can change the state of the output in a single clock cycle. On a 16MHz Arduino you can output an 8MHz square wave.

The difficulty is going from "output square wave" to "send binary information".

Most weather station sensors use a 433Mhz wireless module that sends data using OOK so finding some examples of how they define 0 & 1 bits may be helpful and then substitute a LED for the RF module. I have attached the output of one such sensor. The long off hook is to signal the start of the message and then short off hooks are one’s and longer are zero’s. The signal is pulsed high for a short period between bits.

fungus:
If you access the ports directly you can change the state of the output in a single clock cycle. On a 16MHz Arduino you can output an 8MHz square wave.

Thanks for answering that fast. Could you explain a little bit more on the topic? I'm pretty new to Arduino.

fungus:
The difficulty is going from "output square wave" to "send binary information".

Though I'm not sure how to do this in Arduino (yet), I believe one way to do it would be to place the binary information in an array.
Then, I could read the array element-by-element, generating the "output square wave" with some condition.

Do you know the syntax to do so?

Regards,

Pol

Riva:
Most weather station sensors use a 433Mhz wireless module that sends data using OOK so finding some examples of how they define 0 & 1 bits may be helpful and then substitute a LED for the RF module. I have attached the output of one such sensor. The long off hook is to signal the start of the message and then short off hooks are one's and longer are zero's. The signal is pulsed high for a short period between bits.

Thanks for the answer. Do you know any examples of one of these weather station sensors?

Regards,

Pol

Google only lists 49 900 results for "Arduino Weather station OOK"

P0lDev:

fungus:
The difficulty is going from "output square wave" to "send binary information".

Though I'm not sure how to do this in Arduino (yet)

The same way as you'd do it in any other device.

IR remote controls are a good example of OOK. Use Google to find out how they transmit binary information to a TV.

Thanks to all of you for your answers.

fungus:
If you access the ports directly you can change the state of the output in a single clock cycle.

Before moving forward into "sending the actual binary information", I have to understand the basis of creating the output square wave.
What do you mean by "being able to access the ports directly"?

Regards,

Pol

P0lDev:
Before moving forward into "sending the actual binary information", I have to understand the basis of creating the output square wave.

It's not necessary, the two things aren't linked.

P0lDev:
What do you mean by "being able to access the ports directly"?

It's just the fastest possible way to do "digitalWrite()".

Untested code but the basic idea would be something like this…

const char message[] = {"Hello!"};
const byte outPin = 13;
const int beginDelay = 100;
const int zeroDelay = 50;
const int oneDelay = 25;
const int bitDelay = 10;


void setup() {
  Serial.begin(9600);
  pinMode(outPin,OUTPUT);
}

void loop() {
  digitalWrite(outPin,LOW);
  delay(beginDelay);
  Serial.println("Delay");
  for(int x = 0; x < sizeof(message) - 1; x++) {
    char a = message[x];
    Serial.print(x);
    Serial.print(" ");
    Serial.println(a);
    for (int y = 0; y < 8; y++){
      byte z = (a >> y) & 1;
      Serial.print(z);
      digitalWrite(outPin,HIGH);
      delay(bitDelay);
      digitalWrite(outPin,LOW);
      if (z == 0){
        delay(zeroDelay);
      }
      else {
        delay(oneDelay);
      }
    }
    Serial.println();
  }
  digitalWrite(outPin,HIGH);
  delay(bitDelay);
  digitalWrite(outPin,LOW);
  Serial.println("Finished.");
  while(1){
  }
}

EDIT: Added LA sample from above code.

Hello everyone,

It turns out that the other day, with all the #ArduinoDay stuff I was reminded of this forum. So… first things first, I’d like to thank you all for helping me write the code for the project I was working on at the time.

In the end, I got everything to work kinda perfectly with the following setup: two Arduinos, one with 2 LEDS, the other with 2 photodiodes, and each connected to a different laptop. When I write a text message in one of the laptops, it’s converted into ASCII binary and sent through an OOK modulation to the second board, which transforms the string back to text, showing the original message in the second laptop. The secondary LEDs and photiodes establish the comm protocol, such that the comm channel is kept open while the 2nd photodiode receives a constant signal from the 2nd LED.

Anyway, attached are the final code sketches for both the transmitter (“textSend.ino”) and the receiver (“textRead.ino”) and, in case you are interested in the topic, here’s the research project I wrote (whose experimental results are based on the Arduino project): http://coderagora.com/docs/research/

Thanks!

– Pol

textSend.ino (1.84 KB)

textRead.ino (7.26 KB)

Hi, i saw your project and i worked on something similar but now i am working on V2V using LEDs i was wondering if we could exchange information! Peace Ps if is possible i will leave you my contact here, just say something, thanks!

P0lDev:
When I write a text message in one of the laptops, it's converted into ASCII binary and sent through an OOK modulation to the second board, which transforms the string back to text, showing the original message in the second laptop.

Sounds like a marvellously obscure way to do something you could do via WiFi. :grinning:

P0lDev:
The secondary LEDs and photo-diodes establish the comm protocol, such that the comm channel is kept open while the 2nd photo-diode receives a constant signal from the 2nd LED.

Again, a rather involved way to do things.

The trick on a digital channel, is to merge supervisory ("2nd channel") information with the main stream. This is generally performed as part of the verification process, by using "sync" characters, "escape" sequences and sending data in "packets" with checksums.

In other words, if the channel is idle, you send a continuous stream of SYN characters (of some sort); when you have some actual data to send, you start a packet with a marker, size, the data and a checksum, close with more SYN and "escape" any SYN character appearing within the data.

The SYN stream of course verifies when the channel is "up".

POIDev I am really intertested in your project, will it work with an LDR?

Hmm, OP not been on forum for 4½ years, did not respond to lastreez' enquiry ... I don't think you are likely to get an answer.

So maybe I will give you one.

No, it won't.

P0lDev:
Hello everyone,

It turns out that the other day, with all the #ArduinoDay stuff I was reminded of this forum. So… first things first, I’d like to thank you all for helping me write the code for the project I was working on at the time.

In the end, I got everything to work kinda perfectly with the following setup: two Arduinos, one with 2 LEDS, the other with 2 photodiodes, and each connected to a different laptop. When I write a text message in one of the laptops, it’s converted into ASCII binary and sent through an OOK modulation to the second board, which transforms the string back to text, showing the original message in the second laptop. The secondary LEDs and photiodes establish the comm protocol, such that the comm channel is kept open while the 2nd photodiode receives a constant signal from the 2nd LED.

Anyway, attached are the final code sketches for both the transmitter (“textSend.ino”) and the receiver (“textRead.ino”) and, in case you are interested in the topic, here’s the research project I wrote (whose experimental results are based on the Arduino project): http://coderagora.com/docs/research/

Thanks!

– Pol

Hai POIDev, I’m really interested with your topic’s. Are your project is similar to VLC (Visible Light Communication)? Because i think your project is the implementation of VLC :)). Is there any furhter project with it? I think you know about Li-Fi (Light Fidelity) :slight_smile:

I've just found this and my first thought was "connect the LED to a serial port". Might need a bit more electronics, especially for the receiver, probably need to set the serial port at its lowest speed. Am I missing something? :confused: