Go Down

Topic: Fox Hunt for Amatrue Radio (Read 3304 times) previous topic - next topic

K7TFS

Feb 04, 2017, 06:20 am Last Edit: Feb 04, 2017, 08:35 am by K7TFS
I am working on a Fox Hunt Transmitter for ham radio.  I am having a problem getting my relay to control my Push To Talk mode on my Baofeng.  Basically what I need is to short the negative lead of my mike to the negative of my speaker to activate my PTT.  Everything else works.  Just will not work well on VOX mode.  Just need help in void setup and void loop.

Thanks  
Karl Collett
K7TFS

here is my code

Code: [Select]
/* Morse Code Fox Transmitter Ske5tch */
/* for Sonobuoy Fox Hunt Transmitter http://www.qsl.net/kp4md/sonobuoy.htm */
/* Original code by MH Atkinson http://www.multiwingspan.co.uk */
/* Loop code by K Hooke KK6DCT http://www.kevinhooke.com */
/* Look-up table completed by C Milazzo KP4MD http://www.qsl.net/kp4md */
/* PTT Relay K7TFS K7TFS15@gmail.com */
#include "pitches.h"
#define PTT 10;
const int buzzerPin =8;
const int ledPin = 13;
const int tonefreq = 1200; //change to 2500 for louder piezo output
int melody[] = {
 NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
 4, 8, 8, 4, 4, 8, 4, 4
};


// constants for tone and rest durations
const int dotlength = 100;
const int dashlength = dotlength * 3;
// inter-element gap - between each dot or dash of a letter
const int inter = dotlength;
// letter gap is 3 dots - the inter gap is always added - so this is one fewer
const int lgap = dotlength * 2; // inter-letter gap
// word gap is 7 dots - with letter and inter gap already counted, this is -1
const int wgap = dotlength * 4; //inter-word gap

const char message[] = "  K7TFS FOX HUNT TESTING CAN YOU FIND ME? K7TFS +                                   "; //text must be in CAPITALS

void setup(){
{
 pinMode (PTT, OUTPUT);
}
}
void loop() {
 {
   digitalWrite(PTT, HIGH);
 }
  // iterate over the notes of the melody:
 for (int thisNote = 0; thisNote < 8; thisNote++) {

   // to calculate the note duration, take one second
   // divided by the note type.
   //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
   int noteDuration = 1000 / noteDurations[thisNote];
   tone(8, melody[thisNote], noteDuration);

   // to distinguish the notes, set a minimum time between them.
   // the note's duration + 30% seems to work well:
   int pauseBetweenNotes = noteDuration * 1.30;
   delay(pauseBetweenNotes);
   // stop the tone playing:
   noTone(8);
 }
 {
 for (int currentLetterIndex; currentLetterIndex < sizeof(message); currentLetterIndex++)
 {char currentLetter = message[currentLetterIndex];
   soundLetter(currentLetter);
 }
 }
 {
   digitalWrite(PTT, LOW);
 }
}
void soundLetter(char letter)
{
 // Serial.print(letter);
 // letters are in alphabetic order, then numbers, then punctuation and prosigns
 switch (letter)
 {
   case 'A':
     dit(); dah();
     break;
   case 'B':
     dah(); dit(); dit(); dit();
     break;
   case 'C':
     dah(); dit(); dah(); dit();
     break;
   case 'D':
     dah(); dit(); dit();
     break;
   case 'E':
     dit();
     break;
   case 'F':
     dit(); dit(); dah(); dit();
     break;
   case 'G':
     dah(); dah(); dit();
     break;
   case 'H':
     dit(); dit(); dit(); dit();
     break;
   case 'I':
     dit(); dit();
     break;
   case 'J':
     dit(); dah(); dah(); dah();
     break;
   case 'K':
     dah(); dit(); dah();
     break;
   case 'L':
     dit(); dah(); dit(); dit();
     break;
   case 'M':
     dah(); dah();
     break;
   case 'N':
     dah(); dit();
     break;
   case 'O':
     dah(); dah(); dah();
     break;
   case 'P':
     dit(); dah(); dah(); dit();
     break;
   case 'Q':
     dah(); dah(); dit(); dah();
     break;
   case 'R':
     dit(); dah(); dit();
     break;
   case 'S':
     dit(); dit(); dit();
     break;
   case 'T':
     dah();
     break;
   case 'U':
     dit(); dit(); dah();
     break;
   case 'V':
     dit(); dit(); dit(); dah();
     break;
   case 'W':
     dit(); dah(); dah();
     break;
   case 'X':
     dah(); dit(); dit(); dah();
     break;
   case 'Y':
     dah(); dit(); dah(); dah();
     break;
   case 'Z':
     dah(); dah(); dit(); dit();
     break;
   case '1':
     dit(); dah(); dah(); dah(); dah();
     break;
   case '2':
     dit(); dit(); dah(); dah(); dah();
     break;
   case '3':
     dit(); dit(); dit(); dah(); dah();
     break;
   case '4':
     dit(); dit(); dit(); dit(); dah();
     break;
   case '5':
     dit(); dit(); dit(); dit(); dit();
     break;
   case '6':
     dah(); dit(); dit(); dit(); dit();
     break;
   case '7':
     dah(); dah(); dit(); dit(); dit();
     break;
   case '8':
     dah(); dah(); dah(); dit(); dit();
     break;
   case '9':
     dah(); dah(); dah(); dah(); dit();
     break;
   case '0':
     dah(); dah(); dah(); dah(); dah();
     break;
   case '.':
     dit(); dah(); dit(); dah(); dit(); dah();
     break;
   case '?':
     dit(); dit(); dah(); dah(); dit(); dit();
     break;
   case ',':
     dah(); dah(); dit(); dit(); dah(); dah();
     break;
   case '=':
     dah(); dit(); dit(); dit(); dah(); // = BT (double dash) prosign
     break;
   case '+':
     dit(); dah(); dit(); dah(); dit(); // + AR (end of message) prosign
     break;
   case '%':
     dit(); dah(); dit(); dit(); dit(); // % AS (wait) prosign
     break;
   case ')':
     dah(); dit(); dah(); dah(); dit(); // ) KN (go ahead, exclusive) prosign
     break;
   case '/':
     dah(); dit(); dit(); dah(); dit();
     break;
   case ']':
     dit(); dit(); dit(); dah(); dit(); dah(); // ] SK prosign
     break;
   case ' ':
     delay(wgap);
     break;
 }

 delay(lgap);
}

void dit()
{
 // play a dot
 tone(buzzerPin, tonefreq);
 // LED on
 digitalWrite(ledPin, HIGH);
 delay(dotlength);
 noTone(buzzerPin);
 // LED off
 digitalWrite(ledPin, LOW);
 delay(inter);
}

void dah()
{
 // play a dash
 tone(buzzerPin, tonefreq);
 // LED on
 digitalWrite(ledPin, HIGH);
 delay(dashlength);
 noTone(buzzerPin);
 // LED off
 digitalWrite(ledPin, LOW);
 delay(inter);
}

 

UKHeliBob

Quote
I am having a problem getting my relay to control my Push To Talk mode on my Baofeng
The problem being what exactly ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

TomGeorge

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

K7TFS

The problem being what exactly ?
The relay will not close on the high or open on the low commands.  I have vcc to 5v gnd ro gnd and my switch wire to pin 10.  I hooked my speaker negative to the middle post and my Mic negative to the NO post.  Is that correct?

TomGeorge

#4
Feb 04, 2017, 09:51 am Last Edit: Feb 04, 2017, 09:55 am by TomGeorge
Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What model baofeng?

Thanks..  Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

spycatcher2k

Also - post the type of relay you have, and how you are driving it.
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

K7TFS

One capital letter sure does make a difference.  It is now fixed.  I am happy

el_supremo

The code you posted wouldn't compile because of this:
Code: [Select]
#define PTT 10;

