Yaѕн karade
Published

Morse code Transmitter and Cipher!

Since the day I watched #Titanic I was wondering will I be able to see, use Morse Transmitter, thanks to IoT and BOLT I made one!

IntermediateFull instructions provided10 hours845
Morse code Transmitter and Cipher!

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
5 mm LED: Red
5 mm LED: Red
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Buzzer
Buzzer
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×4

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud

Story

Read more

Schematics

Main Circuit

connect Bolt GPIO pin 0 to the buzzer, GPIO pin 1 to Resistor than to LED, connect the Buzzers and LED's ground to the BOLT's comm ground

Code

Morse Code Encrypt-er, and Transmitter!

Python
I have approached the solution in OOPs way (object-oriented Programming) I wrote a function
1. To Convert English to Morse
2. To Transmit the Morse Code to The LED or The Buzzer
3, Morse code is a language of Dashes and Dots so I wrote a function to transmit a dot, dash and even the space between words

I have added an interactive way for the output so the user won't get bored and try the program multiple times, it asks whether to transmit on LED or on the Buzzer
This is the python code that's connected to my BOLT! with asks the user for input in English and converts it to Morse i.e Dots and Dashes! I programmed it to transmit the code in both ways, visually using LED and Audio via Buzzer! the only drawback the program consists is the one that morse code gives 'time' it takes 10 seconds on average for a single word, but enthusiasts like me watch it with a big smile!
import time
import requests

MORSE_CODE_DICT = {'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': '--..',
                   '1': '.----', '2': '..---', '3': '...--',
                   '4': '....-', '5': '.....', '6': '-....',
                   '7': '--...', '8': '---..', '9': '----.',
                   '0': '-----', ',': '--..--', '.': '.-.-.-',
                   '?': '..--..', '/': '-..-.', '-': '-....-',
                   '(': '-.--.', ')': '-.--.-'
                   }

on = 'https://cloud.boltiot.com/remote/ce212d1c-376b-4b49-b232-XXXX/digitalWrite?pin=0&state=HIGH&deviceName=BOLTXXXXXX'
off = 'https://cloud.boltiot.com/remote/ce212d1c-376b-4b49-b232-XXXX/digitalWrite?pin=0&state=LOW&deviceName=BOLTXXXXXX'
onL = 'https://cloud.boltiot.com/remote/ce212d1c-376b-4b49-b232-XXXX/digitalWrite?pin=1&state=HIGH&deviceName=BOLTXXXXXX'
offL = 'https://cloud.boltiot.com/remote/ce212d1c-376b-4b49-b232-XXXX/digitalWrite?pin=1&state=LOW&deviceName=BOLTXXXXXX'
ans = ''


# HARDWARE FUNCTIONS BUZZING, BLINKING, ETC.
def dot(x):
    if x == 0:
        requests.get(on)
        requests.get(off)
    elif x == 1:
        requests.get(onL)
        requests.get(offL)


def dash(x):
    if x == 0:
        requests.get(on)
        time.sleep(1)
        requests.get(off)
    elif x == 1:
        requests.get(onL)
        time.sleep(1.5)
        requests.get(offL)


def space():
    time.sleep(2)


# CONVERTING ENGLISH TO MORSE CODE


def convert(message):
    message = message.upper()
    my_cipher = ''
    for myletter in message:
        if myletter != ' ':
            my_cipher += MORSE_CODE_DICT[myletter] + ' '
        else:
            my_cipher += ' '

    return my_cipher


# TRANSMISSION - TRANSMITTING OUR MESSAGE TO THE DEVICE


def led(message):
    try:
        for i in message:
            if i == '.':
                dot(1)
            elif i == '-':
                dash(1)
            elif i == ' ':
                space()
    except:
        print('Error')


def buzz(message):
    try:
        for i in message:
            if i == '.':
                dot(0)
            elif i == '-':
                dash(0)
            elif i == ' ':
                space()
    except:
        print('Error')


# FINAL OUTPUT -- I know it looks mess but i tried hard on
# making the output beautiful!

# FUNCTIONS TO MAKE OUTPUT INTERACTIVE

def wait(seconds):
    time.sleep(seconds)


def printdots(x):
    for i in range(2):
        print('.')
        wait(1)


def printspaces(x):
    for i in range(2):
        print(' ')
        wait(1)


printspaces(2)
print('Hello, welcome to the Morse Magic Show')
wait(1)
print('"They say, if the world goes on war,')
wait(1)
print('Morse code will keep us united"')
printspaces(2)
print('Enter The String you want to convert?')
wait(1)
string = input(
    'Include Alphabets, Numbers and .,?/-() These characters only  \n')
wait(1)
printdots(2)
print('Converting')
printdots(2)
yes = input('Should i transmit the code to BOLT?(Y/N)\n')
wait(1)
yes = yes.upper()
ans = convert(string)
if yes == 'Y':
    printdots(1)
    print('Transmiting')
    printdots(2)
    ques = input(
        'oh! wait you wanna see it or hear it? Type:\n 1 for Buzzer! \n 2 for LED! \n')
    printdots(2)
    print('The show begins !!!')

    if ques == '1':
        buzz(ans)

    elif ques == '2':
        led(ans)

else:
    wait(1)
    print('Duh! Too boring')

wait(1)
print(ans)

Credits

Yaѕн karade
1 project • 0 followers

Comments