Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Arduino SWR Meter
/*
* Arduino SWR Meter
* Por Alejandro Santos LU4EXT (alejolp@gmail.com)
*
* Conectar en Analog0 la salida de potencia directa, y en Analog1 la salida de reflejada.
* Creado para usarlo junto a un puente de ROE, por ejemplo el de XQ2FOD.
* http://ludens.cl/Electron/swr/swr.html
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("SWR METER LU4EXT");
delay(1500);
}
int pf=0, pr=0;
#define A 0.9
void loop() {
int pr_real, pf_real, modulo;
float p, swr;
pf_real = analogRead(0);
pr_real = analogRead(1);
pf = pf_real * A + pf * (1-A);
pr = pr_real * A + pr * (1-A);
p = sqrt( ((float)pr) / pf );
swr = (1+p)/(1-p);
modulo = (int)(swr*100)%100;
lcd.setCursor(0, 0);
lcd.print("f:");
lcd.print(pf);
lcd.print(" r:");
lcd.print(pr);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("SWR: ");
lcd.print((int)swr);
lcd.print(".");
if (modulo < 10) {
lcd.print("0");
lcd.print(modulo);
} else {
lcd.print(modulo);
}
lcd.print(" ");
lcd.print(millis()/1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment