I've setup two Arduinos connected via an optocoupler on a breadboard.

One Arduino is a sender and sends pulses to the optocoupler causing the diode to turn on.

When this happens the other Arduino has it's input connected to the emitter. This is interpreted as 1 on the receiver side. Or if the diode is off it's a 0 on the receiver side.

My problem is getting them to sync. I'm currently using delay which I'm starting to realize is a horrible idea since they go out of sync after about 2 characters have been sent. So I wonder are there any better solutions to syncing them?

closed as unclear what you're asking by gre_gor, sempaiscuba, per1234, Greenonline, Juraj Dec 2 '18 at 15:01

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    UART. Either software or hardware. – Majenko Nov 30 '18 at 20:16
  • 2
    What are you trying to sync? I would think the optoisloator setup is how to synchronize two devices which are galvanically isolated. – jose can u c Nov 30 '18 at 20:23
  • 5
    is there a reason for trying to "re-invent the wheel"? There are multiple protocols already in place that can be used( UART, I2C, SPI) And they all can be optically isolated if there is a need for that. – Chad G Nov 30 '18 at 21:55
  • what do you mean by sync? ...... what function are you trying to synchronize? .... you may be overthinking this – jsotola Dec 1 '18 at 20:31

In order to synchronize two deices transmitting any information you need a CLK signal. CLK stands for clock so basically you send a 1 each time you want to send a bit of data. But in order to do so you need one more wire and a CLK generator (usually the transmitter). It is described very well in the video of Ben Eater about Reliable data transmission. So I recommend you watching the video since Ben covers a lot of important topics on data transmission and shows a arduino example of how to transmit and receive data properly.

  • 1
    You only need a discrete CLK signal for synchronous serial communication. For asynchronous the timing is defined by both ends of the link separately and the have to agree within certain tolerances. – Majenko Dec 1 '18 at 10:37

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