////////////////////////////////////////// ///// SEQUENCER with ALC holdoff ///////// ////////////////////////////////////////// // ARDUINO NANO board // PTT on COM port by RTS (not DTR = reset function) // by ON7EQ - 10/2026 ///// DELAY & TIMING DEFINITIONS /////////////////////////////////////////////// // Going into TRANSMIT const int LnaOffDelay = 50; // LNA power off const int AntTXdelay = 50; // Antenna relay to TX const int PaTXdelay = 50; // PA into TX const int ALC_unblock_delay = 200; // Delay before releasing ALC negative voltage // Going into RECEIVE const int PaRXdelay = 50; // PA into RX const int AntRXdelay = 50; // Antenna relay to RX const int LnaOnDelay = 50; // LNA power on const unsigned long CooldownDelay = 2000; // min. time after TX before a new TX const unsigned long TX_tail = 100; // min. time in TX after the TX sequence finished const unsigned long ButtonLockout = 500; // push-button re-trigger lockout const unsigned long PanicLockout = 5000; // push-button TX locked this long after panic ///// LNA & ANT RELAY POLARITY (level on the pin when in RX) /////////////////// bool LNA_RX = 0; // 0 = open collector OPEN in RX, to ground in TX = LNA + ANT RLY, reversed by POL SWITCH BOX bool ANT_RLY_TX = 1; // 1 = open collector to ground in TX, OPEN in RX = for mouse jiggler bool PA_TX = 1; // 1 = open collector to ground in TX, OPEN in RX = for PA bool ALC_enabled = 1; // 1 = ALC holdoff enabled ///// PINS ///////////////////////////////////////////////////////////////////// const int pttInputPin = 2; // Foot-switch / external PTT (active LOW, pull-up) const int PushButtonPin = 3; // Momentary push button (active LOW) const int lnaPin = 4; // LNA power relay const int antennaPin = 5; // Antenna changeover relay const int paPin = 6; // PA relay const int radioPttPinOut = 7; // PTT to transceiver const int radioPttPinIn = 8; // PTT from transceiver (detects TX started by the radio) const int RS232_rts_pin = 9; // CH340 RTS strapped to D9 (active LOW) const int TONE_ALC_pin = 10; // Square wave to the negative charge pump const int LED_ALC_pin = 11; // LED: ALC holdoff active const int RX_LED_pin = 12; // LED: RX status const int TX_LED_pin = 13; // LED: TX requested const int setup_LNA_pin = A0; // Setup of LNA switch polarity const int setup_ANT_pin = A1; // Setup of ANT switch polarity const int setup_PA_pin = A2; // Setup of PA switch polarity const int setup_ALC_pin = A3; // Setup of ALC holdoff enable const int tell_tale_pin1 = A4; // Setup of tell-tale input pin - must be grounded to allow TX'ing const int tell_tale_pin2 = A5; // Setup of tell-tale input pin - must be grounded to allow TX'ing const unsigned int TONE_FREQ_HZ = 10000; // 10 kHz for charge pump efficiency ///// STATE //////////////////////////////////////////////////////////////////// bool isTransmitting = false; bool goIntoReceive = false; bool PushButtonPttActive = false; bool inCooldown = false; bool panic = false; // forced return to RX, waiting for operator reset bool wasinpanic = false; unsigned long ButtonPressTime = 0; unsigned long panicEndTime = 0; unsigned long txEndTime = 0; // when the last TX->RX sequence ended unsigned long txStartTime = 0; // when the last RX->TX sequence ended ///// HELPERS ////////////////////////////////////////////////////////////////// bool isLow(int pin) { return digitalRead(pin) == LOW; } // Foot switch or WSJT-X RTS bool extKeyActive() { return isLow(pttInputPin) || isLow(RS232_rts_pin); } // Any key source at all (incl. the radio's own PTT) bool anyKeyActive() { return extKeyActive() || isLow(radioPttPinIn); } // Set the level first, then make it an output (no glitch at power-up) void safeOutput(int pin, bool level) { digitalWrite(pin, level); pinMode(pin, OUTPUT); } // ALC holdoff: tone + LED on = negative voltage generated, ALC blocked void alcHoldoff(bool on) { if (on) tone(TONE_ALC_pin, TONE_FREQ_HZ); else noTone(TONE_ALC_pin); digitalWrite(LED_ALC_pin, on); } ///// SETUP //////////////////////////////////////////////////////////////////// void setup() { // Inputs first, so they never float pinMode(pttInputPin, INPUT_PULLUP); pinMode(radioPttPinIn, INPUT_PULLUP); pinMode(PushButtonPin, INPUT_PULLUP); pinMode(RS232_rts_pin, INPUT_PULLUP); pinMode(setup_LNA_pin, INPUT_PULLUP); pinMode(setup_ANT_pin, INPUT_PULLUP); pinMode(setup_PA_pin, INPUT_PULLUP); pinMode(setup_ALC_pin, INPUT_PULLUP); pinMode(tell_tale_pin1, INPUT_PULLUP); pinMode(tell_tale_pin2, INPUT_PULLUP); ///// Set switching polarities according to DIP SW position if (digitalRead(setup_LNA_pin) == HIGH) LNA_RX = 1; // in RX open collector is grounded (default : open) if (digitalRead(setup_ANT_pin)== HIGH) ANT_RLY_TX = 0; // in TX open collector is open (default : grounded) if (digitalRead(setup_PA_pin) == HIGH) PA_TX = 0; // in TX open collector is open (default : grounded) if (digitalRead(setup_ALC_pin) == HIGH) ALC_enabled = 0; // ALC holdoff disabled // Outputs, all starting in a safe state if (ALC_enabled == 1) { tone(TONE_ALC_pin, TONE_FREQ_HZ); // negative voltage ready before the radio can key safeOutput(LED_ALC_pin, HIGH); } safeOutput(lnaPin, !LNA_RX); // LNA off, in TX state safeOutput(paPin, !PA_TX); // PA disabled safeOutput(radioPttPinOut, LOW); // radio unkeyed safeOutput(TX_LED_pin, LOW); safeOutput(RX_LED_pin, LOW); // RX status unknown delay(200); safeOutput(antennaPin, ANT_RLY_TX); // antenna to TX position (fail-safe) Serial.begin(115200); delay(300); // Startup message on serial port Serial.println(" "); Serial.println("********************************"); Serial.println("* Smart EME Sequencer by ON7EQ *"); Serial.println("********************************"); Serial.println(" "); Serial.println("Version 1.00 dated 23 oct 2026"); Serial.println(" "); Serial.println("Arduino NANO board"); Serial.println("External KEY on this serial port for WSJT is by RTS only"); Serial.println(" "); Serial.println("Open collector outputs as now defined by DIP switches:"); Serial.print(" * LNA powered: "); if (LNA_RX == 1) Serial.print("to GROUND"); else Serial.print("OPEN"); Serial.println(" while receiving"); Serial.print(" * ANT Relay : "); if (ANT_RLY_TX == 1) Serial.print("to GROUND"); else Serial.print("OPEN"); Serial.println(" while transmitting"); Serial.print(" * PA key : "); if (PA_TX == 1) Serial.print("to GROUND"); else Serial.print("OPEN"); Serial.println(" while transmiiting"); Serial.print(" * AGC Holdoff : "); if (ALC_enabled == 1) Serial.println("Enabled"); else Serial.println("Disabled"); Serial.println(" "); Serial.println("Sequencer delays going into TX (ms)"); Serial.println(" "); Serial.print(" * LNA : "); Serial.println(LnaOffDelay); Serial.print(" * ANT Relay : "); Serial.println(AntTXdelay); Serial.print(" * PA Key : "); Serial.println(PaTXdelay); Serial.print(" * AGC off: "); Serial.println(ALC_unblock_delay); Serial.println(" "); Serial.println("Sequencer delays going into RX (ms)"); Serial.println(" "); Serial.print(" * PA unkey : "); Serial.println(PaRXdelay); Serial.print(" * ANT Relay : "); Serial.println(AntRXdelay); Serial.print(" * LNA : "); Serial.println(LnaOnDelay); Serial.println(" "); // Wait (blinking) until nobody is keying while (anyKeyActive()) { digitalWrite(TX_LED_pin, HIGH); delay(50); digitalWrite(TX_LED_pin, LOW); delay(50); } // Not keyed: go to RX delay(200); digitalWrite(antennaPin, !ANT_RLY_TX); delay(LnaOnDelay); digitalWrite(lnaPin, LNA_RX); digitalWrite(RX_LED_pin, HIGH); Serial.println("Now ready to go !"); Serial.println(" "); } ///// SEQUENCES //////////////////////////////////////////////////////////////// ///// RX -> TX. keyRadio = false when the radio itself already keyed.///////// void goTX(bool keyRadio) { Serial.println("--------------------------------"); Serial.println("Going into TX"); Serial.println(" "); digitalWrite(RX_LED_pin, LOW); digitalWrite(TX_LED_pin, HIGH); digitalWrite(lnaPin, !LNA_RX); // 1. LNA off Serial.println(" * LNA power Off"); delay(LnaOffDelay); digitalWrite(antennaPin, ANT_RLY_TX); // 2. antenna to TX Serial.println(" * ANT Relay to TX position"); delay(AntTXdelay); digitalWrite(paPin, PA_TX); // 3. PA on Serial.println(" * PA is keyed"); delay(PaTXdelay); while ((digitalRead(tell_tale_pin1) == HIGH)) { digitalWrite(TX_LED_pin, !digitalRead(TX_LED_pin)); // Tell-tale contact error digitalWrite(RX_LED_pin, !digitalRead(TX_LED_pin)); delay (100); } while ((digitalRead(tell_tale_pin2) == HIGH)) { digitalWrite(TX_LED_pin, !digitalRead(TX_LED_pin)); // Tell-tale contact error digitalWrite(RX_LED_pin, !digitalRead(TX_LED_pin)); delay (100); } digitalWrite(TX_LED_pin, HIGH); // Reset flashing now problem solved digitalWrite(RX_LED_pin, LOW); if (keyRadio) { digitalWrite(radioPttPinOut, HIGH); // 4. key the radio Serial.println(" * Radio is keyed"); } delay(ALC_unblock_delay); alcHoldoff(false); // 5. release ALC if (ALC_enabled == 1) { Serial.println(" * ALC is released"); } isTransmitting = true; txStartTime = millis(); // start of TX tail window } ////// TX -> RX ///////////////////////////////////////////////////////////// void goRX() { Serial.println("--------------------------------"); Serial.println("Going into RX"); Serial.println(" "); digitalWrite(TX_LED_pin, LOW); if (ALC_enabled == 1) { alcHoldoff(true); // block ALC first Serial.println(" * ALC is blocking RF output"); } digitalWrite(radioPttPinOut, LOW); // 1. unkey radio Serial.println(" * Radio is unkeyed"); delay(PaRXdelay); digitalWrite(paPin, !PA_TX); // 2. PA off Serial.println(" * PA is unkeyed"); delay(AntRXdelay); digitalWrite(antennaPin, !ANT_RLY_TX); // 3. antenna to RX Serial.println(" * ANT Relay to TX position"); delay(LnaOnDelay); digitalWrite(lnaPin, LNA_RX); // 4. LNA on Serial.println(" * LNA power On"); digitalWrite(RX_LED_pin, HIGH); isTransmitting = false; goIntoReceive = false; PushButtonPttActive = false; txEndTime = millis(); // start of cooldown window } // Blink until the operator holds the button with all key inputs released void panicWait() { while (panic) { digitalWrite(RX_LED_pin, LOW); digitalWrite(TX_LED_pin, HIGH); delay(50); digitalWrite(TX_LED_pin, LOW); digitalWrite(LED_ALC_pin, HIGH); delay(50); digitalWrite(LED_ALC_pin, LOW); digitalWrite(RX_LED_pin, HIGH); delay(50); if (millis() - txEndTime > 1000 && isLow(PushButtonPin) && !anyKeyActive()) { panic = false; delay(200); panicEndTime = millis(); } } } ///// MAIN LOOP //////////////////////////////////////////////////////////////// void loop() { if (millis() - panicEndTime > PanicLockout) wasinpanic = false; // 1. Push button: toggles TX; in TX it forces RX (panic if another key source is still active) if (isLow(PushButtonPin) && millis() - ButtonPressTime > ButtonLockout && !inCooldown) { delay(20); // debounce if (isLow(PushButtonPin)) { ButtonPressTime = millis(); if (!isTransmitting && !wasinpanic) { PushButtonPttActive = true; } else { goIntoReceive = true; if (extKeyActive()) panic = wasinpanic = true; } } } // 2. Radio-initiated PTT (ignore our own keying of the radio) bool trxPttActive = isLow(radioPttPinIn) && isLow(radioPttPinOut); // 3. Final TX request (OR of all sources) bool txRequested = extKeyActive() || trxPttActive || PushButtonPttActive; inCooldown = millis() - txEndTime < CooldownDelay; bool inTxTail = millis() - txStartTime < TX_tail; // 4. Sequencer if (txRequested && !isTransmitting && !inCooldown && !goIntoReceive) { goTX(!trxPttActive); } else if ((!txRequested && isTransmitting && !inTxTail) || goIntoReceive) { goRX(); Serial.println("------------------------------------------"); Serial.println("*** PANIC - attempting to revert to RX ***"); Serial.println("------------------------------------------"); panicWait(); } }