Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int measurePin = 0;
- int ledPower = 7;
- int samplingTime = 280; // parametry pomiarowe
- int deltaTime = 40;
- int sleepTime = 9680;
- float voMeasured = 0;
- float calcVoltage = 0;
- float dustDensity = 0;
- float dust; // zmienna pojedyńczego pomiaru
- float MIN_VOLTAGE = 600.0;
- int MAX_ITERS = 10;
- float avgDust = 0; // uśredniony wynik z 10 pomiarów
- int iter = 0;
- //arduino
- void setup(){
- Serial.begin(9600);
- pinMode(ledPower,OUTPUT);
- }
- float measureDust() {
- digitalWrite(ledPower,LOW); // włączenie LED
- delayMicroseconds(samplingTime);
- voMeasured = analogRead(measurePin); // odczytanie wartości zmierzonej
- delayMicroseconds(deltaTime);
- digitalWrite(ledPower,HIGH); // wyłączenie LED
- delayMicroseconds(sleepTime);
- calcVoltage = (5000.0 / 1024.0) * voMeasured;
- //dustDensity = 0.17 * calcVoltage - 0.1;
- if (calcVoltage > MIN_VOLTAGE)
- {
- return (calcVoltage - MIN_VOLTAGE) * 0.2;
- //return (0.17 * calcVoltage) - 0.1; różne opcje zamiany tego na wartość
- }
- return 0;
- }
- //arduino
- void loop(){
- avgDust = 0;
- iter = 0;
- while (iter < MAX_ITERS)
- {
- dust = measureDust(); //funkcja zwracająca pojedyńczy pomiar pyłu
- if (dust > 0)
- {
- avgDust += dust;
- iter++;
- delay(10);
- }
- }
- avgDust /= MAX_ITERS;
- //avgDust = measureDust();
- Serial.print("D = ");
- Serial.print(avgDust);
- Serial.println("ug/m3");
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement