the world is a pixel
Morse Code Translator with Arduino
You write in your computer, sends a message thought USB and Arduino translates it into a Morse code.
Just a Arduino board with a buzzer connected at the digital output 12 (one wire in the ground and the other in the 12).
I tried to make the code as general as possible so you can easily adapt it for anthers ways of transmitting a Morse code. To do that you just need to rewrite a few functions.
+-------------------+
| 3) Interpretation |
+-------------------+
| 2) Translation |
+-------------------+ +-------------------+
| Computer |<========USB (Serial)=======>| 1) Reading |
+-------------------+ +-------------------+
- Reads a character from Serial. Main function loop().
- Translate a ascii char into a Morse code using a reference table. A letter 'K' becomes a string word "-.-". Function say_char().
- Interpret the Morse word as light and sound. Mostly at function say_morse_word(). The Interpretation needs 5 functions to say all Morse words, dot(), dash(), shortgap(), mediumgap() and intragap().
For a more details on Morse code I strongly recommend the English Wikipedia article on it.
int led = 13; // LED connected to digital pin 13 int buzzer = 12; // buzzer connected to digital pin 12 int unit = 50; // duration of a pulse char * morsecode[] = { "-----", // 0 ".----", // 1 "..---", // 2 "...--", // 3 "....-", // 4 ".....", // 5 "-....", // 6 "--...", // 7 "---..", // 8 "----.", // 9 "---...", // : "-.-.-.", // ; "", // < (there's no morse for this simbol) "-...-", // = "", // > (there's no morse for this simbol) "..--..", // ? ".--._.", // @ ".-", // 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 }; void setup() { pinMode(led, OUTPUT); pinMode(buzzer, OUTPUT); Serial.begin(9600); } void say_morse_word(char * msg){ int index = 0; while(msg[index]!='\0'){ // say a dash if(msg[index]=='-'){ dash(); } // say a dot if(msg[index]=='.'){ dot(); } // gap beetween simbols intragap(); index++; } } // beep void beep(int time){ int i; int t = 100; // period of the wav. bigger means lower pitch. int beepduration = (int)((float)time/t*1800); digitalWrite(led, HIGH); for(i=0;i<beepduration;i++){ digitalWrite(buzzer, HIGH); delayMicroseconds(t); digitalWrite(buzzer, LOW); delayMicroseconds(t); } delay(time); } // silence void silence(int time){ digitalWrite(led, LOW); delay(time); } // general procedure for . void dot() { beep(unit); } // general procedure for - void dash() { beep(unit*3); } // gap between dots and dashes void intragap() { silence(unit); } // gap between letters void shortgap() { silence(3*unit); } // gap be tween words void mediumgap() { silence(7*unit); } void say_char(char letter){ if((letter>='0')&&(letter<='Z')&&(letter!='<')&&(letter!='>')){ Serial.print(morsecode[letter-'0']); Serial.print(' '); say_morse_word(morsecode[letter-'0']); shortgap(); } else { if(letter==' '){ Serial.print(" \\ "); mediumgap(); }else{ Serial.print("X"); } } } void loop(){ if(Serial.available()){ say_char((char)Serial.read()); } }
Additionally you can put another function to say entire strings, like say_string("HELLO WORLD")
void say_string(char * asciimsg){ int index = 0; char charac; charac = asciimsg[index]; while(charac!='\0'){ say_char(morsecode[charac-'0']); Serial.println(morsecode[charac-'0']); charac = asciimsg[++index]; shortgap(); } }
You can use the Arduino IDE itself or any other program that talks with the serial port USB.
You must be logged in to post a comment.
No trackbacks yet.
C# class properties example
15 December, 2011 - 12:26 pm
Tags: .Net, C, C-Sharp, celsius, fahrenheit, kelvin, temperature
Posted in english | No comments
A example of use of C# class properties to convert temperatures in Celsius, Fahrenheit or Kelvin. The temperature is encapsulated and stored in a internal representation, in this example, in Celcius (private double c). Each conversion is accessible by getting or setting a property. using System; public class Temperature { private double c; [...]
Python, flatten a list
Surprisingly python doesn’t have a shortcut for flatten a list (more generally a list of lists of lists of…). I made a simple implementation that doesn’t use recursion and tries to be written clearly. I get a element from a “bad” list (a list that can have another lists). If the element is not a [...]
OpenPixels: simple sprite sheet with Processing
22 August, 2011 - 10:54 pm
Tags: Openpixels, Pixelart, Processing, programming
Posted in english | No comments
/** * Openpixels example in Processing. * This simple example of how to get a sprite * from a sprite sheet. */ PImage bg; PImage sprite_sheet; PImage player; void setup() { // load images bg = loadImage("kitchen.png"); sprite_sheet = loadImage("guy.png"); /* The sprite size is 32×49. Look guy.png, the "stand position" is [...]
Atiaia early releases
23 July, 2011 - 9:57 pm
Tags: Atiaia, C, Marco Diego, programming, Ray Tracying
Posted in english | 1 comment
This was a project that me and Marco Diego created during our graduation for the Computer Graphics course. It is a ray tracing engine build from scratch in C. It was great exercise of experimentation on how implement object-oriented design patterns in ANSI C. Later Marco continued it in his master’s degree thesis implementing more [...]
Android screen height and width
12 March, 2011 - 9:30 pm
Tags: Android, Java, mobile, programming, screensize
Posted in english | 1 comment
Context ctx = getContext(); Display display = ((WindowManager)ctx.getSystemService(ctx.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); Yes, there are easier ways to retrieve the screen width on Android but there are cases that this long code is the only solution. You may already have the Context. WindowManager or the Display and so it would be [...]
PHP: array, all elements but first
9 March, 2011 - 12:52 pm
Tags: array, array_shift, PHP, programming
Posted in english | No comments
$bric = array("Brazil", "Russia", "India", "China"); $ric = $bric; // array copy $br = array_shift($ric); // left shift at $ric. $br stores "Brazil" print_r($bric); // $bric remains the same print_r($ric); // $ric lost "Brazil" Output: Array ( [0] => Brazil [1] => Russia [2] => India [3] => China ) Array ( [0] => Russia [...]
Arduino The Documentary
15 January, 2011 - 5:03 pm
Tags: Arduino, documentary, hardware, Open Source, open source hardware
Posted in english | No comments
Arduino The Documentary (2010) English HD from gnd on Vimeo. :D
Java: invoking a method by name
29 April, 2010 - 10:29 am
Tags: Class, Java, method, programming, Reflection
Posted in english | 2 comments
import java.lang.reflect.*; public class Foo { public void bar(int param){ System.out.println(param); } public static void main(String args[]){ Object f = new Foo(); try { Method m = f.getClass().getMethod("bar", int.class); m.invoke(f, 42); } catch (Exception e){ System.err.println(e); } } } $ java Foo 42
calling commands in Java
8 April, 2010 - 1:09 pm
Tags: getruntime, Java, programming, runtime
Posted in english | No comments
I don’t like the approach of calling native shell commands in any language instead of using multi platform libraries, but here is a little prof of concept Java program to call native commands. import java.io.*; import java.util.*; public class Exec { public static void main(String args[]) throws IOException { Process proc = Runtime.getRuntime().e xec(args); BufferedReader [...]
Iterating over a HashMap
8 April, 2010 - 11:22 am
Tags: collections, enhanced loop, foreach, hashmap, iterating, Java, programming
Posted in english | No comments
Iterating over a HashMap using the enhanced loop (foreach) in Java is a good way to keep your code smaller, more legible and usually more semantically coherent. import java.util.HashMap; import java.util.Map; class Foo {} public class Main { public static void main(String args[]){ Map<Byte, Foo> mHash; mHash = new HashMap<Byte, Foo>(); [...]














24 October, 2009 - 3:56 am
Great stuff!
What do you think, on the other side, could there be a Morse code -> Text translating Arduino? That would be pretty practical….
24 October, 2009 - 1:32 pm
Greg, seems a good idea.
25 October, 2009 - 11:54 am
@Greg: I will start to work on such a project in the coming weeks. An Arduino will be connected to an LCD display that displays the translation from morse input. Way to input morse will be non standard. Project is to be used as a communication tool for a person with severe physical disabilities.
30 October, 2009 - 9:13 pm
Yes, I would like to see an example of a working morse decoder with LCD! :-) Great! Thanks!
23 November, 2009 - 12:11 am
I’m just starting on my arduino and want to know how to go about decoding morse and display to an LCD my self thanks!!!
Nice work
Chad
25 July, 2010 - 12:19 pm
Hi There. Really nice project you have there. I was interested in implementing morse code in arduino, however I did i the other way around – user flashes the flashligh or other source of light near the photo diode, and arduino board translates it into letters, works pretty well :)
Btw. How did you configure your IDE to have serial monitor directly below the code in the same window (it’s pretty annoying to open serial monitor every time from the menu, and the Keyboard shotcuts always puts empy line in the code…).
2 May, 2011 - 11:53 am
Hi! I wonder if you ever made the morse code decoder – if so, could you send me the sourcecode for it ?
I am making a project which I could share with you later on.. :)
2 May, 2011 - 12:02 pm
Daniel, the source is in this post. You can use it in the Creative Commons Attribution Share-Alike license or GPLv3 license.
12 May, 2011 - 6:51 am
Hi all
I’m working on an art piece at the moment which will decode morse but the difference is that the morse will be sent by human operated morse key so will obviously have to account for slightly variable timings. I have made some code in processing – the idea being that i will use analog in from arduino and send that by serial to processing. I’m happy to post the code if anyone is interested? at the moment it jsut works with a key press.