Data Driven Air Pollution Sculpture Diorama

by AndrewRMidkiff in Circuits > Microcontrollers

91 Views, 0 Favorites, 0 Comments

Data Driven Air Pollution Sculpture Diorama

20240417_123636 (2).jpg

With some craft skills and electricial engineering skills, you too can make a cool diorama that changes color and mood based on how much air pollution is currently in the air near you. When the air is clean the diorama is cheery and bright, and when the air is polluted the diorama becomes dark and spooky.

I created this project for the Computational Sculpture Project in my Physical Computing Laboratory class in my junior year at Albert G. Lane Technicial High School. I partnered with Jannet Morales from the Sculpture class, where she did the art components. The Computational Sculpture project required students to create a diorama in a cardboard box that used LED lights and motors to change based on changes in real-time data related to pollution. We decided to make our project a room of a house that would change based on the levels of air pollution to depict a happy and clean environment and then change to a dark and scary environment, because that mirrors what happens with pollution in real life. The main subject of the project is the Flower Guy, and his head can rotate from kind and happy to scary and unnerving, and there are overhead LED lights that will change from green to purple.

This guide will serve as a general-purpose guide to illustrate how I put together the computer science side (not the art side) of the project. This includes the motor for the Flower Guy's head and the LEDs, and drawing the air pollution data from the API to trigger the changes.

Supplies

  • Particle Argon
  • Breadbord
  • Red solid core wire, 0.64 mm gauge (3ft)
  • Yellow solid core wire, 0.64 mm gauge (3ft)
  • Black solid core wire, 0.64 mm gauge (3ft)
  • Male/male jumper wires, 0.64 mm gauge (2x)
  • Rohs 28BYJ-48 5V DC stepper motor
  • Cable that can plug into the wall and has two power wires, giving you external power
  • Adafruit Neopixel Strips, close together, (3 strips of 7, totalling 24 LEDs)
  • Solder (the metal)
  • Hot glue

Tools:

  • Wire stripper small enough for 0.64mm gauge
  • Wire cutter
  • Soldering Iron
  • Needle nose pliers
  • Hot glue gun

Soldering/Wiring

All of the physical components for this project will be mounted on a breadboard. Preferably a brand new one, so the connections are sturdy. The final board will have a total of 11 wires plugged into it: six wires (2 power and 4 data) for the stepper motor, three wires for the LED strips, and the two jumper wires for enabling the power and ground rails.

Stepper Motor

This motor will be mounted on the Flower Guy's neck, so the wires can be relatively short, only having to reach from the suspended-in-air motor controller board to the breadboard.

  1. You will probably need the wires reaching from the motor controller to the breadboard to be 2.5 times as long as the provided jumper wires.
  2. Cut two red wire segments, two black wire segments, and two yellow wire segments, all of equal length (about 8 inches)
  3. Strip each jumper wire from the motor controller to expose the inside. Be careful to cut off the male end and not the female, as you still need to plug the female into the pins on the motor controller
  4. Solder each wire segment onto each jumper wire.
  5. Now you should have a stepper motor with wires from its motor controller board that are long enough to reach your breadboard. Plug the power wires into the rails, and then in descending order plug the data wire for INI 1 to D8, and so on until INI 4 into D5.

LED Strips

These LED strips will be mounted on the top of the cardboard box, so the wires going to the breadboard need to be much longer than the wires for the stepper motor. Each seven-LED strip will not be connected individually, but instead soldered together sequentially, this is to reduce complexity.

  1. Cut six wire segments of equal length, around 10 inches each, make sure you get three of each color. Strip them at their ends.
  2. Cut your LED strips into three equal length strips of seven each.
  3. Making sure that the arrows are aligned in the correct direction, solder three wires, each a different color, onto the end of one of your LED strips (the arrows pointing away from the end where you are soldering, we are working backwards)
  4. Take those wires and solder them to the same side of another LED strip. Now you should have two LED strips connected with the arrows pointing the same direction.
  5. Take three more wires and solder them to the end of the second LED strip, where the arrows are pointing towards the first LED strip.
  6. Take a third LED strip and repeat step 4, except this time you have three LED strips with the arrows all pointing in the same direction, going away from the end of the third strip.
  7. Cut three new wire segments that are around three feet long each.
  8. Solder these to the end of the third strip so that these new wires are pointing in the same direction as the arrows.
  9. Now you should be finished with soldering the LED strips. Plug the data wire into D4 and the power wires into the rails.

Now you are done with the physical component. Onto the digital part.

Coding

In this section, I will show how to set up the API to pull data from it, and also how to code the rest of the components so they work correctly.

Setting up the API

For this project, I used the OpenMeteo air quality API to measure Nitrogen Dioxide levels in Chicago near my school.

I specifically wanted to poll the API every hour, which is how frequently the sensor used measures the data. Figuring out how to do this was slightly difficult, but I eventually got the parameters that I needed to use.

  1. Set up a webhook in the integrations tab of the particle console. This is fairly self explanatory, and the only special thing you need to do is copy "{{{current.nitrogen_dioxide}}}" into the response template field.
  2. Setup a particle program file, and subscribe to the webhook, and then setup a handler that can take the NO2 levels and assign them to a double variable. Once you have this working, the webhook setup is now complete, but now we need to actually do something with it.
  3. Use the millis() function to set up logic that runs statements every ten seconds. Inside the conditional, publish the webhook.
  4. Inside the handler, create logic that will run statements if the NO2 quality is higher than an somewhat high threshold, but one that is hit somewhat often; it will be different for your area, so just exercise your own judgement about what numbers to use, and another conditional that will run if the air quality is average or below average. These are the bad and good states of the project, respectively.

Setting up the NeoPixels

You need to have bought NeoPixels that can work with the NeoPixel library by AdaFruit or this will not work. All the information I will give is also available in their own Uber guide.

  1. Import the library, setup the number of lights (24), the serial number of your neopixels, and the variable name. Also Make sure to also set up a variable for brightness. Put in some test values and initialize the strip to make sure its working.
  2. Next step is to integrate it into the previously existing logic.
  3. On the good side, write code that turns all the lights green. You can also adjust the brightness so that the lower the air pollution is, the brighter the green lights will be. I did this by mapping the range of "good" values to the NO2 values (I.e 0-17, if 17 is your cutoff point for the good side) to 255,0, that way the lower it is, the brighter it is.
  4. On the bad side, write code that turns all the lights purple. You can also adjust the brightness so that the higher the air pollution is, the brighter the purple lights will be. I did this by mapping the range of "bad" values to the NO2 values (I.e 18-52, if 17 is your cutoff point for the good side) to 0, 255, that way the higher it is, the brighter it is.
  5. Make sure to write strip.begin() after every time you change something about the LEDs.

Setting up the Stepper Motor

You will have to use the stepper motor library to do this, and it may be complicated so you might need to look up an online guide.

  1. Setup the stepper motor.
  2. Everytime you go into good mode, turn the stepper motor half way to turn the head to the good side, if its not already on the good side (indicated by a boolean variable). If its on the bad side and you go to the good side, put the variable (IsItGood) to true, and then when you go to the bad side from the good side do the same thing but make the variable false. This logic will prevent you from turning the motor every 10 seconds.

If you followed the instructions correctly, your project should now be working. Check out my video below for an example.

Video of Working Project

Due to Instructables file size limit, I will attach the link as a Google Drive file. It is open to anyone with a Google account. This video shows my project shifting between each state.

https://drive.google.com/file/d/1dtl_JOf_emIDJnDrm1jVdlaCPCbizopL/view?usp=sharing