Components and supplies
Arduino Pro Mini 328 - 3.3V/8MHz
Project description
Code
Acoustic Variometer code
arduino
1/* 2 This sketch act as Variometer for paragliding, by Marco Zonca, 2020 3 Arduino MiniPro 3.3 as CPU, GY-63 (MS5611) barometric pressure sensor, 8 x dipswitch, buzzer, 4 Mux 4051, lipo 1s 3.7v 350mA, 3.7v -> 5v voltage stepup + lipo usb charger; 5 6 DipSwitch: 1= not used 7 2= hw low/high buzzer volume 8 3= \sink alarm: OFF -1.0 -2.0 -3.0 m/sec 9 4= / 10 5= \frequency beeps: +1.0 +1.5 +2.0 +3.0 Hz 11 6= / 12 7= \sensibility: +0.0 +0.1 +0.2 +0.5 m/sec 13 8= / 14 */ 15 16#include <MS5611.h> 17#include <NewTone.h> 18 19const int muxIOpin = 15; 20const int vbattPin = 14; 21const int muxbit0 = 4; 22const int muxbit1 = 5; 23const int muxbit2 = 6; 24const int buzzerPin = 7; 25const int DIPSWinterval = 5000; 26const int BATTinterval = 10000; 27const int PrexInterval = 500; 28const boolean isDebug = false; 29 30float sensibility[5]; 31float frequency[5]; 32float sinkalarm[5]; 33long n=0; 34boolean dipswitch[9]; 35String dips; 36unsigned long prevDIPSWmillis = 0; 37unsigned long prevBATTmillis = 0; 38float n1=0; 39float n2=0; 40float SensorVBatt=0; 41double referencePressure = 0; 42unsigned long prevPrexMillis = 0; 43unsigned long currPrexMillis = 0; 44double realPressure = 0; 45float absoluteAltitude = 0; 46float relativeAltitude = 0; 47float avgAltitude = 0; 48float avgPrevAltitude = 0; 49long PrexCounter = 0; 50float PrexTotal = 0; 51float PrexVario = 0; 52boolean isFirstCalc = true; 53 54MS5611 psensor; // pressure sensor 55 56void setup() { 57 Serial.begin(9600); 58 pinMode(muxbit0, OUTPUT); 59 pinMode(muxbit1, OUTPUT); 60 pinMode(muxbit2, OUTPUT); 61 pinMode(buzzerPin, OUTPUT); 62 63 sensibility[4]=0; 64 sensibility[3]=0.5; 65 sensibility[2]=0.2; 66 sensibility[1]=0.1; 67 sensibility[0]=0.0; 68 69 frequency[4]=0; 70 frequency[3]=3.0; 71 frequency[2]=2.0; 72 frequency[1]=1.5; 73 frequency[0]=1.0; 74 75 sinkalarm[4]=0; 76 sinkalarm[3]=-3.0; 77 sinkalarm[2]=-2.0; 78 sinkalarm[1]=-1.0; 79 sinkalarm[0]=-999.9; 80 81 readDIPswitch(); 82 psensor.begin(); 83 referencePressure = psensor.readPressure(); 84 if (isDebug == true) Serial.println("Vario is on"); 85 NewTone (buzzerPin,4); 86 delay(750); 87 noNewTone(); 88} // end setup() 89 90void loop() { 91 readPSensor(); 92 if ((prevDIPSWmillis+DIPSWinterval) < millis()) { 93 readDIPswitch(); 94 prevDIPSWmillis=millis(); 95 } 96 if ((prevBATTmillis+BATTinterval) < millis()) { 97 checkBATT(); 98 prevBATTmillis=millis(); 99 } 100} // end loop() 101 102void readPSensor() { // read Pressure Sensor 103 // Calculate average altitude and vario 104 realPressure = psensor.readPressure(); 105 absoluteAltitude = psensor.getAltitude(realPressure); 106 relativeAltitude = psensor.getAltitude(realPressure, referencePressure); 107 PrexCounter = PrexCounter + 1; 108 PrexTotal = PrexTotal + relativeAltitude; 109 currPrexMillis = millis(); 110 if (currPrexMillis - prevPrexMillis >= PrexInterval) { 111 avgAltitude = PrexTotal / PrexCounter; // average 112 if (isFirstCalc == true) { 113 avgPrevAltitude=avgAltitude; 114 isFirstCalc=false; 115 } 116 PrexVario=(avgAltitude-avgPrevAltitude) * (1000/PrexInterval); // vario mSec 117 if ((PrexVario <= sensibility[4]) && (PrexVario >= sinkalarm[4])) { 118 noNewTone(); 119 } 120 if ((PrexVario > sensibility[4])) { // lift beep beep + 121 NewTone (buzzerPin,((int)(PrexVario+frequency[4]))); 122 } 123 if ((PrexVario < sinkalarm[4])) { // sink beeeeeep - 124 NewTone (buzzerPin,0.1); 125 } 126 avgPrevAltitude=avgAltitude; 127 prevPrexMillis = currPrexMillis; 128 PrexTotal=0; 129 PrexCounter=0; 130 131 if (isDebug == true) { 132 Serial.print("Vario="); 133 Serial.println(PrexVario); 134 } 135 136 } 137} // end readPSensor() 138 139void readDIPswitch() { // read dipswitch 1-8 for settings 140 int s=0; 141 for (n=1; n<9; n++) { 142 dips="0000"+String(n-1, BIN); //leading zeros at left, compose 3 bits selection 143 dips=(dips.substring(dips.length()-3,dips.length())); 144 if (dips.substring(2,3) == "0") digitalWrite(muxbit0, LOW); // port selection (1-8) 145 else digitalWrite(muxbit0, HIGH); 146 if (dips.substring(1,2) == "0") digitalWrite(muxbit1, LOW); 147 else digitalWrite(muxbit1, HIGH); 148 if (dips.substring(0,1) == "0") digitalWrite(muxbit2, LOW); 149 else digitalWrite(muxbit2, HIGH); 150 if (analogRead(muxIOpin) > 512) dipswitch[n]=false; // read selected port 151 else dipswitch[n]=true; 152 if (isDebug == true) { 153 if (dipswitch[n]==false) Serial.print("0"); 154 else Serial.print("1"); 155 } 156 } // end for 157 if (isDebug == true) Serial.println(""); 158 s=0; 159 if (dipswitch[7]==true) s = s + 2; 160 if (dipswitch[8]==true) s = s + 1; 161 sensibility[4]=sensibility[s]; 162 if (isDebug == true) { 163 Serial.print("Sensibility="); 164 Serial.println(sensibility[4]); 165 } 166 s=0; 167 if (dipswitch[5]==true) s = s + 2; 168 if (dipswitch[6]==true) s = s + 1; 169 frequency[4]=frequency[s]; 170 if (isDebug == true) { 171 Serial.print("Frequency="); 172 Serial.println(frequency[4]); 173 } 174 s=0; 175 if (dipswitch[3]==true) s = s + 2; 176 if (dipswitch[4]==true) s = s + 1; 177 sinkalarm[4]=sinkalarm[s]; 178 if (isDebug == true) { 179 Serial.print("SinkAlarm="); 180 Serial.println(sinkalarm[4]); 181 } 182} // end readDIPswitch() 183 184void checkBATT() { // check lipo/liion battery voltage 185 n1 = analogRead(vbattPin); 186 n2=(((6.60 * n1) / 1023.00)); 187 SensorVBatt=(n2 + ((n2 * 0.0) /100)); // arbitrary correction (not active = 0.0%) 188 if (SensorVBatt <= 3.4) { 189 NewTone (buzzerPin,6,1000); 190 } 191 if (isDebug == true) { 192 Serial.print("VBatt="); 193 Serial.println(SensorVBatt); 194 } 195} // end checkBATT() 196 197
Downloadable files
Fritzing schematic
Fritzing schematic
Gerber PCB file
Gerber PCB file
Gerber PCB file
Gerber PCB file
Fritzing schematic
Fritzing schematic
Documentation
Solder face PCB
Solder face PCB
Components face PCB
Components face PCB
Components face PCB
Components face PCB
Solder face PCB
Solder face PCB
Comments
Only logged in users can leave comments
marcozonca
0 Followers
•0 Projects
Table of contents
Intro
6
0