Morse Code Transmitter/Detector

The questions below are due on Friday May 05, 2023; 05:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Before Building

Before building, turn on the scope and let's reset it to all of its defaults by:

  • Pushing the "Default Setup" button in the upper left, and
  • Under the "Wave Gen" menu (accessible by pushing the button in the bottom right), click the "Settings" button (the bottom one on the screen), then click the "Default Wave Gen" button (the bottom one again) You should get a message on screen saying that things have been reset.

In ancient times, civilizations would warn their citizens about approaching armies by lighting bonfires on mountaintops. Today, we still routinely use light to communicate across distances... although it is more commonly to help us change our channel or increase the volume. TV remotes commonly operate by using an infrared (light that is so "red" it is invisible to the human eye) light-emitting diode and a phototransistor. The light comes from the remote and is received by a phototransistor on the TV.

In this lab, we'll create a simplified version of such a system, and we'll use visible LEDs so that you can see the light. By the end of the lab, we'll have a small system capable of sending messages over the span of a few inches, which we can use to send and receive messages using Morse code. Here is an example of what the whole system will look like, end-to-end:

The circuit on the far right (with the flashing light) is our transmitter. By pushing a button, we're able to turn the light on and off. To the left is a receiver that is responsible for reading the message. The circuit on that board converts the signal into a format that the Teensy is capable of understanding, and then some code on the Teensy decodes messages sent in morse code and displays the results on the laptop screen.

This Little Light of Mine

Since we're going to be building the circuit in two parts, go ahead and grab two breadboards. It probably makes sense to grab one of the half-length breadboards (for the transmitter) and one of the full-length breadboards (for the receiver).

We'll start with the transmitter. In fact, as a place to start, just hook up a green LED so that it is powered by the wave generator. When hooking this up, make sure that the longer lead of the LED is connected to the red side of the wave generator. Then set the wave gen to the following settings:

  • Waveform: DC
  • Offset: 2.7 Volts

When you've done that, you should see your LED light up, hooray!

Next, add a button to your circuit such that the light only lights up while the button is pressed down. Remember that the button acts like a short when it is pressed, and like an open otherwise.

Picking Up What You're Laying Down

Actually, that's about it for our transmitter (we'll come back to it later, but yeah). Now that we have a way to make a signal by pushing a button, we'll get started on the circuit for detecting that signal. This circuit will ultimately be powered by the Teensy (which is where we'll do the detection), so go ahead and grab one of those and plug it into your laptop with a USB cable. For now, we won't program it in any particular way, we'll just use it to power the detector for now (code will come later).

The centerpiece of our detector circuit will be a phototransistor (which are available from the cart at the front of the room). When hooked up in a certain way (like we'll do below), the phototransistor behaves a lot like a current source, whose current is proportional to the amount of light falling on it. build a little circuit like the following (where the current source represents the phototransistor).

MAKE SURE THAT THE LONGER OF THE TWO LEADS OF THE PHOTOTRANSISTOR IS CONNECTED TO THE 100{\rm k}\Omega RESISTOR, NOT TO GROUND!

Notice that our output voltage v_{\rm sense} is the voltage drop across the phototransistor.

If the current flowing through the photoresistor is given by i_0 (Amps), what is the value of v_{\rm sense} in units of Volts? You may use i_0 in your answer to represent i_0, but use numbers for everything else.
v_{\rm sense} =~

Hook up channel 1 of your scope to measure v_{\rm sense}.

Then line up the LED on your transmitter with the phototransistor on your detector. The easiest way to do this is to set the two breadboards flat and slightly bend the LED and phototransistor so that they are facing each other, as shown below:

Check Yourself 1:
Try pushing the button to turn your light on/off. You should be able to notice a change in v_{\rm sense} as you turn the light on and off.

How does it change as you move your transmitter around? How far apart can the transmitter and receiver be to still detect the signal?

Check Yourself 2:
Try shining a flashlight on your detector as you're turning your LED on/off (from your phone or however you want to do it). How does this affect things?

Rhythm is a Dancer

Probably in the last section, the change in your signal was pretty small, and thus difficult to reliably detect. We'd like to think about amplifying it with an op-amp, but that strategy would have some problems with our current setup (specifically, since the voltage there is big both when the light is on and when it's off, we'd have trouble avoiding the op-amp's power supply limitations). On sunny days, we might also have problems telling our little green light apart from external light sources.

