Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 Serial pc(USBTX, USBRX); 00004 00005 AnalogIn vrefint1(PA_3); 00006 AnalogIn vrefint2(PC_0); 00007 AnalogIn vrefint3(PC_3); 00008 AnalogIn vrefint4(PF_3); 00009 AnalogIn vrefint5(PF_5); 00010 AnalogIn vrefint6(PF_10); 00011 AnalogIn vrefint7(PB_1); 00012 AnalogIn vrefint8(PA_6); 00013 00014 DigitalOut Buzzer(PA_5); 00015 00016 DigitalOut led1(PF_15); 00017 DigitalOut led2(PE_13); 00018 DigitalOut led3(PF_14); 00019 DigitalOut led4(PE_11); 00020 DigitalOut led5(PE_9); 00021 DigitalOut led6(PF_13); 00022 DigitalOut led7(PF_12); 00023 DigitalOut led8(PD_15); 00024 00025 00026 00027 int main() 00028 { 00029 Buzzer = 0; 00030 led1 = 0; 00031 led2 = 0; 00032 led3 = 0; 00033 led4 = 0; 00034 led5 = 0; 00035 led6 = 0; 00036 led7 = 0; 00037 led8 = 0; 00038 00039 float val1, val2, val3, val4, val5, val6, val7, val8; 00040 00041 float Volts1, Volts2, Volts3, Volts4, Volts5, Volts6, Volts7, Volts8; 00042 00043 float temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8; 00044 00045 float tempC1, tempC2, tempC3, tempC4, tempC5, tempC6, tempC7, tempC8; 00046 00047 float avg1[50], avg2[50], avg3[50], avg4[50], avg5[50], avg6[50], avg7[50], avg8[50]; 00048 00049 float totalavg1, totalavg2, totalavg3, totalavg4, totalavg5, totalavg6, totalavg7, totalavg8 = 0.0; 00050 00051 float Rx; 00052 00053 //for 3v 00054 //float C = -74.26; 00055 00056 //for 5v 00057 float C = 106.85; 00058 00059 //for 3.3v 00060 //float slope = 167.03; 00061 00062 00063 //for 5v 00064 float slope = 48.31; 00065 00066 //for sensor supply 5v adc reff 3.3v 1) 1.10 for 30 deg c 2) 0.09 fpr 30deg c 00067 //float C = 110.42; 00068 //float C = 88.9; 00069 //float slope = 14.21; 00070 //float slope = 20.73; 00071 00072 00073 00074 float calibration; 00075 00076 float R0 = 100.0; 00077 00078 float alpha = 0.00385; 00079 00080 float tempTh = 26; 00081 00082 while(true) 00083 { 00084 00085 for(int i=0; i < 50; i++) 00086 { 00087 val1 = vrefint1.read_u16(); 00088 //pc.printf("%3.2f",val1); 00089 //Volts1 = (val1/65536)*3.3; 00090 Volts1 = (val1/65536)*3.3; 00091 Rx = Volts1*slope+C; 00092 temp1= (Rx/R0-1.0)/alpha; 00093 calibration=0.3+(0.005*temp1); 00094 tempC1=temp1-calibration; 00095 avg1[i]=tempC1; 00096 00097 val2 = vrefint2.read_u16(); 00098 00099 Volts2 = (val2/65536)*3.3; 00100 Rx = Volts2*slope+C; 00101 temp2= (Rx/R0-1.0)/alpha; 00102 calibration=0.3+(0.005*temp2); 00103 tempC2=temp2-calibration; 00104 avg2[i]=tempC2; 00105 00106 val3 = vrefint3.read_u16(); 00107 00108 Volts3 = (val3/65536)*3.3; 00109 Rx = Volts3*slope+C; 00110 temp3= (Rx/R0-1.0)/alpha; 00111 calibration=0.3+(0.005*temp3); 00112 tempC3=temp3-calibration; 00113 avg3[i]=tempC3; 00114 00115 val4 = vrefint4.read_u16(); 00116 00117 Volts4 = (val4/65536)*3.3; 00118 Rx = Volts4*slope+C; 00119 temp4= (Rx/R0-1.0)/alpha; 00120 calibration=0.3+(0.005*temp4); 00121 tempC4=temp4-calibration; 00122 avg4[i]=tempC4; 00123 00124 val5 = vrefint5.read_u16(); 00125 00126 Volts5 = (val5/65536)*3.3; 00127 Rx = Volts5*slope+C; 00128 temp5= (Rx/R0-1.0)/alpha; 00129 calibration=0.3+(0.005*temp5); 00130 tempC5=temp5-calibration; 00131 avg5[i]=tempC5; 00132 00133 val6 = vrefint6.read_u16(); 00134 00135 Volts6 = (val6/65536)*3.3; 00136 Rx = Volts6*slope+C; 00137 temp6= (Rx/R0-1.0)/alpha; 00138 calibration=0.3+(0.005*temp6); 00139 tempC6=temp6-calibration; 00140 avg6[i]=tempC6; 00141 00142 val7 = vrefint7.read_u16(); 00143 00144 Volts7 = (val7/65536)*3.3; 00145 Rx = Volts7*slope+C; 00146 temp7= (Rx/R0-1.0)/alpha; 00147 calibration=0.3+(0.005*temp7); 00148 tempC7=temp7-calibration; 00149 avg7[i]=tempC7; 00150 00151 val8 = vrefint8.read_u16(); 00152 00153 Volts8 = (val8/65536)*3.3; 00154 Rx = Volts8*slope+C; 00155 temp8= (Rx/R0-1.0)/alpha; 00156 calibration=0.3+(0.005*temp8); 00157 tempC8=temp8-calibration; 00158 avg8[i]=tempC8; 00159 00160 wait(0.02); 00161 } 00162 00163 for(int j=0; j < 50; j++) 00164 { 00165 totalavg1 = totalavg1 + avg1[j]; 00166 totalavg2 = totalavg2 + avg2[j]; 00167 totalavg3 = totalavg3 + avg3[j]; 00168 totalavg4 = totalavg4 + avg4[j]; 00169 totalavg5 = totalavg5 + avg5[j]; 00170 totalavg6 = totalavg6 + avg6[j]; 00171 totalavg7 = totalavg7 + avg7[j]; 00172 totalavg8 = totalavg8 + avg8[j]; 00173 wait(0.01); 00174 } 00175 totalavg1 = (int)totalavg1/50; 00176 totalavg2 = (int)totalavg2/50; 00177 totalavg3 = (int)totalavg3/50; 00178 totalavg4 = (int)totalavg4/50; 00179 totalavg5 = (int)totalavg5/50; 00180 totalavg6 = (int)totalavg6/50; 00181 totalavg7 = (int)totalavg7/50; 00182 totalavg8 = (int)totalavg8/50; 00183 00184 totalavg1 -= 6; 00185 totalavg2 -= 2; 00186 totalavg3 -= 7; 00187 totalavg4 -= 2; 00188 totalavg5 -= 2; 00189 totalavg6 -= 2; 00190 totalavg7 -= 2; 00191 totalavg8 -= 2; 00192 00193 pc.printf("%3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f\n", totalavg1, totalavg2, totalavg3, totalavg4, totalavg5, totalavg6, totalavg7, totalavg8); 00194 00195 if((totalavg1 >= tempTh && totalavg1 < 100 ) || (totalavg2 >= tempTh && totalavg2 < 100 ) || (totalavg3 >= tempTh && totalavg3 < 100 ) || (totalavg4 >= tempTh && totalavg4 < 100) || (totalavg5 >= tempTh && totalavg5 < 100 ) || (totalavg6 >= tempTh && totalavg6 < 100) || (totalavg7 >= tempTh && totalavg7 < 100 ) || (totalavg8 >= tempTh && totalavg8 < 100 )) 00196 Buzzer = 1; 00197 00198 else 00199 Buzzer = 0; 00200 00201 00202 if((totalavg1 >= tempTh) && (totalavg1 < 100)) 00203 { 00204 led1 = 1; 00205 //pc.printf("Relay 1 is ON\n"); 00206 } 00207 else 00208 { 00209 led1 = 0; 00210 //pc.printf("Relay 1 is OFF\n"); 00211 } 00212 totalavg1 = 0; 00213 00214 if((totalavg2 >= tempTh) && (totalavg2 < 100)) 00215 led2 = 1; 00216 else 00217 led2 = 0; 00218 totalavg2 = 0; 00219 00220 if((totalavg3 >= tempTh) && (totalavg3 < 100)) 00221 led3 = 1; 00222 else 00223 led3 = 0; 00224 totalavg3 = 0; 00225 00226 if((totalavg4 >= tempTh) && (totalavg4 < 100)) 00227 led4 = 1; 00228 else 00229 led4 = 0; 00230 totalavg4 = 0; 00231 00232 if((totalavg5 >= tempTh) && (totalavg5 < 100)) 00233 led5 = 1; 00234 else 00235 led5 = 0; 00236 totalavg5 = 0; 00237 00238 if((totalavg6 >= tempTh) && (totalavg6 < 100)) 00239 led6 = 1; 00240 else 00241 led6 = 0; 00242 totalavg6 = 0; 00243 00244 if((totalavg7 >= tempTh) && (totalavg7 < 100)) 00245 led7 = 1; 00246 else 00247 led7 = 0; 00248 totalavg7 = 0; 00249 00250 if((totalavg8 >= tempTh) && (totalavg8 < 100)) 00251 led8 = 1; 00252 else 00253 led8 = 0; 00254 totalavg8 = 0; 00255 00256 00257 wait(0.5f); 00258 //totalavg1, totalavg2, totalavg3, totalavg4, totalavg5, totalavg6, totalavg7, totalavg8 = 0.0; 00259 } 00260 }
Generated on Mon Jul 25 2022 02:41:37 by
1.7.2