Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
| ||||||
| ||||||
| ||||||
| ||||||
|
It's a college project for Logic Gates Subject. I chose this project to apply coding system in real life so I tried to transform ASCII code into Morse code and to begin dealing with microcontrollers.
Arduino transmitter which convert English words into Morse code then represent it in light and sound with laser and buzzer. Arduino receives words through serial bluetooth communication. I build Android application and desktop application using "MIT app inventor, Python 3.7, PyQt4, Serial package". I also used Image Processing to recognize text through image or video through cam and then send it to the arduino using "Python 3.7, OpenCV, Tesseract OCR, Serial package".
// 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
*/
# 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
PythonEnter 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_()
Comments