Skip to main content

Air Quality Kit - Mobile Air Conditioner: Part 1

heat map of UK and Europe

In the past month, the UK has declared a national emergency for the red extreme heat warning, which is the first time that issues a national emergency for hot weather. At the same time, hundreds die during the heatwave in Europe. Also, Hong Kong is facing hot weather affecting, the Hong Kong Observatory also announced a special weather tip about a “prolonged heat alert”, which is the first time the Observatory issued a special reminder for the prolonged heat alert.

One of the main reasons for this extreme weather is caused by global warming. Burning fossil fuels and deforestation are the causes of global warming. Therefore, understanding the air quality around us can help us improve global warming. Here, I won't say we don't use electricity as the most effective way to solve the global warming issue. Because I think it is impossible, especially under this extreme weather. As we have seen in the bad news about European heatwaves. Therefore, I believe using electricity correctly is a more effective way to solve global warming. In this project, I will make a mobile air conditioner with the air quality kit, through the temperature measured by the air quality kit (ESDK) to determine if we need to turn on the mobile air conditioner.

In this chapter, I will share how I received data from Air Quality Kit in Arduino Nano 33 IoT.

As we know there is a temperature sensor to check the environment temperature. Also, we can check all the measured values on the dashboard easily. However, in this project, I will send data to MCU (Arduino Nano 33 IoT) via MQTT for air conditioning.


The Air quality kit is already installed in the MQTT. Before we start, we can test the MQTT function well first.

We can check the MQTT by connecting via SSH and entering “ mosquitto_sub -h localhost -t '#' ”.

After we check it is functional, we can start the MCU part.

In this project, I will through the localhost communicate will the Air Quality Kit (Publish) and the Arduino Nano 33 IoT (Subscribe). Hence, we need to check the IP address of the Air Quality Kit and create the name of the topic we subscribed to first.

const char broker[] = "";   //IP address of the Air Quality Kit 
int        port     = 1883;
const char topic[] = "airquality/#";


Then, we can through “mqttClient.onMessage()” to receive the MQTT message.

void onMqttMessage(int messageSize) {
  char input[384] = {0};
  // we received a message, print out the topic and contents
  Serial.println("Received a message with topic '");
  Serial.print("', length ");
  Serial.println(" bytes:");

After receiving the data, we can deserialize the received data through JSON. Through JSON, we can allocate the received data on the JsonDocument, and fetch the values.

StaticJsonDocument<384> doc;
DeserializationError error = deserializeJson(doc, input);

if (error) {
  Serial.print(F("deserializeJson() failed: "));

  const char* hardwareId = doc["hardwareId"]; // "RPI0000000008abc681"
  JsonObject thv = doc["thv"];
  thv_vocIndex = thv["vocIndex"]; 
  thv_temperature = thv["temperature"]; 
  thv_humidity = thv["humidity"]; 
  const char* thv_sensor = thv["sensor"]; 
  JsonObject pm = doc["pm"];
  const char* pm_sensor = pm["sensor"]; 
  pm_pm1_0 = pm["pm1.0"]; 
  pm_pm2_5 = pm["pm2.5"]; 
  pm_pm4_0 = pm["pm4.0"]; 
  pm_pm10 = pm["pm10"]; 
  const char* geohash = doc["geohash"]; 
  const char* co2_sensor = doc["co2"]["sensor"]; 
  co2_co2 = doc["co2"]["co2"];
  Serial.print("VocIndex: ");     Serial.println(thv_vocIndex);
  Serial.print("Temperature: ");  Serial.println(thv_temperature);
  Serial.print("Humidity: ");     Serial.println(thv_humidity);
  Serial.print("co2: ");          Serial.println(co2_co2);
  Serial.print("pm_pm1_0: ");     Serial.println(pm_pm1_0);
  Serial.print("pm_pm2_5: ");     Serial.println(pm_pm2_5);
  Serial.print("pm_pm4_0: ");     Serial.println(pm_pm4_0);
  Serial.print("pm_pm10: ");      Serial.println(pm_pm10);

Finally, we can receive the data in the MCU, with this data we can do any project we want on the MCU.

In the next chapter, I'll go into the central part of the project - the air conditioner, please look forward, and I hope you are interested in this project.

JulianWong has not written a bio yet…
DesignSpark Electrical Logolinkedin