GreenAir - Datalogger

by ÁlvaroM13 in Workshop > Science

84 Views, 0 Favorites, 0 Comments

GreenAir - Datalogger

greenair.png

The idea for this project arose from the desire to create an integrative and engaging activity for secondary and vocational education students. From the outset, we aimed to design an experience that was both interactive and educational, enabling students to develop new skills in areas where concepts are often taught in a predominantly theoretical manner.

The main objective of this project is to provide a hands-on demonstration of an environmental phenomenon while integrating multiple fields of knowledge, such as physics, mathematics, and electronics. The choice of this project is particularly relevant in an educational context, as it allows students to visualize atmospheric gas concentrations using measurement equipment, making abstract concepts more tangible.

By implementing this system, it becomes possible to monitor air quality through an alert mechanism while also creating simulated practice scenarios. These practical experiences enhance students’ learning by making it more immersive and meaningful, bridging the gap between theory and real-world application.

Supplies

Imagem1.png
Imagem2.png
Imagem3.jpg
Imagem4.png
Imagem5.png
  1. ESP-WROMM-32 - 1 unit
  2. LCD 16x2 I2C - 1 unit
  3. Sensor SEN0465 - 1 unit
  4. Sensor SEN0159 - 1 unit
  5. Power bank - 1 unit
  6. NeoPixel - 1 unit
  7. Junction Box - 1 unit
  8. Double Side Prototype Diy Universal Printed Circuit PCB Board
  9. Screws
  10. Cables: Female-to-Female, Male-to-Female and Male-to-Male Jumper for Breadboard
  11. Female Pin Header Socket
  12. resistor 470 ohm
  13. capacitor 1000uf

Mind Map

Imagem6.jpg

A mind map is a diagram that visually represents ideas and concepts related to the development of a project. It expands through multiple branches, with each branch breaking down aspects of the main concept. These maps often use different elements and colors to create a visually intuitive structure, making information easier to understand.

The following mind map illustrates key ideas and concepts behind this project.

At the core of the project, we have the ESP-WROOM-32, a programmable board with Wi-Fi and Bluetooth capabilities, compatible with the Arduino platform. This board interacts with both sensors and actuators through programming.

Sensors:

  1. An oxygen sensor
  2. A carbon dioxide (CO₂) sensor

Actuators:

  1. An LCD screen to display information
  2. An LED strip for visual signaling

All these components are integrated into a junction box, which serves as the enclosure for the project. This setup allows for efficient organization and protection of the electronic components while ensuring smooth interaction between the different elements.

Construction

caixa.png
WhatsApp Image 2025-03-02 at 12.54.29.jpeg
WhatsApp Image 2025-03-02 at 12.55.38.jpeg
PXL_20250211_221908809.jpg
PXL_20250211_221227734.jpg
WhatsApp Image 2025-03-02 at 12.56.47.jpeg

Ok, make the holes to mount the sensors from the inside out, create the socket for the ESP32, and place it inside the box. Take a look at Thingiverse to choose a case for the display and assemble everything using screws.

Connections

Captura de ecrã 2025-03-02, às 12.11.28.png

The SEN0159 Sensor (DFRobot CO2 Sensor - MG811) operates with an analog output, and in the documentation for Arduino, it is typically connected to the A0 pin, as traditional Arduino boards (such as the Uno) have dedicated analog pins.

However, the ESP32 (ESP-WROOM-32) does not have an A0 pin like the Arduino Uno. Instead, it features multiple ADCs (Analog-to-Digital Converters), and GPIO32 is one of these analog-capable pins.

On the ESP32, the pins that support ADC (Analog-to-Digital Conversion) include:

GPIO32, GPIO33, GPIO34, GPIO35, GPIO36, GPIO39.

The SEN0465 Sensor (DFRobot Oxygen Sensor - O2) and the displays both communicate using the I2C protocol, which operates on the ESP-WROOM-32 using the following default pins:

SDA (Data): GPIO21; SCL (Clock): GPIO22

For the NeoPixel: Identify the “input” end of your NeoPixel strip, pixel(s) or other device. On some, there will be a solder pad labeled “DIN” or “DI” (data input).

