Optical communication using the RGB LED

It got me thinking after reading this post:

Is it actually possible to do communication between two Arduboys using just the RGB LED? Turns out, yes!

It doesn’t work well if the room is too bright and the protocol I designed is far from perfect but as a proof of concept it works well. Data communication works in both directions simultaneously too. Not suitable for a real time multiplayer game (unless you tape them together) but still neat!

Code on Github here:


Well done!

As is, it could be useful for turn based games where information is transferred only after each move. Chess, poker, battleship, etc. It would save effort over each player having to manually enter the other player’s info. If the info on each screen has to be hidden from the other (poker or battleship) you would make sure to blank the screen during transfers.

Maybe also to exchange secret information. E.g. competition hangman:
Each player picks a word for the other player to solve. The words are exchanged then the race is on to see who solves it first. For two players, there’s not much advantage over just exchanging units themselves to enter the word but if it were a 3 or more way competition you wouldn’t have to enter the same info on more that one unit.

It could be used to keep high scores in sync between units for a particular game, or even all of EEPROM to “clone” two units.

I should point out here that if this kind of thing ends up requiring that units be uniquely identified, keep in mind that there’s a 16 bit unit ID stored in system EEPROM. It can be read and written using readUnitID() and writeUnitID() and also set using the SetSystemEEPROM example sketch in the Arduboy2 library.


3 posts were merged into an existing topic: Why not making a LAN game?

You could make a 3D printed dock that holds the two Arduboys with the LEDs aligned and masks out any stray light. Would look like a toaster (but only cooking the lower 1cm of the Arduboys!).

1 Like

Would a cable made of optic fiber would work?

1 Like

I suggested that in the post that provided the inspiration.

1 Like

I bought a length of cheap optical fibre from Ebay and tried to use it to get the two Arduboys to communicate but was unable to get it to work reliably. Perhaps because it was cheap it was diminishing the strength of the LED too much.

fantastic )
I understand the led blinking
but what is acting as a light-receiving sensor?
as far as I know, there are no such as the element in standard arduboy

by the way I’m experimenting in storing the game code at mifare 4/8k cards and reading them the same way as cartridges.
it works ) hope to implement this in Little Game Engine for ESPboy next week.

If you program the LED pin as input then it will effectively be a light sensor like in @MLXXXp’s sketch:

So in my demo it rapidly switches between input and output to communicate with another Arduboy.

Just a speculation but would the Green LED be more suseptable to input from the Green light or am I just not understanding the physics here

I tried the green and blue LEDS as light sensors (with white light), neither was anywhere near as sensitive as red.

I think you’re thinking of humans.

Humans can detect more shades of green than any other colour,
but that’s because of the balance of rods and cones in the human eye (or something like that),
it’s not a general property of light.

(Fun fact: chickens can actually see more colours than humans.)


I would speculate that would be down to the lower forward voltage / band gap for red LEDs. IR LEDs have even lower Vf so if you are ever in a strange situation of having your choice of LEDs but no photodiodes, perhaps they’re the ones to pick. Harder to debug though!


Not to bump off topic too far but has anyone tried using the speaker as a mic for audio/ultrasonic data transfer?

I had a look at this before but unfortunately the speaker pins cannot be used for analog input.

Piezo produces high voltage spikes if there’s high impedance, so wondering if it would be possible to use it as digital. Even On-Off-Keying perhaps.

In my test when I tried using the speaker pins with digital input if I knocked the Arduboy on the desk then it detected a change in voltage. :slight_smile:

1 Like

So you have a way to password lock your Arduboy and unlock with a secret knock/tap sequence. I suppose it’s not too much of a stretch to say you have “fingerprint unlock” available on Arduboy!

Whats the effective bit rate?

In the demo it is 50 bits per second: an interrupt runs at 200hz but it takes 4 cycles to switch between input/output.

It starts to get unstable when increasing the update rate but it might be possible to get better results if you had something block out the ambient light like an optical fibre cable and a custom housing around the LED.

It also just occurred to me that if the green and blue LEDs are also capable of detecting light changes then you might be able to use them to have additional channels. E.g. maybe one Arduboy uses red for send and green for receive and the other uses red receive and green send.