Jameson Gronowski
Published

PCL + Sculpture Project

Light Garden that responds to Air Quality Index. Color, brightness, and spinning wheel speed change based on AQI level.

IntermediateFull instructions provided8 hours10
PCL + Sculpture Project

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
28BYJ-48 Stepper Motor
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
×1

Story

Read more

Schematics

Circuit Diagram

Code

Cultivating Light Project

C/C++
This code is used to pull data from my webhook and make the lights and stepper motor respond to the data. There are 5 if statements which all have different actions based on the air quality.
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// This #include statement was automatically added by the Particle IDE.
#include <Stepper.h>

// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>

JsonDocument doc;

/*--- Particle setup ---*/
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);


/* --- Stepper Motor --- */
const int stepsPerRevolution = 2048;

#define IN1 3
#define IN2 4
#define IN3 5
#define IN4 6

Stepper myStepper(stepsPerRevolution, IN1, IN3 , IN2, IN4);


/* --- LED Strips --- */
#define PIXEL_COUNT 14
#define PIXEL_PIN SPI1
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);


/* --- Air Quality value --- */
int aqi = 0;


void setup()
{
    Serial.begin(9600);

    pinMode(7, OUTPUT);
    digitalWrite(7, LOW);

    while(Particle.disconnected()) ;

    Serial.println("Particle connected to cloud!");

    Particle.subscribe("hook-response/airquality", extractInfo);

    myStepper.setSpeed(10);

    strip.begin();
    strip.show();
}


void loop()
{
    if (aqi <= 50)
    {
        myStepper.setSpeed(15);

        for (int i = 0; i < PIXEL_COUNT; i++)
        {
            strip.setPixelColor(i, 0, 128, 0);
        }

        strip.setBrightness(255);
        strip.show();
        
    }
    
    else if (aqi <= 100)
    {
        myStepper.setSpeed(12);

        for (int i = 0; i < PIXEL_COUNT; i++)
        {
            strip.setPixelColor(i, 255, 255, 0);
        }

        strip.setBrightness(200);
        strip.show();
    }
    else if (aqi <= 150)
    {
        myStepper.setSpeed(9);

        for (int i = 0; i < PIXEL_COUNT; i++)
        {
            strip.setPixelColor(i, 255, 120, 0);
        }

        strip.setBrightness(150);
        strip.show();
    }
    else if (aqi <= 200)
    {
        myStepper.setSpeed(6);

        for (int i = 0; i < PIXEL_COUNT; i++)
        {
            strip.setPixelColor(i, 255, 0, 0);
        }

        strip.setBrightness(100);
        strip.show();
    }
    else
    {
        myStepper.setSpeed(3);

        for (int i = 0; i < PIXEL_COUNT; i++)
        {
            strip.setPixelColor(i, 150, 0, 255);
        }

        strip.setBrightness(60);
        strip.show();
    }

    myStepper.step(16);
}
    

void extractInfo(const char *event, const char *data)
{
    Serial.println("Handler is starting...");

    aqi = atoi(data);

    Serial.print("AQI: ");
    Serial.println(aqi);
}

Credits

Jameson Gronowski
1 project • 0 followers
Thanks to Yaretzy Crespo.

Comments