To ensure stable operation of the NeoPixel LEDs, a 1000µF capacitor is placed between VCC and GND to smooth out power fluctuations. A 470Ω resistor is added to the data line (GPIO18) to reduce noise and protect signal integrity.”

Code

Explanation of the Code

This program runs on an ESP32 microcontroller and combines several functionalities:

  1. Wi-Fi Connection
  2. The ligarWiFi() function initializes the ESP32 in station mode and attempts to connect to the specified Wi-Fi network.
  3. It waits until the connection is successful (WL_CONNECTED) before continuing.
  4. CO2 Measurement
  5. The code uses an MG-811 sensor connected to an analog pin (MG_PIN) to measure CO2 concentration.
  6. Within the lerSensores() function, it calls MGRead() to average several analog readings and convert them to a voltage.
  7. It then calculates the CO2 concentration in ppm (MGGetPercentage()) using calibration constants defined in CO2Curve.
  8. O2 Measurement
  9. An SEN0465 O2 sensor communicates via I2C (address 0x74).
  10. The DFRobot_GAS_I2C library reads O2 concentration (in %vol), temperature, and can also identify the gas type.
  11. In setup(), the code checks if the sensor is available. It sets the sensor to passive mode (gas.changeAcquireMode(gas.PASSIVITY)) and disables temperature compensation.
  12. LCD Display
  13. The LiquidCrystal_I2C library controls a 16x2 LCD at address 0x27.
  14. The program displays three different types of information on the LCD in a round-robin manner:
  15. CO2 level (ppm) and its classification (Normal, Moderado, Alto, or Perigoso)
  16. O2 level (%vol) and its classification (Normal, Baixo, Muito Baixo, Perigoso)
  17. Temperature in Celsius.
  18. This rotation is managed by the lcdState variable in atualizarLCD().
  19. NeoPixel LEDs
  20. Three RGB LEDs (NeoPixel) provide a color-coded status.
  21. When displaying CO2 data, atualizarNeopixelCO2() sets the color based on the ppm level:
  22. Green for normal
  23. Yellow or orange for moderately high levels
  24. Red for dangerous levels
  25. When showing O2 data, atualizarNeopixelO2() uses a similar approach but with different threshold logic.
  26. Data Upload to Google Forms
  27. The enviarDados() function collects O2, CO2, and temperature readings and sends them using HTTPClient to a Google Forms URL.
  28. It performs a POST request with the appropriate form field names (entry.XXXXX), allowing the data to be registered in the form responses.
  29. Timing and Main Loop
  30. The main loop (loop()) checks if at least intervalo milliseconds (5,000 by default) have passed since the last sensor reading and upload (Maybe here it should be changed to a more realistic time, like 30 and 30 minutes (I don’t know)).
  31. If so, it reads sensor data, sends it to the Google Form, updates the LCD display, and then resets the timing reference (lastSendTime).

Overall, this code offers a compact method for real-time CO2 and O2 monitoring, displays the data on an LCD, provides color-coded status through NeoPixel LEDs, and periodically logs the readings to a Google Form via Wi-Fi.

DataLogger - Google Sheet

Create a Google Sheet named “greenair”

Go to ToolsCreate a new form

Possible issue – sometimes a question appears at the start of the form, asking for an email address. How to fix this?

Go to SettingsForm Defaults, and choose Collect email addresses by default – select Do not collect.


Add questions to the form

CO2 – short answer; required

O2 – short answer; required

Important

Go to the three dots (More) in the top-right corner, choose Get pre-filled link.

Copy the generated link shown in the URL bar, something like docs.xxxxxxxxx/prefill

Open a text editor; copy the link in order to make changes.


Changes…

docs.xxxxxxxxx/prefill → in the link, replace prefill with formResponse (exactly that word).

Still with the pre-filled link…

Add sample values in each field of the form.

Click Get link – a button or alert appears saying COPY LINK.

In the text editor, paste the link that was copied to the clipboard.

What do we need?

entry.140413188= – we will need all the “entry” parameters.

Don’t forget to share the Google Sheet.