Patrick Jackson
Published © GPL3+

Home Automation Project: CPI Data

Sculpture that is intended to represent the hardship caused by inflation

IntermediateShowcase (no instructions)6 hours47
Home Automation Project: CPI Data

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×1
Photon
Particle Photon
×1
Stepper Motor
Digilent Stepper Motor
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1
Stepper Motor Controller- ULN2003A
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
U.S. Treasury API

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Custom parts and enclosures

Linear Actuator/Track

Converts rotational motion in motor to linear motion, so that the shopping cart can move back and forth.

Schematics

Perf Board

Connects Particle Photon to Stepper Motor, NeoPixels, and Power.

Perf Board(Top)

Code

Main Code

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

// 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>


const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
// for your motor

//initializing neopixel strip
#if (PLATFORM_ID == 32)
// MOSI pin MO
#define PIXEL_PIN SPI1
// MOSI pin D2
// #define PIXEL_PIN SPI1
#else // #if (PLATFORM_ID == 32)
#define PIXEL_PIN D2
#endif
#define PIXEL_COUNT 7
#define PIXEL_TYPE WS2812B

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

SerialLogHandler logHandler(LOG_LEVEL_INFO);

String startDate = "2020-01-01";
String refDate = "";

int period = 86400000;
unsigned long time_now = 0;


Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, IN1, IN3, IN2, IN4);

 long oldCPI = 0;

void setup() {
    
    
     Particle.subscribe(String(System.deviceID()) + "/hook-response/cpiData", myHandler);  // Hook response
    Serial.begin(9600);
    

      
    strip.begin();
    strip.setBrightness(50);
    for(int i = 0; i<7;i++){
        strip.setPixelColor(i,255,255,255);
    }
    strip.show();
  // set the speed at 17 rpm:
  myStepper.setSpeed(17);
  // initialize the serial port:
  Serial.begin(9600);
  
 
}

void loop() {
    
    time_now = millis();
  
  StaticJsonDocument<128> doc;  
  
  doc["start_date"] = startDate;

  
  std::string jsonPayload;
  serializeJson(doc, jsonPayload);

  
  Particle.publish("cpiData", jsonPayload.c_str(), PRIVATE);
  
  while(millis() < time_now + period){
    }


}

void myHandler(const char *event, const char *data) {
  // Handle the integration response
  String dataStr = String(data);
 
  
  String refCPI = dataStr.substring(35,38);
  refDate = dataStr.substring(61,71);
  
  //Serial.println(data);
  Serial.println(refCPI);
  Serial.println("refCPI");
  Serial.println(refDate);
  
  startDate = refDate;
  
 long currCPI = refCPI.toInt();
 
 if(currCPI>250)
 {
     if(oldCPI>300)
    {
         for(int i = 2;i<5;i++)
         {
             strip.setPixelColor(i,255,255,255);
         }
        strip.show();
        myStepper.step(stepsPerRevolution/3);
     
    }
    else
    {
        for(int i = 0; i<2;i++)
      {
         strip.setPixelColor(i,0,0,0);
      }
        strip.show();
         myStepper.step(-stepsPerRevolution/3); 
    }
    
 }
     if(currCPI>300)
 {
     if(oldCPI>350)
    {
         for(int i = 2;i<5;i++)
         {
             strip.setPixelColor(i,255,255,255);
         }
        strip.show();
        myStepper.step(stepsPerRevolution/3);
     
    }
    else{
     for(int i = 2; i<5;i++)
     {
         strip.setPixelColor(i,0,0,0);
     }
     strip.show();
    myStepper.step(-stepsPerRevolution/3); 
    
    }
 }
    oldCPI = currCPI;
   
  
}

Credits

Patrick Jackson
2 projects • 0 followers
Thanks to Mr. Law and Vivian.

Comments