Okay, so the idea was to convert light signals (Morse code) to text that would be displayed on the computer screen via the Serial Monitor. So, I set up an LDR circuit (in voltage divider configuration) to test the brightness of light. When the intensity of light is high, the LDR has low resistance and thus most of the voltage difference is across the 100k-ohm resistor, giving us a high voltage (analog values > 1000), and when there's no light values of 300-400 were common. To prevent ambient/surrounding lights from influencing the LDR, I set up a closed box housing the LDR+Arduino with a small hole, where the signal would be flashed.
 |
| The circuit |
Essentially the circuit is this:
The Morse Signal would be flashed using my cell-phone back camera flash using an app called
Morse Code Flasher.
 |
| The opaque box - there are two holes - one for the light/signal and another on the side to run in the USB cable to Arduino. |
 |
Inside of the box
|
After constructing an opaque box to house the LDR circuit and arduino I ended up with the following results:
- In darkness, general analog values < 100.
- In light, general analog values > 1000
 |
| Another view of the inside - the paper separating the Arduino and the breadboard is to prevent the onboard LED lights from affecting the LDR. |
This was the simple part. However, a few challenges that cropped up:
- We don't know the base time (or time taken for a dot) of the Morse Code. Morse code specifies that a dash should be thrice the length of a dot, but does not exactly specify the time for a dot. We can use different "base times" to transmit the same message. I attempted to solve this by measuring the duration of the first 10 intervals of light/darkness and use this to estimate the base-time which would then be used to translate Morse to text.
- Since this is an analog signal there is no such things as fully off/on for the light. So we need to develop threshold above which we consider the bulb to be on, and threshold below which the bulb is said to be off. I used 800 as the cutoff for light, and 200 as the cutoff for darkness.
All in all, this was more challenging than expected... and sadly did not work. The code I wrote simply refused to give out any output - also the base-time estimates that it showed were waay of the mark.
View the code I used
here.
Despite a lot of trials in trying to debug, the errors persisted, and for today, I give up. I spent more than 6 hours on this and am just bored of it. Possible reasons for errors:
- Maybe the LDRs response time is not fast enough to note the quick transition from light to dark associated with a dot. When I tried sending the morse signal "SOS" the program could generally detect only 5-6 on/offs, while there should be atleast a total of 9. This however, doesn't explain the fact of why the code doesn't do better even when the transmission speed is decreased (to even as low as 50 dots/minute or basetime of ~0.8s)
- Maybe the threshold values of 800 and 200 that I chose are causing the problems. Maybe the limits I set are too strict... But then - general tests showed analog values > 1000 when my cell flash was on and <100 when there was no light. So, the boundaries should work.
- If you've looked at the code you'll notice that:
- First 10 durations of dark/light are observed.
- Then the program does a bunch of calculations to determine base-time
- While those calculations are being done, we do not continue to check the brightness levels. This *might* cause us to miss a quick flash of light or two, but I think it's unlikely - C is an extraordinarily fast language, and those instructions can't slow it down more than a few milliseconds at most.
Things to try:
- Simplify the program. Maybe stick to a fixed base-time that is entered by the user.
- Debug the existing program.
Edit (4/July/2018): Finally got the program working (somewhat). The main problem I had yesterday was
how do I know the time duration of a dot? Yesterday I tried determining that automatically, but that didn't really work. The "auto-detection" code I wrote was a miserable failure (I tried to save the time durations of the first five light flashes and the darkness between them. The light flashes/darkness must either be
x or
3x - using that info, I tried arriving at an average dot duration or 'x' value by weighted averages but that was a miserable failure). Today, I got three ways for asking the user to enter the base time/duration of a dot:
- Ask user to input at what speed he'll transmit in (in units of WPM or words per minute) - buuut there's no standard value for 1 WPM as words vary in length. Wikipedia said dot duration = 1200/(WPM value) but that again was an approximation. Also, asking users to type in stuff is lame.
- Ask user to first transmit the letter 'E' and measure the time period of flash. Since morse codeof letter 'e' is just a dot ('.'), we get dot duration.
- Another approach would be to ask the user to first transmit the string "EEE" and average the time duration of the three flashes
I wrote code for all the above three approaches but ended up using the second option because it was working the most effectively + simplicity.
Click
here for today's code.
 |
| A screenshot of the program at work. The string I entered was the alphabets "ABCD...Z" |
|
With that out of the way, more problems cropped up today:
- That morse code that the Android App is flashing is kinda weird - dashes, on average, are only 2.25 times more than dots; according to official morse rules, dash = 3 * dot.
- The program detects the first few letters okayishly. After the 5th or 6th letter it starts messing up - maybe it is due to fatigue of the LDR due to the constant changes in light. After a while perhaps the LDR just gets saturated and doesn't respond as quickly to changes in light intensity.
- It's slow. Anything faster than 5WPM and accuracy in results takes a plunge. The LDR isn't fast enough to detect Morse at 40-50WPM.
Well, that's that! Time to move on to something else, I guess!
This comment has been removed by the author.
ReplyDelete