This project engages students to understand how drones can be an important key for data collection. In this specific case, a DJI Mini 4 Pro drone was used to capture data with a goal to investigate and compare urban air quality in different city locations.
Air quality affects the environment and human health in many ways. Air pollutants can spread over large areas and reduce the quality of the air. Measuring air quality using ground sensors often requires many site visits and long periods of work. These methods can take a lot of time and may only cover small areas. Remote sensing tools offer another way to study air quality, reducing the need to be on site while giving a wider view of pollution across an area.
Students set up an air quality logger with gps, attach it to the drone, plan a simple flight path and operate a drone. They document the process with pictures and short videos that later will become learning materials. Safety considerations should be frequently mentioned. This project will allow students to question themselves about how the world will be in 10/15 years and concerns about current environmental care of the world in general.
Documentation
Code
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <DHT.h>
// ** Definitions for MQ sensor
#define MQ_PIN A0 // Analog pin for MQ sensor
// GPS uses SoftwareSerial. On ESP8266, avoid using GPIO0 and GPIO2 in some cases depending on boot.
// Here it’s set as RX = GPIO0 and TX = GPIO2.
SoftwareSerial SerialGPS(0, 2); // RX = D3 (GPIO0), TX = D4 (GPIO2)
TinyGPSPlus gps;
// DHT sensor setup
#define DHTPIN 5 // D1 (GPIO5)
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// SD card setup
#define SD_CS_PIN 15 // D8 (GPIO15)
// EEPROM addresses
#define EEPROM_ADDR 0
// Timer variables
unsigned long lastLogTime = 0;
const unsigned long logInterval = 5000; // 5 seconds
void setup() {
Serial.begin(115200);
SerialGPS.begin(9600);
dht.begin();
// Initialize SD card
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD card initialization failed!");
} else {
Serial.println("SD card initialized.");
}
Serial.println("System initialized.");
}
void loop() {
// Read GPS data
while (SerialGPS.available() > 0) {
gps.encode(SerialGPS.read());
}
// Read MQ sensor
int mqValue = analogRead(MQ_PIN);
// Read DHT sensor
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Log data every interval
if (millis() - lastLogTime >= logInterval) {
lastLogTime = millis();
// Prepare log string
String logData = "";
if (gps.location.isValid()) {
logData += "Lat: " + String(gps.location.lat(), 6);
logData += ", Lng: " + String(gps.location.lng(), 6);
} else {
logData += "Lat: INVALID, Lng: INVALID";
}
logData += ", MQ: " + String(mqValue);
logData += ", Temp: " + String(temperature);
logData += ", Hum: " + String(humidity);
Serial.println(logData);
// Write to SD card
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(logData);
dataFile.close();
Serial.println("Data written to SD.");
} else {
Serial.println("Error opening datalog.txt");
}
// Store last MQ value in EEPROM (example)
EEPROM.put(EEPROM_ADDR, mqValue);
EEPROM.commit();
}
}












