Matthew Solc
Published

Chicago UV Tracker

Physical representation of Chicago's UV using a diorama of a Chicago beach

BeginnerShowcase (no instructions)2 hours3
Chicago UV Tracker

Things used in this project

Hardware components

SparkFun Snappable Protoboard
SparkFun Snappable Protoboard
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Stepper Motor
Digilent Stepper Motor
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
×1
Photon 2
Particle Photon 2
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Code

Code for project

C/C++
The bulk of the commented lines are just different variations for the umbrella. One of the chunks makes it spin every time data is pulled, the other is constant spinning but at different speeds proportional to the UV
// 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>

// Include Particle Device OS APIs
#include "Particle.h"


const int stepsPerRevolution = 2048;
int stepperSpeed = 15;
//See if you can make a float
int brightness = 0;

#define IN1 3
#define IN2 4
#define IN3 5
#define IN4 6
Stepper myStepper(stepsPerRevolution, IN1, IN3 , IN2, IN4);


JsonDocument doc;

#if (PLATFORM_ID == 32)
    #define PIXEL_PIN SPI1
    #else // 
    #define PIXEL_PIN D2
    #endif
    #define PIXEL_COUNT 20
    #define PIXEL_TYPE WS2812B
    
    Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
    



void setup() {
    Serial.begin(9600);
    
    while(Particle.disconnected()) ;
    
    Particle.subscribe("hook-response/UVPULL/0", extractInfo);
    delay(1000);
    
    Serial.println("Particle connected to cloud!");
    
    
    Particle.publish("UVPULL");
    Serial.println("PULLED");
    
    myStepper.setSpeed(stepperSpeed);
    
    strip.begin();
    strip.show();

    
}





int lastPublish = 0;

void loop() {
  
   
    strip.setBrightness(brightness);
    myStepper.setSpeed(stepperSpeed);
  
     for (int i = 0; i < 20; i++)
        {
            strip.setPixelColor(i, 255, 180, 0);
            strip.show();
        }
  
    myStepper.step(stepsPerRevolution);

    // myStepper.step(stepsPerRevolution);


    // if (millis() - lastPublish >= 60000)
    // {
    //     Particle.publish("UVPULL");
    //     Serial.println("print");
    //     lastPublish = millis();
    // }
    if (millis() - lastPublish >= 1800000)
        {
            Particle.publish("UVPULL");
            // Particle.subscribe("hook-response/UVPULL/0", extractInfo);
            Serial.println("print");
            lastPublish = millis();
            
            // for (int i = 0; i < 5; i++)
            // {
            //     myStepper.step(stepsPerRevolution);
            // }
            
        }
    

    
    
}

void extractInfo(const char *event, const char *data)
{
    Serial.println("Handler is starting...");
    
    deserializeJson(doc, data);
    
    //JsonObject root_0 = doc[0];
    float uvIndex = doc["now"]["uvi"];
    
    Serial.print("uv");
    Serial.println(uvIndex);
    
    // for (int i = 0; i < 5; i++)
    // {
    //     myStepper.step(stepsPerRevolution);
    // }
    // Constant Movement Motor relating to speed
    // Another option is just a few spins at top speed every 10 minutes or something or *** every time the light updates ***
    // if (uvIndex == 0)
    // {
    //     stepperSpeed = 0;
    // }
    // else if (uvIndex <= 1)
    // {
    //     stepperSpeed = 10 + (0.5 - (0.5 * (10 - uvIndex)));
    // }
    // else if (uvIndex <= 2)
    // {
    //     stepperSpeed = 10.5 + (0.5 - (0.5 * (10 - uvIndex)));
    // }else if (uvIndex <= 3)
    // {
    //     stepperSpeed = 11 + (0.5 - (0.5 * (10 - uvIndex)));
    // }else if (uvIndex <= 4)
    // {
    //     stepperSpeed = 11.5 + (0.5 - (0.5 * (10 - uvIndex)));
    // }else if (uvIndex <= 5)
    // {
    //     stepperSpeed = 12 + (0.5 - (0.5 * (10 - uvIndex)));
    // }else if (uvIndex <= 6)
    // {
    //     stepperSpeed = 12.5 + (0.5 - (0.5 * (10 - uvIndex)));
    // }else if (uvIndex <= 7)
    // {
    //     stepperSpeed = 13 + (0.5 - (0.5 * (10 - uvIndex)));
    // }else if (uvIndex <= 8)
    // {
    //     stepperSpeed = 13.5 + (0.5 - (0.5 * (10 - uvIndex)));
    // }else if (uvIndex <= 9)
    // {
    //     stepperSpeed = 14 + (0.5 - (0.5 * (10 - uvIndex)));
    // }else if (uvIndex <= 10)
    // {
    //     stepperSpeed = 14.5 + (0.5 - (0.5 * (10 - uvIndex)));
    // }
    
    
    
    
    
    
    
    brightness = uvIndex * 10;
    Serial.print("Brightness");
    Serial.println(brightness);
    Serial.print("Speed");
    Serial.println(stepperSpeed);
    
    // for (int i = 0; i < 8; i++)
    //     {
    //         strip.setPixelColor(i, 150, 80, 20);
    //         strip.setBrightness(uvIndex * 10);
    //         strip.show();
    //     }
    
    
    
}

Credits

Matthew Solc
2 projects • 1 follower

Comments