ahmedharbi197
Published © MIT

Morse Code Transmitter

Transform English words into Morse code, then transmit it by laser and buzzer. The words can be received from Bluetooth devices.

IntermediateWork in progress5,252
Morse Code Transmitter

Things used in this project

Story

Read more

Schematics

Laser Module

Buzzer

Bluetooth Module

Code

Transmitter

C/C++
Transfer received words into morse code and represent it in laser and buzzer.
// This Code written by Ahmed Harbi on August.2018

// Defined Laser & Buzzer
#define Laser 13
#define Buzzer 9

// Enter Morse Code Library
char* MorseCode[] = {
  ".-",     // A
  "-...",   // B
  "-.-.",   // C
  "-..",    // D
  ".",      // E
  "..-.",   // F
  "--.",    // G
  "....",   // H
  "..",     // I
  ".---",   // J
  "-.-",    // K
  ".-..",   // L
  "--",     // M
  "-.",     // N
  "---",    // O
  ".--.",   // P
  "--.-",   // Q
  ".-.",    // R
  "...",    // S
  "-",      // T
  "..-",    // U
  "...-",   // V
  ".--",    // W
  "-..-",   // X
  "-.--",   // Y
  "--.."    // Z
};

//Enter Numbers Library
char* Numbers[] = {
  "-----",   // 0
  ".----",   // 1
  "..---",   // 2
  "...--",   // 3
  "....-",   // 4
  ".....",   // 5
  "-....",   // 6
  "--...",   // 7
  "---..",   // 8
  "----."    // 9
};

//Define I/Os
void setup() {
  pinMode(Laser, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  Serial.begin(9600);
}



void loop() {

  // Reset the readed data every loop
  char letter;
  

  // Check if bluetooth is connected
  if (Serial.available() > 0) {

    // Read data from bluetooth
    letter = Serial.read();


    // Lower case letters
    if (letter >= 'a' && letter <= 'z') {
      // Call the letter element then apply morse code decoder
      decoder(MorseCode[letter - 'a']);
    }

    // Capital case letters
    else if (letter >= 'A' && letter <= 'Z') {
      // Call the letter element then apply morse code decoder
      decoder(MorseCode[letter - 'A']);
    }

    // Numbers
    else if (letter >= '0' && letter <= '9') {
      // Call Number's Element then apply morse code decoder
      decoder(Numbers[letter - '0']);
    }

    // Space Case
    else if (letter == ' ') {
      delay(600);
    }
    
    // Print output back
    if (letter == '\0') {
      Serial.println("");
    } else {
      Serial.print(letter);
    }
  }
}

// Set the decoder [flash for each letter in received string]
void decoder (char* x) {

  // Counter
  int i = 0;

  //Decoder
  while (x[i] != '\0') {
    flashType(x[i]);
    i++;
  }
  
  // Delay between every letter
  delay(250);
}



// Dash or Dot 
void flashType (char data) {

  // Turn laser & Buzzer on
  digitalWrite(Laser, HIGH);
  tone(Buzzer, 1000);

  // DOT
  if (data == '.') {
    delay(200);
  }

  //Dash
  if (data == '-') {
    delay(600);
  }

  // Turn laser & Buzzer off
  digitalWrite(Laser, LOW);
  noTone(Buzzer);

  //Delay before the following dash/dot
  delay(200); 
}

/*Problems:
 *1.cann't control laser or buzzer itself
 */

Text Detection

Python
To recognize text from Image or Video and send it to arduino via bluetooth.
# this code was written by Ahmed Harbi & Omar Ghonim on FEB.2018

import cv2
import pytesseract
import os
from PIL import Image
import serial

#Define Bluetooth
port = "COM8"
bluetooth = serial.Serial(port, 9600)
bluetooth.flushInput()

#Stored Words
stored = ["SOS", "DANGER", "HELP"]

#open the webcam and capture a video
cap = cv2.VideoCapture(0)

while (True):

    #read each frame in the loop as image
    image = cap.read()[1]

    #noise filtration
    #Change color space into Gray
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    #Apply thrsholding
    #Otsu to reduce the graylevel & Binary to change in B\W image
    threshold = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1] #save data into numerical tuple
    #Use median filter and remove noise
    blur = cv2.medianBlur(threshold, 3)

    #save filtered photo
    filtered = 'filtered.png'
    cv2.imwrite(filtered, blur)

    #export text from saved photo
    text = pytesseract.image_to_string(Image.open(filtered))

    #Delete saved picture
    os.remove(filtered)

    #Skip unwanted readed data
    if text.upper() in stored:
        bluetooth.write(str.encode(str(text)))
        print (text)
        break
    #show captured
    cv2.imshow('Morse Code', blur)

    #Press ESC to end the program
    k = cv2.waitKey(1) & 0xff
    if k == 27:
        break

cv2.destroyAllWindows()
cap.release()

Desktop Application

Python
Enter text which you want to transfer into morse code then send it to arduino via bluetooth
#this Code was written by Ahmed Harbi on June.2018

import sys
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import *
import serial
import time

#define Bluetooth Device
port = "COM8"
bluetooth = serial.Serial(port, 9600)
bluetooth.flushInput()

 
# create window
app = QApplication(sys.argv)
w = QWidget()
w.setWindowTitle('Morse Code')

#Laser on Button
laserOn = QPushButton('Laser on', w)
laserOn.move(20,10)

#Buzzer on Button
buzzerOn = QPushButton('Buzzer on', w)
buzzerOn.move(20,40)

#Laser off Button
laserOff = QPushButton('Laser off', w)
laserOff.move(225,10)

#Buzzer off Button
buzzerOff = QPushButton('Buzzer off', w)
buzzerOff.move(225,40)

# Create textbox
textbox = QLineEdit(w)
textbox.move(20, 70)
textbox.resize(280,40)
 
# Set window size.
w.resize(320, 200)
 
# send button
send = QPushButton('Send', w)
send.move(20,120)
 
# Create the actions
@pyqtSlot()

#send Button
def on_click_send(self):
    textboxValue = textbox.text()
    bluetooth.write(str.encode(str(textboxValue)))
    print("Sent")
    
    
#Laser On Button
def on_click_laserOn(self):
    bluetooth.write(str.encode(str('100')))

#Buzzer On Button
def on_click_buzzerOn(self):
    bluetooth.write(str.encode(str('50')))

#Laser Off Button
def on_click_laserOff(self):
    bluetooth.write(str.encode(str('0')))

#Buzzer Off Button
def on_click_buzzerOff(self):
    bluetooth.write(str.encode(str('25')))
    
# connect the signals to the slots
send.clicked.connect(on_click_send)
laserOn.clicked.connect(on_click_laserOn)
buzzerOn.clicked.connect(on_click_buzzerOn)
laserOff.clicked.connect(on_click_laserOff)
buzzerOff.clicked.connect(on_click_buzzerOff)

 
# Show the window and run the app
w.show()
app.exec_()

Applications

Android Application Desktop Application Image Processing Code

Credits

ahmedharbi197

ahmedharbi197

0 projects • 1 follower

Comments