This project describes how to use the MATLAB® Support Package for Arduino hardware to create a homemade Morse code transceiver. Morse code was a standard for communications over telegraph during the early 20th century, and is still used internationally for radio transmissions for identification. The transceiver built in this project uses light signals instead of radio signals to designate the characteristic dots and dashes of Morse code. Although these optical signals from simple LEDs are not useful over a distance of more than a few inches, this project can still be used to communicate between two Arduino transceivers.
- Get the project code on File Exchange at MATLAB Centralo
- Files included: char2morse, morse2char, ArduinoSetup, TransceiverCalibration, and OpticalMorseCodeTranceiver
- Arduino Uno
- Connector wires
- Photoresistor, similar to sparkfun.com/products/9088
- Two LEDs
Task 1 – Setting Up the Hardware
You’ll need to use one side of your breadboard to wire the photoresistor and one LED (slot-sensor). Use the other side of your breadboard for the potentiometer, button, and second LED.
To create a proper slot-sensor, set up your photoresistor so it faces the LED, with about a half-inch of space between. It’s best if you bend the LED so the top points directly at the photoresistor, because this is where the majority of the light is emitted. Figure 1 is the circuit diagram for wiring the photoresistor to your Arduino board using an analog pin to read voltages. Figure 2 is a circuit diagram showing how to wire a LED to be controlled by a digital pin on the Arduino board. Depending on the type of LED you have available, you may need to choose a differently valued resistor.
On the opposite side of your breadboard, connect the potentiometer and the push button to your Arduino using the circuit diagrams in Figures 2 and 3. Connect the middle pin of the potentiometer to the analog Arduino pin. You also need to connect the second LED on this side of the breadboard. You’ll use this LED to show when the slot sensor is activated, and for transmitting Morse code signals from it.
Task 2 – Connecting the Arduino to MATLAB
To connect the Arduino to MATLAB, open the ArduinoSetup script. When connecting to an Arduino Uno, MATLAB can automatically determine which port the Arduino Uno is connected to. If your Arduino board is a Mega, Due, Leonardo, or an Arduino clone, you’ll need to specify the USB port and board type when initializing the Arduino object. You can do this in the first section of the ArduinoSetup script.
The next section of the ArduinoSetup script defines variables that refer to your specific wiring hardware setup. Make sure the port numbers listed in this section align with the actual hardware connections you’ve implemented.
The Morse code setup section defines parameters of the Morse code signal the demo uses. The default parameters work well, but you should feel free to experiment with the signal parameters once the transceiver is up and running.
Task 3 – Calibrating the Sensors
The next step is to calibrate the slot sensor and light sensor that the Arduino will use to read Morse code signals. The TransceiverCalibration script contains three sections: (1) Calibrate LED Brightness, (2) Calibrate Slot Sensor Threshold, and (3) Calibrate Light Source threshold. Run this script and follow the prompts to calibrate each sensor using the potentiometer to adjust the threshold and the button to stop and save the calibration. When testing the slot sensor, insert a thick plastic card (an ID card or credit card works well) between the photoresistor and the slot LED to simulate a signal. When testing the light sensor (the photoresistor on its own), shine a flashlight at the photoresistor to simulate a signal. Because these sensors are light-based, they will be sensitive to ambient lighting conditions and may need to be recalibrated if conditions change.
Task 4 – Receiving a Morse Code Message
Once your system is calibrated, you can use the receiveMessage.m script to receive Morse code messages from either the slot sensor or light sensor mode. In the script, set the SENSOR_TYPE number to +1 to use the light sensor, or -1 to use the slot sensor. For the slot sensor, activate the sensor by sliding a card between the slot LED and the photoresistor. You activate the light sensor by shining a flashlight on the photoresistor; it doesn’t need the slot LED to be on. Once you’ve specified the sensor type, run the script. By activating the slot sensor or the light sensor for different lengths of time, the program recognizes either a dot or a dash and displays the received signal in the command window. If you don’t activate the sensor for two seconds, that signals to the program that one letter signal is complete, so the program automatically looks up what Morse signal was received and outputs the letter to the command window. To clear the signal memory, you need to activate the sensor for more that two seconds and the recording is reset. The script runs until you press the button to stop it.
To transmit a message using the signal LED, use the transmitMessage.m script. By changing the uppercase characters in messageString, you can set the letters that are sent over the Morse code signal. If you have two Arduinos, you can use one Arduino to send messages using this script and the other Arduino to receive messages using the receiveMessage.m script.