In the 1830s Americans Samuel Morse, Joseph Henry, and Alfred Vail, an artist, physicist and mechanical engineer developed a telegraph system to send electric pulses. To translate these pulses into natural language Morse developed a code, to send the digits 0-9 which would be used to send a letters in numeric code, this was done in 1837 and not long after this Vail then expanded the code to include the alphabet, this code became known as American Morse code, or Railroad Morse which was actually still used on American railways until the 70’s.
Early forms of the telegraph printed the pulses on paper, however operators soon started to recognise the sound of the dots and dashes and could copy without looking at the paper.
It’s worth mentioning (at least from the point of view of a Brit) that the first commercial telegraph was actually invented by two Brits, William Cooke and Charles Wheatstone, called the Cooke-Wheatstone electrical telegraph, it worked by using the little arrows in the middle to point to letters, kind of an electronic ouija board.
The current international standard Morse code, is derived from a improved proposal by a German chap called Friedrich Gerke in 1848, this is known as Continental code. One of the main improvements which you can see on the image below is that the various different length pulses were reduced to two sizes (plus the long pulse for 0), he also added a number of characters required for the German alphabet. If you see on the right the International Morse standard was finalised in 1865 and is very similar to Gerkes continental code.