Go Down

Topic: Arduino Morse code receiver - Help needed please! (Read 185 times) previous topic - next topic

C19378136

I'm new to Arduino as I've just started it in college so please bare with me.
I don't know how to write Arduino C either.

I made a very basic Morse code sender using a button and a buzzer. Hold the button to make the beep, Dot or Dash. (Hold longer for Dash)
Using another arduino I made a receiver using a microphone and an LCD display. I was able to use the serial monitor to display the sound level and was given a hand by someone to implement the threshold for the buzzer sound.

Context out of the way; I have an Dash showing up on the LCD when the sound level reaches the threshold, now I need to add some sort of duration to the code. eg. Longer time above threshold for Dash, else Dot.

I'll attach the code below. I did not write this code I just modified examples of code to suit my needs.

Thank you very much for your help!

C19378136

Note: I have a line in the code
"if (analogRead(A0) > 700) for (delay(100)){ //if detected sound is above threshold for duration Print DASH"

The "for (delay(100))" part I wrote and it doesn't work. I'm unsure what to use here.
Thanks

slipstick

What were you hoping it would do? It's difficult to work out because the code makes no real sense. I hope its not what the comment says cus that'll never happen.

Steve

MarkT

This sort of problem requires a state-machine.  Various events and time-outs are used to trigger transistions between states.

Here you have states like idle, dot_or_dash, dash.

When a beep starts you want to transition idle -> dot_or_dash and record the time.
When in dot_or_dash state and the time since entering the state goes over the threshold you transistion
to dash state.  Beep ending transitions dot_or_dash to idle and emits a dot.  Beep ending transistions dash state to idle and emits a dash.

You'll need a few more states for recognizing word gaps.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

C19378136

What were you hoping it would do? It's difficult to work out because the code makes no real sense. I hope its not what the comment says cus that'll never happen.

Steve
I'm using a Grove starter kit set, I've only been using it for a week.
My aim is to display a dot or dash on the LCD when the microphone detects a sound over a threshold for a duration.

Thanks.

C19378136

This sort of problem requires a state-machine.  Various events and time-outs are used to trigger transistions between states.

Here you have states like idle, dot_or_dash, dash.

When a beep starts you want to transition idle -> dot_or_dash and record the time.
When in dot_or_dash state and the time since entering the state goes over the threshold you transistion
to dash state.  Beep ending transitions dot_or_dash to idle and emits a dot.  Beep ending transistions dash state to idle and emits a dash.

You'll need a few more states for recognizing word gaps.
Hi, I've only been using an arduino for a week so I'm very inexperienced. Can you expand on how to write these states into my code?

Thank you very much.

dougp

The state machine MarkT references is usually implemented in Arduino land with the switch/case construct.  There are examples and explanations all over the web and in the tutorials topic on this site.

In addition, there's the https://www.arduino.cc/reference/en/ page where this and many other essential parts of the language are listed.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

slipstick

Your life would be a lot easier if instead of a plain microphone you used a sound detector board with the threshold built-in and a digital output - above threshold/below threshold. Something like https://www.sparkfun.com/products/12642

Then you would use the StateChangeDetection technique from the IDE example of that name and just measure the time between going above and coming back down to below.

Steve

C19378136

The state machine MarkT references is usually implemented in Arduino land with the switch/case construct.  There are examples and explanations all over the web and in the tutorials topic on this site.

In addition, there's the https://www.arduino.cc/reference/en/ page where this and many other essential parts of the language are listed.
That's very helpful, I'll look into that.
Thank you.

C19378136

Your life would be a lot easier if instead of a plain microphone you used a sound detector board with the threshold built-in and a digital output - above threshold/below threshold. Something like https://www.sparkfun.com/products/12642

Then you would use the StateChangeDetection technique from the IDE example of that name and just measure the time between going above and coming back down to below.

Steve
Sorry I was told it was a microphone, I just looked up the set and it's called "Grove - Sound Sensor", so not a microphone.
How do I measure the time between going above and down to below?

slipstick

Despite the name it is just a microphone with amplifier. It does not have any way for you to set a threshold or any digital output like the Sparkfun sounds sensor board or most other sound sensors (like the well-known KY-038 sensor found in many starter kits).

You can still use that Grove sensor it but it will involve a fair bit more coding because you will have to keep checking the level and deciding if it's just become above threshold (note the time), is still above threshold or has just gone below threshold (note the time again).

Steve

 




Go Up