This is a project I worked on a while ago, but never finished it due to time. I will update my site or this post when I get it working how I want.
This code is free to use and edit, as long as the credit to me is left at the top. Thanks.
I don’t remember if I ever got the band to save, so that might not be working.
You should expect to edit or add to the “void BandSetup()” section.
You can also hard-code the band to a relay setting.
I never got around to setting up outputs for the relays, but that should be simple to add.
/* HF Band Detecting Auto Antenna Switch
Designed by
KC8GRQ - Mark Rodgers
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
#define A 2
#define B 3
#define C 4
#define D 5
#define Select 6
#define Next 7
int AntennaPort = '1';
int Band = '0';
void setup()
{
pinMode(A, INPUT);
pinMode(B, INPUT);
pinMode(C, INPUT);
pinMode(D, INPUT);
pinMode(Select, INPUT);
pinMode(Next, INPUT);
// digitalWrite(Select, LOW);
// digitalWrite(Next, LOW);
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("Auto Antenna Switch ");
lcd.setCursor(0, 2);
lcd.print(" KC8GRQ ");
delay(3000);
lcd.clear();
}
void ReadRadio()
{
digitalRead(A);
digitalRead(B);
digitalRead(C);
digitalRead(D);
if (digitalRead(A) == LOW && digitalRead(B) == LOW && digitalRead(C) == LOW && digitalRead(D) == HIGH)
{ lcd.setCursor(0, 0);
lcd.print(" 160 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 1.8 to 2.0 Mhz ");
lcd.print(" Random Legth Wire "); }
else if
(digitalRead(A) == LOW && digitalRead(B) == LOW && digitalRead(C) == HIGH && digitalRead(D) == LOW)
{ lcd.setCursor(0, 0);
lcd.print(" 80 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 3.5 to 4.0 Mhz ");
lcd.print(" G5RV East / West "); }
else if
(digitalRead(A) == HIGH && digitalRead(B) == LOW && digitalRead(C) == HIGH && digitalRead(D) == LOW)
{ lcd.setCursor(0, 0);
lcd.print(" 60 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 5.330 - 5.403 Mhz ");
lcd.print(" G5RV East / West "); }
else if
(digitalRead(A) == LOW && digitalRead(B) == LOW && digitalRead(C) == HIGH && digitalRead(D) == HIGH)
{ lcd.setCursor(0, 0);
lcd.print(" 40 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 7.0 to 7.3 Mhz ");
lcd.print(" G5RV East / West "); }
else if
(digitalRead(A) == LOW && digitalRead(B) == HIGH && digitalRead(C) == LOW && digitalRead(D) == LOW)
{ lcd.setCursor(0, 0);
lcd.print(" 30 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 10.1 to 10.15 Mhz ");
lcd.print(" Triband 3 EL Yagi "); }
else if
(digitalRead(A) == LOW && digitalRead(B) == HIGH && digitalRead(C) == LOW && digitalRead(D) == HIGH)
{ lcd.setCursor(0, 0);
lcd.print(" 20 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 14.0 to 14.35 Mhz ");
lcd.print(" Triband 3 EL Yagi "); }
else if
(digitalRead(A) == LOW && digitalRead(B) == HIGH && digitalRead(C) == HIGH && digitalRead(D) == LOW)
{ lcd.setCursor(0, 0);
lcd.print(" 17 Meters ");
lcd.setCursor(0, 1);
lcd.print("18.068 to 18.168 Mhz");
lcd.print(" Triband 3 EL Yagi "); }
else if
(digitalRead(A) == LOW && digitalRead(B) == HIGH && digitalRead(C) == HIGH && digitalRead(D) == HIGH)
{ lcd.setCursor(0, 0);
lcd.print(" 15 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 21.0 to 21.45 Mhz ");
lcd.print(" Triband 3 EL Yagi "); }
else if
(digitalRead(A) == HIGH && digitalRead(B) == LOW && digitalRead(C) == LOW && digitalRead(D) == LOW)
{ lcd.setCursor(0, 0);
lcd.print(" 12 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 24.89 to 24.99 Mhz ");
lcd.print(" 10 / 12 Vertical "); }
else if
(digitalRead(A) == HIGH && digitalRead(B) == LOW && digitalRead(C) == LOW && digitalRead(D) == HIGH)
{ lcd.setCursor(0, 0);
lcd.print(" 10 Meters ");
lcd.setCursor(0, 1);
lcd.print(" 28.0 to 29.7 Mhz ");
lcd.print(" 10 / 12 Vertical "); }
else
{ lcd.setCursor(0, 0);
lcd.print(" ** ERROR ** ");
lcd.setCursor(0, 1);
lcd.print(" No Radio Data ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print("Check Wiring & Radio"); }
}
void BandSetup()
{
lcd.setCursor(0, 0);
lcd.print(" * Setup Mode * ");
lcd.setCursor(0, 1);
lcd.print("Band: ");
lcd.setCursor(6, 1);
if (Band == '0') { lcd.print("160 Meters"); } else
if (Band == '1') { lcd.print("80 Meters "); } else
if (Band == '2') { lcd.print("60 Meters "); } else
if (Band == '3') { lcd.print("40 Meters "); } else
if (Band == '4') { lcd.print("30 Meters "); } else
if (Band == '5') { lcd.print("20 Meters "); } else
if (Band == '6') { lcd.print("17 Meters "); } else
if (Band == '7') { lcd.print("15 Meters "); } else
if (Band == '8') { lcd.print("12 Meters "); } else
if (Band == '9') { lcd.print("10 Meters "); }
// Scroll Thru The Bands
if (Band > '9') {
Band = '0';
}
if (digitalRead(Next) == HIGH) {
Band++; }
// The band is selected that we want to edit, now set AntennaPort
if (digitalRead(Select) == HIGH) {
lcd.setCursor(0, 2);
lcd.print("Antenna Port # ");
lcd.setCursor(16, 2);
lcd.write(AntennaPort);
// Scroll Thru The Antenna Ports
if (AntennaPort > '4') {
AntennaPort = '1';
}
if (digitalRead(Next) == HIGH) {
AntennaPort++; }
}
// OK, now we have set the Band to the Antenna Port, lets save it.
if (digitalRead(Select) == HIGH) {
lcd.setCursor(0, 3);
lcd.print(" * Settings Saved * "); }
}
void loop()
{
// ReadRadio();
// if (digitalRead(Select) == HIGH) { BandSetup(); }
lcd.setCursor(0, 0);
lcd.print(" * Setup Mode * ");
lcd.setCursor(0, 1);
lcd.print("Band: ");
lcd.setCursor(6, 1);
if (Band == '0') { lcd.print("160 Meters"); } else
if (Band == '1') { lcd.print("80 Meters "); } else
if (Band == '2') { lcd.print("60 Meters "); } else
if (Band == '3') { lcd.print("40 Meters "); } else
if (Band == '4') { lcd.print("30 Meters "); } else
if (Band == '5') { lcd.print("20 Meters "); } else
if (Band == '6') { lcd.print("17 Meters "); } else
if (Band == '7') { lcd.print("15 Meters "); } else
if (Band == '8') { lcd.print("12 Meters "); } else
if (Band == '9') { lcd.print("10 Meters "); }
// Scroll Thru The Bands
if (Band > '9') {
Band = '0';
}
if (digitalRead(Next) == HIGH) {
Band++; }
// The band is selected that we want to edit, now set AntennaPort
if (digitalRead(Select) == HIGH) {
lcd.setCursor(0, 2);
lcd.print("Antenna Port # ");
lcd.setCursor(16, 2);
lcd.write(AntennaPort);
// Scroll Thru The Antenna Ports
if (AntennaPort > '4') {
AntennaPort = '1';
}
if (digitalRead(Next) == HIGH) {
AntennaPort++; }
}
// OK, now we have set the Band to the Antenna Port, lets save it.
if (digitalRead(Select) == HIGH) {
lcd.setCursor(0, 3);
lcd.print(" * Settings Saved * "); }
}