So, in short, while this worked, we can definitely do better. And that's exactly what we'll try to do for the remainder of the lab.

It may seem strange at first, but the key to our approach is going to be to make the light flicker at a predictable frequency. This will allow us to separate the signal from our LED from other noise/interference from other sources.

Try to find a partner (or ask us for help if you're having trouble finding one). Within your group, we'll have one of you work at around 15kHz, and the other at around 30kHz. Then change the settings on your wave gen to:

  • Waveform: sine
  • Frequency: 15kHz or 30kHz (whichever one you chose)
  • Amplitude: 1V peak-to-peak
  • Offset: 2.7V

After having done this, when you push the button to turn on your light, it still likely looks the same as it did before; but the brightness is actually varying subtly at your given frequency. And your detector circuit can detect those changes!

Make sure your detector is lined up, and then try measuring it again. As you push/unpush the button, you should be able to see v_{\rm sense} change. But unlike before, you shouldn't just see the level of v_{\rm sense} change; when the light is on, you should also be able to see the wiggles on v_{\rm sense} at the frequency you chose (which you can verify with the cursors and/or measurement functionality of the scope).

Now comes the beautiful part. Now that the signal we care about is isolated to a particular frequency, we can use a filter to isolate that frequency so that we're not affected by ambient lights, or by other signals operating at different frequencies. This will also help us remove the constant offset in v_{\rm sense}, which will allow us to get a much better look at just what's coming from our transmitter.

We'll build a little band-pass filter to isolate the frequency we're interested in. Our filter will take the following form, which should be familiar from lecture/recitation/psets:

Check Yourself 3:
What value of capacitor do you need to put the peak of the frequency reponse at the frequency you care about?

Go ahead and lay out this circuit on your breadboard with your chosen capacitance (we probably don't have exactly the value you need, but try your best), but for now build it separate from the other pieces so that we can characterize its behavior. We'll do so by running a frequency sweep like we did last week. For today, use a frequency range from 100Hz to 100kHz, 1 Volt peak-to-peak, and 100 points.

Check Yourself 4:
Where is the actual peak of your frequency response? Before moving on, adjust the frequency of your wave generator so that it's actually producing a sine wave at that peak frequency (rather than at the frequency we were using before).

Awake on My Airplane

We'd ultimately like to use this filter with v_{\rm sense} as its input, producing a new voltage across the resistor that ideally contains only the signal we received from our LED. Unfortunately, though, the filter would mess up our detector if we just hooked it up directly. So let's buffer the detector's output first, and then filter the result.

Check Yourself 5:
Draw a complete schematic for your detector (including the buffer and filter). We'll be adding to this as we go, and we'll expect to see a complete schematic during the checkoffs, so try to keep this up to date as we add things as well.

Checkoff 1:
Discuss your work so far with a staff member. Be prepared to discuss your frequency response analysis, how you chose your capacitance value, and your schematic diagram.

Build It

Now go ahead and lay this out on your board. Use the MCP6002 op-amps we have on the cart, they have the same pinout as the TL082's we used a few weeks ago:

Power the op-amps with the 3.3V supply from the Teensy (the same Teensy pins we're using in the phototransistor circuit).

Check Yourself 6:
After building your circuit, look at your filtered output on the scope while the light is on. What are the most noticeable differences from before the filter was added? You may find it helpful to measure both the input and output of your filter at the same time to compare them.

Check Yourself 7:
Try adjusting your the frequency on the wave gen up and down. If your filter is doing its job, you should see your filtered output change dramatically.

Does what you see match what you expect?

Again, A Gain

The signal that is coming out of your filter is pretty nice, but it is really tiny, probably too small for the Teensy to reliably detect. As such, we're going to want to amplify it substantially. We're going to run the filtered signal through a non-inverting amplifier with a 1{\rm k}\Omega resistor and 500k\Omega resistor to make a gain of around 500.

Check Yourself 8:
Add this non-inverting amplifier to your circuit schematic. As always, if you're unsure, feel free to ask a staff member for help.

Now build it. Note that the MCP6002 package has two op-amps in it (one on each side), so you should be able to use the same one. When you've hooked that up, measure the amplified signal.

Check Yourself 9:
This signal no longer looks like a sine wave! That's OK and expected, but make sure you understand why this is the case (we're going to ask about it during the checkoff).

Check Yourself 10:
Try changing the frequency on your wave gen, adjusting it up and down. How does this affect the output of your amplifier?

How is your output affected as you move the light closer or farther away, or change its angle?

Flattening the Curve

We're well on our way here! We've got a nice output voltage corresponding to the signal from our LED, and it's relatively focused in on that one frequency (so it won't be super affected by ambient light, or other flashing light sources, etc).

But we're not quite done yet. We're ultimately going to want to feed this voltage into our Teensy and be able to tell from one measurement whether the light is on or not. But with how much our signal is oscillating, that makes the Teensy's job hard. What we'd like to do is to build a little circuit to turn the voltage output from our amplifier into a pulse the Teensy can understand.

In particular, we're looking at a signal like the following (where here the light is on for the left half of the graph and off for the right half):

What we would ideally like to see, instead, is a DC voltage corresponding to the light being on or not:

We won't be able to achieve that exactly, but we can get close with a circuit like the following:

Measuring the drop across the capacitor should show us a smoother curve.

Check Yourself 11:
How does this circuit accomplish the task of smoothing out our signal? How can you set R and C to make this happen effectively?

Check Yourself 12:
Add this piece to your circuit schematic and to your board.

Go ahead and measure this output on your scope. If you need to, feel free to adjust your R and C values until you get a pretty smooth signal It might be OK to have variations of maybe 10-100mV in your signal, but everything will work better the smoother this is.

Finally, take that voltage and connect it to pin 14 on the Teensy, and run the code from morse.zip. Try shining your LED on the detector. As you do so, if everything is working, you should see a little orange light come on on the Teensy when your LED is on (indicating that the Teensy is successfully seeing that signal).

Check Yourself 13:
Try adjusting the frequency on your wave gen. If everything is working, the Teensy should be really bad at detecting signals when the frequency moves away from your filter's peak frequency by a few kilohertz.

Check Yourself 14:
Try moving things around as well. How far away can your detector and transmitter be and still detect the signal reliably? Hopefully you should be able to detect things about 6 inches away, but it's fine if not.

Check Yourself 15:
Let's also try messing with the signal a little bit.

Try shining a bright light (like the one on your phone) on your detector while turning your LED on and off. Because we're filtering out the DC component, this should not impede the Teensy's ability to detect the LED.

Similarly, have your buddy (who chose a different frequency than you) shine their LED on your detector while you turn yours on and off. The presence of the other light again shouldn't have a big effect on the Teensy's ability to detect your LED.

Messages

Finally, if you're so inclined, feel free to open up the "Serial Monitor" in Arduino while you're connected up to your Teensy. Doing so will cause letters to pop up on the screen when you send them using Morse code (like in the video at the top of the page). Feel free to play around with this if you want, and try to send/receive a few messages!

Checkoff 2:
Discuss all of your results with a staff member. At this point, you should have a working circuit as well as a complete schematic drawing. Talk through the design decisions you had to make, and describe the purpose of the various parts of the circuit.

Finally, shed a single, silent tear for the end of the last 6.200 lab of the semester.

When you're done with that, please return the phototransistor, op-amps, inductors, LEDs, and breadboards to the cart at the front of the room. Make sure not to confuse the LEDs and the phototransistors!

Also, leave your Teensy in the breadboard. We'll take care of removing it.

Resistors and capacitors, as well as cut wires, can be thrown away.