Monday, 16 September 2013

Arduino Morse Code Sender/Receiver pair using lasers

I've spent some playing with my Arduino's on behalf of http://opencomputerscience.co.uk/. They are running computing sessions for under 16s/18s. One of my ideas was to set a challenge using Arduinos - create a communication system which can cross a considerable distance (say >30m). This would probably involve two Arduino's.

Here is one way of doing this where the LED on the sending board is actually 6mm brass housed Laser Diode (I managed to get 30 for 7 quid including P&P):
I got mine from ebay seller newdaystart
http://www.ebay.co.uk/itm/140963232227?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

Description:
30pcs per lot 650nm 6mm 3V 5mW Laser Dot Diode Module Red Copper Head




The sender board uses Eric Linder's Morse library taken from:
https://code.google.com/p/arduino-morse/issues/detail?id=1
Note that it is necessary to replace WProgram.h with Arduino.h in both the morse.cpp and the morse.h files.

The Arduino sketch used for sending:

#include

// Author Erik Linder
// Released 2011 under GNU GPLv3
//
// Usage: morse( , , <1 0="PTT" beep=""> )
//        sendmsg( "" )
//

#include

// Uncomment to beep a speaker at pin 9
//Morse morse(9, 12, 1);

// Use pin 13 (built-in LED of Arduino 2009)
Morse morse(13, 12, 0);

void setup()
{
  Serial.begin(9600);
  // Nothing here for the Morse lib
}

void loop()
{
  morse.sendmsg("HELLO WORLD!");
  delay (2000);
}


On the receiver end, no special libraries required - it's just an LDR and a resistor into one of the Analogue pins on the Arduino:

int LDR_Pin = A0; //analog pin 0
int led = 13;
//Maximum reading from the LDR with laser on.
int LDR_Maxvalue=1000;
int dot_length=800;
int dash_length=2500;
int letter_pause=2400;
//#include

//LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// 10k between GND and A0
// LDR between 5V and A0


void setup(){
  Serial.begin(9600);
  pinMode(led, OUTPUT);  

 // lcd.begin(16,2);
  
}
int counter_high = 0;
int counter_low = 0;

void loop(){

  int LDRReading = analogRead(LDR_Pin); 
//  Serial.println(LDRReading);
  if (LDRReading >= LDR_Maxvalue){
  counter_high++ ;
   if ( counter_low > 0 ){
//     Serial.print("Low\t");
//     Serial.print(counter_low);
//     Serial.print("\n");
   }
   if ( counter_low >= letter_pause) {
      Serial.println();
  //    lcd.clear();
  //    lcd.setCursor(0, 0);

  }
      
     counter_low=0;
     digitalWrite(led, HIGH);

  
  } else {
//   Serial.print(".");
  counter_low++;
  if ( counter_high > 0 ){
//      Serial.print("High\t");  
//   Serial.print(counter_high);

  }
  if ( (counter_high <= letter_pause ) &&( counter_high >=dot_length)){
//      Serial.print(counter_high);
    Serial.print(".");
  //  lcd.print(".");
  }
  if ( counter_high > letter_pause ){
 //         Serial.print(counter_high);
        Serial.print("-");
    //    lcd.print("-");
  }

      counter_high=0;
      digitalWrite(led, LOW);

  }



}

All codes used are available for download here. Copy them into ~/sketchbook. Note that the download code includes code to display on an LCD screen. The codes will actually display on the Serial monitor - an LCD screen is optional:

Google+ Link to videos of this stuff in action:
https://plus.google.com/117903659405547038190/posts/KQuFt811EhB


My next steps are to implement the same project using two Raspberry Pis and to implement a communication system using Morse over a 434 transmitter receiver pair.

1 comment:

Deepak Narayanan said...

Nice code. Thanks! few questions.
1. The code is sent out in reverse pattern for every letter (the dit and dash), why is that?
2 For every letter, say "H" instead of "...." it sends "........" that is 8 dots instead of 4! why?