Please Help-IR TX RX

Hi,

I'm struggling with a project where I need to send a string from the serial monitor to an IR TX hooked up to an arduino, which is then sent to the IR RX (hooked up to a seperate arduino)

Attached below is images showing the hardware. I believe this is wired correctly, if not please inform me.

Below is the code for the transmitter. I must admit I am not a good prgrammer and have struggled to get to this point. I have read up on the code and sort of understand it.

int irtxPin = 9;

char* letters[] = {
  ".-", "-...", "-.-", "-..", ".", "..-.", "--.", "....", "..",     //Letters A-I
  ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",  //Letters J-R
  "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."          //Letters S-Z  
 };

char* numbers[] ={
  "-----", ".----", "..---", "...--", "....-", ".....", "-....",
  "--...", "---..", "----." //Numbers 0-9
 };

 int dotDelay = 200;
 
 void setup()
 {
   pinMode(irtxPin, OUTPUT);
   Serial.begin(9600);  //Set the communications speed between the Arduino board and the USB 9600 baud
 }
 
 void loop()
 {
   char ch;
   if (Serial.available())  //Constantly checks to see if any letters have been sent over the USB Connection and if the letter needs to be processed
   
   {
     ch = Serial.read(); //Reads a single letter
     if (ch >= 'a' && ch <= 'z')
     { 
       flashSequence(letters[ch - 'a']); //Flashes the LED to match the string that has been input
     } 
     else if (ch >='A' && ch <= 'Z')
     {
       flashSequence(letters[ch - 'A']);
     }
     else if (ch >='0' && ch <= '9')
     {
       flashSequence(numbers[ch - '0']);
     }
     else if (ch == ' ')
     {
       delay(dotDelay * 4);
     }
   }
 }
 
 void flashSequence(char* sequence)
 {
     int i = 0;
     while (sequence[i] !=NULL)
     {
       flashDotOrDash(sequence[i]);
       i++;
     }
     delay(dotDelay * 3);  //Gap between each letter
 }
 
 void flashDotOrDash(char dotOrDash)
  {
    digitalWrite(irtxPin, HIGH);
    if (dotOrDash == '.') 
    {
      delay(dotDelay);
    }
    else //must be a dash
    {
      delay(dotDelay * 3);
    }
    digitalWrite(irtxPin, LOW);
    delay(dotDelay);  //Gap between flashes
  }

The main issue i believe is the receiver. I have tried various tests but have got no where. Can anyone help how I can translate the morse back into a text string and output to the serial monitor.

Things to note are I am obviously using seperate serial cables. I have tried to test if i am even getting a signal (see code below-which i know is wrong because it wont compile)

int receiver = 8;

void setup()
{
  Serial.begin(9600);
  pinMode (receiver, INPUT);
}

void loop()
{
  digitalRead(receiver, LOW);
}
  if (receiver, HIGH)
  {
    Serial.println("Recieved");
    delay(100);
  }
}

I have spent weeks looking online and trying various things but it does not seem to be clicking. I really want to learn this but I may need a step by step guide (which I have looked for, but found nothing).

PLEASE HELP...

Any help is greatly appreciated as i need to hand a report in on this project to my college.

Cheers.

irtxrx_1.jpeg

Interesting project. Here are some thoughts:

  1. This code isn't happy:
  digitalRead(receiver, LOW);
}
  if (receiver, HIGH)

Correct code for digital read is:

   value = digitalRead(pin);

Correct code for testing for equality in an if statement is:

if (value == HIGH)

So this code needs tweaking to do what you want. Read the pin's state into a value variable (which you'll need to declare) and test that value in the if. Make it look exactly like the syntax in the examples. You can keep a few examples open for reference as you code.

  1. Once you can prove you're getting a receive stream, you can move on to matching morse. The basic idea is to capture the dit-dah pattern while waiting for a silent inter-character interval, then compare the captured dit-dah pattern to each item in the table you use to transmit morse until you find a pattern that matches. The character that owns that pattern is the character you process as received.

This is best done by organizing your code as a 'state machine', search for it, you'll find lots of examples, then write your own.

When I was a kid, I read a book about AI that talked about receiving Morse as an AI-class project. Now we do it on our Arduinos.

Good luck with your project.

-br

Edit: Here's some code that does Morse send and receive. It's torn out of a project, so it would need tweaking to work, but it might give you some ideas: bitlash/morseio.c at master · billroy/bitlash · GitHub
-- for your project you'd pretend the receiving IR was the keyer input.

Thanks for the response. On the receiever i am now using the following code (still not sure its right-especially the declare on value).

int pin = 8;
int value; 
void setup()
{
  Serial.begin(9600);
  pinMode (pin, INPUT);
}


void loop()
{
  value = digitalRead(pin);
{  if (value == HIGH)
  {
    Serial.println("Recieved");
    delay(100);
  }
}
}

what i have found now is that if i take a wire from the breadboard and put it to 5v on the reciever the serial monitor goes mad with the text "Receieved". Would this mean i have wired up incorrectly?

the images on the original post show the hardware.

I was expecting to transmit and then if receieved at the ir rx i would get the text "received" in the serial monitor.

I am completely confused by this.

Thanks again

That code looks great. Nice work.

what i have found now is that if i take a wire from the breadboard and put it to 5v on the reciever the serial monitor goes mad with the text "Receieved". Would this mean i have wired up incorrectly?

I am puzzled now, too. Take a wire from where to where? If what you are saying is that when putting +5V (also known as HIGH) into the receive pin, the receiver prints Received, isn't that victory?

Another way to test the receive code is to use an IR remote control as the transmit side...

-br

I meant from the ir rx.

No unfortunately it's not victory. I only want it to return Received if it receives an ir signal. At the moment I am not sending anything so I know it's incorrect.

Any other suggestions.

Many thanks

Apologies. Ignore that last comment. Something has clicked. That is what it is doing now because it is receiving something from the IR TX phototransistor. The IR RX is always receiving from the IR TX, I proved this by blocking the signal and then I got no result.

Now I need to interpret the morse that is sent from the IR TX Arduino. Thanks for the link in your first post.

Another question is, can I not use the char letters from the ir transmitter code but instead of just showing the dots and dashes say something like ".-" = "a" and then print the string to the serial monitor.

A separate question I have found links on dits and dahs and the code to receive. Can I apply this to dots and dashes I used in the IR TX code. For example in the codes I have found they specify dits and dahs can I change them for dots and dashes or does it matter. The only reason I ask this is because I have not referenced dits and dahs on the IR TX code.

Many thanks once again.

Bump

Victory! Now, as for your questions:

Another question is, can I not use the char letters from the ir transmitter code but instead of just showing the dots and dashes say something like ".-" = "a" and then print the string to the serial monitor.

Sure. That's what I meant by comparing the captured dit-dah pattern to your table.

A separate question I have found links on dits and dahs and the code to receive. Can I apply this to dots and dashes I used in the IR TX code. For example in the codes I have found they specify dits and dahs can I change them for dots and dashes or does it matter. The only reason I ask this is because I have not referenced dits and dahs on the IR TX code.

Dit and Dah are just amateur radio lingo for dot and dash. You can call them what you like. We use them because mastery requires learning the sounds of the letters: we learn R as didahdit, which it actually sounds like, not dotdashdot. Y is dadidada. And so on. You learn the code faster thinking in sounds instead of visual dots and dashes. But for your program it's up to you what to call them.

-br