Alireza Karkon
Published © MIT

Morse Code Receiver

It's a Morse code receiver base on processing the light signals.

AdvancedShowcase (no instructions)4.5 hours11,479
Morse Code Receiver

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Pmod OLEDrgb
Digilent Pmod OLEDrgb
Or any Display I used Oled Adafruit
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Photo resistor
Photo resistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Android device
Android device
I used android phone just for transmit the morse
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Visual Studio 2015
Microsoft Visual Studio 2015
Actions on Google
Actions on Google
Google play for DL the morse app

Story

Read more

Code

Code

C/C++
morse tree adapted from code written by Achindra Bhatnagar
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// If using software SPI (the default case):
#define OLED_MOSI  11   //D1
#define OLED_CLK   12   //D0
#define OLED_DC    9
#define OLED_CS    8
#define OLED_RESET 10


Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);


const char MorseTree[] = {'\0','E', 'T', 'I', 'A', 'N', 'M', 'S',
                          'U', 'R', 'W', 'D', 'K', 'G', 'O', 'H',
                          'V', 'F', 'U', 'L', 'A', 'P', 'J', 'B',
                          'X', 'C', 'Y', 'Z', 'Q', '\0','\0','5',
                          '4', '\0','3', '\0','\0','\0','2', '\0',
                          '\0','+', '\0','\0','\0','\0','1', '6',
                          '=', '/', '\0','\0','\0','(', '\0','7',
                          '\0','\0','\0','8', '\0','9', '0', '\0',
                          '\0','\0','\0','\0','\0','\0','\0','\0',
                          '\0','\0','\0','?', '_', '\0','\0','\0',
                          '\0','"', '\0','\0','.', '\0','\0','\0',
                          '\0','@', '\0','\0','\0','\0','\0','\0',
                          '-', '\0','\0','\0','\0','\0','\0','\0',
                          '\0',';', '!', '\0',')', '\0','\0','\0',
                          '\0','\0',',', '\0','\0','\0','\0',':',
                          '\0','\0','\0','\0','\0','\0','\0'
                         };


int val = 0; // A Variable to Store the Light Value from the LDR
int ctrHigh = 0;
int ctrLow = 0;
int codePtr = 0;
int dotLen;
bool Bflag;
int wpm;
 static unsigned long thisMicros = 0;
  static unsigned long lastMicros = 0;

void setup()
{
  
 display.begin(SSD1306_SWITCHCAPVCC);
  display.display();
  delay(1000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);

  Serial.begin(9600);// Start a Serial Connection
  Serial.print(codePtr);
}

void loop()
{
 
  getMorse();


  
}











void dis(){
  display.display();
 lastMicros = thisMicros;
 thisMicros = micros();
}












void getMorse(){
    wpm = (analogRead(2)*10)/1023 ;
    val = analogRead(1);
    ///////////////////
    if (wpm == 1){
      dotLen = 63;
    }
    if (wpm == 2){
      dotLen = 125;
    }
    if (wpm == 3){
      dotLen = 187;
    }
    if (wpm == 4){
      dotLen = 250;
    }
    if (wpm == 5){
      dotLen = 312;
    }
   if (wpm == 6){
      dotLen = 375;
    }
    if (wpm == 7){
      dotLen = 737;
    }

        if (wpm == 8){
      dotLen = 500;
    }
        if (wpm == 9){
      dotLen = 562;
    }
        if (wpm == 10){
      dotLen = 625;
    }
    ////////////////////
    
//  Serial.println(wpm);
  if (val >= 300)
  {
    ctrHigh++;
    ctrLow = 0;
//    digitalWrite(13, HIGH);
 //   tone(9, 1000);
  } else {
    ctrLow++;
    if ((ctrHigh >= dotLen) && (ctrHigh < dotLen*2)) {
    //  Serial.print(".");
    Bflag =true;
      codePtr = (2*codePtr) + 1;
    } else if (ctrHigh >= dotLen * 2) {
      Bflag =true;
    //  Serial.print("-");
      codePtr = (2*codePtr) + 2;
    } else {
      if(ctrLow >= dotLen*6 && Bflag == true){
         Serial.print(" ");
          display.print(" ");
          Bflag = false;
      }
       if(ctrLow >= dotLen*14){
           display.clearDisplay();
            display.setCursor(0,0);
      }
      if(ctrLow == dotLen*2){
        
        Serial.print(MorseTree[codePtr]);
    display.print(MorseTree[codePtr]);
    dis();
        codePtr = 0;
      }
    }

    ctrHigh = 0;
//    digitalWrite(13, LOW);
//    noTone(9);
  }
}

Credits

Alireza Karkon

Alireza Karkon

10 projects • 67 followers
Hey guys! I'm Alireza. I'm a student (Bachelor of Technology)-Computer EngrgTech. I'm C# / C++ / Unity programmer and familiar to Front-End.

Comments