The initialization of this for loop is not correct/complete:
Code: [Select]
   for (int currentLetterIndex; currentLetterIndex < sizeof(message); currentLetterIndex++) {


Which capital letter made the difference?

Pete
Don't send me technical questions via Private Message.

K7TFS

I got everything fixed.  The Capital letter thing was a diss on me because it was just an easy fix.  I thought I would post my final code and my schematics if any one else wants to try their hand at it and maybe improving it.  In my schematics I may have used the wrong part for my terminal block but it was the closest I could find to what I wanted.  Please let me know what you think.  Thanks for all the help on this project.


Code: [Select]
/* Morse Code Fox Transmitter Ske5tch */
/* for Sonobuoy Fox Hunt Transmitter http://www.qsl.net/kp4md/sonobuoy.htm */
/* Original code by MH Atkinson http://www.multiwingspan.co.uk */
/* Loop code by K Hooke KK6DCT http://www.kevinhooke.com */
/* Look-up table completed by C Milazzo KP4MD http://www.qsl.net/kp4md */
/* PTT Relay K7TFS K7TFS15@gmail.com tested with BAOFENG */
 #define CH1 10   // Connect Digital Pin 10 on Arduino to Relay Module
const int buzzerPin =8;
const int ledPin = 13;
const int tonefreq = 1200; //change to 2500 for louder piezo output

// constants for tone and rest durations
const int dotlength = 100;
const int dashlength = dotlength * 3;
// inter-element gap - between each dot or dash of a letter
const int inter = dotlength;
// letter gap is 3 dots - the inter gap is always added - so this is one fewer
const int lgap = dotlength * 2; // inter-letter gap
// word gap is 7 dots - with letter and inter gap already counted, this is -1
const int wgap = dotlength * 4; //inter-word gap

const char message[] = "  K7TFS TEST K7TFS +"; //text must be in CAPITALS

void setup(){
   //Setup all the Arduino Pins
   pinMode(CH1, OUTPUT);
   pinMode(buzzerPin, OUTPUT);
   pinMode(ledPin, OUTPUT);
   
   //Turn OFF any power to the Relay channels
   digitalWrite(CH1,LOW);
   delay(2000); //Wait 2 seconds before starting sequence
{
}
}
void loop() {
    digitalWrite(CH1, HIGH); //PTT to switch on
    delay(1000);  //Delay for 1 second to alow radio to respond before  message
 
    for (int currentLetterIndex; currentLetterIndex < sizeof(message); currentLetterIndex++)
  {char currentLetter = message[currentLetterIndex];
    soundLetter(currentLetter);
  }
   delay(1000);  //Delay for 1 second before PTT switch off to alow all message to transmit
  digitalWrite(CH1, LOW);   //Turns off PTT
   delay(120000);  //Delay to next transmit 60000 per minuite
}
void soundLetter(char letter)
{
  // Serial.print(letter);
  // letters are in alphabetic order, then numbers, then punctuation and prosigns
  switch (letter)
  {
    case 'A':
      dit(); dah();
      break;
    case 'B':
      dah(); dit(); dit(); dit();
      break;
    case 'C':
      dah(); dit(); dah(); dit();
      break;
    case 'D':
      dah(); dit(); dit();
      break;
    case 'E':
      dit();
      break;
    case 'F':
      dit(); dit(); dah(); dit();
      break;
    case 'G':
      dah(); dah(); dit();
      break;
    case 'H':
      dit(); dit(); dit(); dit();
      break;
    case 'I':
      dit(); dit();
      break;
    case 'J':
      dit(); dah(); dah(); dah();
      break;
    case 'K':
      dah(); dit(); dah();
      break;
    case 'L':
      dit(); dah(); dit(); dit();
      break;
    case 'M':
      dah(); dah();
      break;
    case 'N':
      dah(); dit();
      break;
    case 'O':
      dah(); dah(); dah();
      break;
    case 'P':
      dit(); dah(); dah(); dit();
      break;
    case 'Q':
      dah(); dah(); dit(); dah();
      break;
    case 'R':
      dit(); dah(); dit();
      break;
    case 'S':
      dit(); dit(); dit();
      break;
    case 'T':
      dah();
      break;
    case 'U':
      dit(); dit(); dah();
      break;
    case 'V':
      dit(); dit(); dit(); dah();
      break;
    case 'W':
      dit(); dah(); dah();
      break;
    case 'X':
      dah(); dit(); dit(); dah();
      break;
    case 'Y':
      dah(); dit(); dah(); dah();
      break;
    case 'Z':
      dah(); dah(); dit(); dit();
      break;
    case '1':
      dit(); dah(); dah(); dah(); dah();
      break;
    case '2':
      dit(); dit(); dah(); dah(); dah();
      break;
    case '3':
      dit(); dit(); dit(); dah(); dah();
      break;
    case '4':
      dit(); dit(); dit(); dit(); dah();
      break;
    case '5':
      dit(); dit(); dit(); dit(); dit();
      break;
    case '6':
      dah(); dit(); dit(); dit(); dit();
      break;
    case '7':
      dah(); dah(); dit(); dit(); dit();
      break;
    case '8':
      dah(); dah(); dah(); dit(); dit();
      break;
    case '9':
      dah(); dah(); dah(); dah(); dit();
      break;
    case '0':
      dah(); dah(); dah(); dah(); dah();
      break;
    case '.':
      dit(); dah(); dit(); dah(); dit(); dah();
      break;
    case '?':
      dit(); dit(); dah(); dah(); dit(); dit();
      break;
    case ',':
      dah(); dah(); dit(); dit(); dah(); dah();
      break;
    case '=':
      dah(); dit(); dit(); dit(); dah(); // = BT (double dash) prosign
      break;
    case '+':
      dit(); dah(); dit(); dah(); dit(); // + AR (end of message) prosign
      break;
    case '%':
      dit(); dah(); dit(); dit(); dit(); // % AS (wait) prosign
      break;
    case ')':
      dah(); dit(); dah(); dah(); dit(); // ) KN (go ahead, exclusive) prosign
      break;
    case '/':
      dah(); dit(); dit(); dah(); dit();
      break;
    case ']':
      dit(); dit(); dit(); dah(); dit(); dah(); // ] SK prosign
      break;
    case ' ':
      delay(wgap);
      break;
  }

  delay(lgap);
}

void dit()
{
  // play a dot
  tone(buzzerPin, tonefreq);
  // LED on
  digitalWrite(ledPin, HIGH);
  delay(dotlength);
  noTone(buzzerPin);
  // LED off
  digitalWrite(ledPin, LOW);
  delay(inter);
}

void dah()
{
  // play a dash
  tone(buzzerPin, tonefreq);
  // LED on
  digitalWrite(ledPin, HIGH);
  delay(dashlength);
  noTone(buzzerPin);
  // LED off
  digitalWrite(ledPin, LOW);
  delay(inter);
}
 

TomGeorge

Hi,
OPs Circuit

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Your Fritzy is just a picture.

Also a bit confusing as to how you are controlling the relay, in your picture it should be ON all the time that power is applied, that is the coil is connected to gnd and the 5V supply.

Please hand draw a circuit and post a picture of it and a picture of you project so we can see your component layout.

If you are really controlling the relay coil directly from the controller, what is the relay specs please, as you can only at the maximum draw 40mA.
Alsi you have no back EMF diode on the relay coil.

Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

el_supremo

You still haven't fixed this:
The initialization of this for loop is not correct/complete:
Code: [Select]
  for (int currentLetterIndex; currentLetterIndex < sizeof(message); currentLetterIndex++) {

Pete
Don't send me technical questions via Private Message.

K7TFS

You still haven't fixed this:
Pete
I wished I was smarter than I was because I don't understand this part of the code.  I just brought several sketches together to make what I wanted.  What I posted is working as I wanted it to work.  I have use it on several fox hunts as well to test it out.  If you can elaborate on what the problem is or why it shouldn't work I would love to learn more.  I have only been working with Arduino for about 4 months now very much a nubee.

K7TFS

I know there are still some questions about my code I wished I knew more to understand what shouldn't be working but I am learning. 
Some questions were asked about the Relay Module.  I only use the module to close the loop between the mic ground and the speaker ground as that is how the Push to Talk mode is activated on the Baoefeng.  The arduino is only used to activate the Relay switch.  The picture from Fritzing software did not have a good representation of the relay module I was using and I have yet figured out all the in's and out's of making my own part.  so in the picture you will see three wires from the relay module and the arduino +5v, Gnd, and Switch.
The 3.5mm jack is for communication to the Radio.
I hope this helps out

73's
Karl
K7TFS

TomGeorge

#13
Mar 26, 2017, 10:07 am Last Edit: Mar 26, 2017, 10:08 am by TomGeorge
Hi,
K7TSF I would hope in your ham radio class you were taught how to read and draw basic circuit diagrams.
So can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

You picture does not show the relay board top.
You are trying to connect to this?

Tom... :)

Everything runs on smoke, let the smoke out, it stops running....

el_supremo

Quote
If you can elaborate on what the problem is
In the for loop, the first part is used to initialize one or more variables. The way you have it written, the variable is declared but not initialized. It will have whatever random value is on the stack when the for loop is executed. You have been lucky that the stack value happened to be zero (or possibly a small negative number) which will give the correct output. If later on, you or someone else changes the code, the value on the stack may change and the sketch will start acting strangely with no apparent cause.
You should use this:
Code: [Select]
  for (int currentLetterIndex = 0; currentLetterIndex < sizeof(message); currentLetterIndex++) {

Another very minor fix is to remove this pair of braces in the setup function after the delay statement.
Code: [Select]
{
}

They do nothing and the compiler will ignore them.

Your code will be more readable if you use the Tools|Auto Format menu item in the IDE.

Pete
Don't send me technical questions via Private Message.

Go Up