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.