I am using a Arduino Due. I am doing a project on Visible Light Communication. I need to convert a binary data into a PWM Signal. Can anyone suggest me a method of generating that PWM Signal based on the binary data given?

Thank You.


So, if you simplu has to convert the binary data to PWM signal there are few things you need to cover:

  1. If the binary data that you are receiving from the sensor is linear or non linear.

  2. What is the size of binary byte. Ex: int(16 bits),char(8 bits),long (32 bits).

  3. If it is linear, then if the data is multiplied by some number it will output a value betwen 0-255.

  4. If the data is not linear than you just need to create an giant array with the pwm intensite value direct without any particular mathematical function. Ex: array[1024] = {0,1,1,2,3,4,5,5,6,6,10,9,...}; (1024 values because if you are using analog input. Then you can direct output the values from array:

    analogWrite(3,array[x]); //x being your data

Here's the linear Example:

   //map(value, fromLow, fromHigh, toLow, toHigh);
    y = map(x, 0, 1023, 0, 255);

Doing this, y will receive a value from 0 to 255. You just need to first do a simple serial program that prints you through arduino serial window the binary data and see if the data increases or decreases conform your light project.

  • I don't know about your programming levels or if you are using a digital sensor or analog sensor, but if you are using a digital sensor, so you are probaly using SPI communication or i2c. Then you just need to read that binary data and take where the values bits are with bit wize manipulation.

    y=(x & (0xfff<<3))>>3;

Tell me more about the source of data, how this data is and how is the behavior of the data so i can help you a lot more. Thanks

| improve this answer | |

Count the amount of time a signal is high over a certain period, and use the ratio of on time to period as the duty cycle for the PWM signal.

| improve this answer | |

Rather than completely build everything from scratch, perhaps you can use some already tested and debugged Arduino library designed for free-space optical communication, such as

Practically all of these systems convert expand arbitrary binary data to structured "frames" or "packets" of information including some sort of checksum. Each packet is repeated several times; hopefully the receiver catches at least one of them. Each bit of the packet is expanded to either the "pattern representing a 0 bit" (typically turning the LED off for the full bit time) or the "pattern representing a 1 bit" (typically blinking the LED at 38 KHz for the full bit time, typically using a PWM).

To make the hardware and the software simpler and cheaper, most of these systems transmit only a few dozen bits per second. A few free-space optical communication systems are designed to run much faster, such as RONJA.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.