phototransistor as input to serial port, speed problem

Hi,
I have a new project. I want to use an Arduino to read serial data that is being sent by an IR serial port at 9600 baud (by an electricity meter).

So I set up a test to see if I can send serial data from one Arduino to another using an IR LED and an IR phototransistor. See attached schematics.

After some tinkering I got this sort of working. However, I can only make it work at 2400 baud. When I try at 9600 baud I receive different characters from the ones I sent. Some bits seem to get lost / added / changed.

So I was wondering what the speed limiting factor is here. Do I need a phototransistor with a faster response? Is it the LED? Or something else?

The sketches are very simple:

//sending Arduino:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(13, 3, true); // RX, TX, inverse_logic

void setup() {
  Serial.begin(9600);
  Serial.println("starting...");
  mySerial.begin(2400);
}

void loop() 
{ 
  if (Serial.available()) 
  {
    mySerial.write(Serial.read());
  }
}
//receiving Arduino:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 3, true); // RX, TX

void setup() 
{
  pinMode(4, INPUT);
  Serial.begin(9600);
  Serial.println("starting...");
  mySerial.begin(2400);
}

void loop() 
{
  if (mySerial.available()) 
  {
    Serial.write(mySerial.read());
  }
}

Arduino_IR_serial_test - Schematic.pdf (30.7 KB)

http://optekinc.com/pdf/App%20Bulletin%20213-Opto%20Assemblies.pdf

or see if you can locate a "photo-Schmitt"

( Sorry, all , but -- ↑ ↑ ↑ the link has gone 'dead'. ↑ ↑ ↑ )

If I'm reading the datasheet for the phototransistor correctly, it gives 15us rise/fall time with a RL of 1k. How did you choose 10k for your circuit?

In a situation like this, 2 minutes with an $80 oscilloscope can save you hours of debugging time.

Ahaaaaa! so simple. With a 1k resistor it works perfectly! Thank you very much!
Not entirely sure why I chose a 10k. It was probably within reach and I considered it to be more like a pull-down and thought the value wasn't critical. :wink:

Problem solved!

BTW, I had tried this too; added a buffer transistor. The result was exactly the same as with just the phototransistor as in my schematics. It worked at 2400 baud but failed when I increased to 4800.
But thanks for trying to help!