Converting binary input into decimal

(deleted)

Using pure PWM is not going to be easy, have a look at Manchester encoding for a starter.

The “VirtualWire” library might be another possibility.

I don't know why you'd want to subject yourself to all that grief. A photoresistor is a rather slow acting device, and if your path isn't protected from stray light variations, you might suffer a lot of errors. If the distance between these arduinos is short, just use software serial, and wire. Otherwise, you could buy a couple of OOK transceivers (very simple, very cheap, look on EBay) which could give you more range and far better interference rejection that a laser solution.

As for sending binary, and interpreting it as decimal, google up the union structure in C++. It does a wonderful job of making data conversions simple.

(deleted)

Why not use a serial port to connect the laser and phototransistor as a simplex laser modem?

Pretty much all serial communication is made up of ones and zeros.

As others have suggested, you can just treat the laser like a normal serial communication. You might need to use a slow baud setting if your LDR has a slow response time.

Decimal and hexadecimal are ways to display numbers to make them easier for us humans to read. Computers and microcontrollers store all numbers in binary. One generally doesn't "convert" binary to decimal. Decimal is just one way of displaying the number.

jrdoner:
As for sending binary, and interpreting it as decimal, google up the union structure in C++. It does a wonderful job of making data conversions simple.

If you want to receive decimal, try using a 2-out-of-5 code.

Hi,

This whole project isn't about practicality, its more or less a project that i am working on "because I can".

Good on ya mate..
Even just getting the RX arduino respond to the Tx On and Off, will be a good start.

If you do this in stages you will learn a lot about arduino and comms systems.
I agree with the use of a phototransistor instead of an LDR, but if you do use and LDR it will show you how slow they are and probably help debug any problems development, because it will be at slow speed.

Tom...... :slight_smile:
(I think we need to keep that quote in mind, Jdp8y is aiming to learn, the optimization will come later..)

Get phototransistors, they’re fast.

Why re-invent serial? The laser and detector are binary, just wire them to serial pins and use the working serial software you already have.

You do know that you are liable for any damages that laser may do? Keep it away from where eyes might get. And btw, an IR led and detector can likely do the job more safely. Just choke down the view of the detector to where the only IR it sees is that led.

Jdp8y:
Hello! I am using two arduino uno's, i plan on having a means of (impractical) communication between the two. I plan one using a Photo resistor on one arduino and a laser on the other, through the laser it will send data to the photo resistor via PWM. or by simply turning the laser on and off. I need a way to decrypt the oncoming binary data and have it displayed on a lcd.

Based on your statement "because I can" I would suggest you separate and treat different task separately.
( There is a fancy layered approach to this everybody talks about and nobody uses )
As mentioned - you already have means to "send" data to I/O pins using ASCII code.
ASCII code can be made error detecting (parity) and error correcting (CRC).
Converting such modified code into ANY transmission media is a different task - basically hardware application - laser ( transmitter) plus appropriate detector (receiver) which does not care about the data format ( ASCII with parity and CRC in my example).

The key is to keep these tasks cooperating, ether on hardware level or in software.

And of course you need to decide up front what these tasks will do.
You decided to use laser and already have received suggestion to use different hardware for valid safety reasons.

Sure receipt for never finishing the project - decide one method and stick to it.

BTW in is not cast in stone that ASCII has to be ones and zeroes only - high speed modems (phase / star) coding is a good example. ( little OT here )