Alexis Santiago Allende
Published © GPL3+

ESP-light System

A prototype that seeks to give intelligence and magic to the lights of cities of the future using Cayenne and Sparkfun ESP8266 dev.

IntermediateFull instructions provided10 hours1,726
ESP-light System

Things used in this project

Hardware components

SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
Adafruit INA219 Current sensor
×1
Adafruit Neopixel Ring 12
×2
Adafruit Capacitor 1000u 16v
×1
SparkFun Resistor 330
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Cayenne
myDevices Cayenne

Story

Read more

Schematics

final_s_bb_pplgu9ghs6.png

Code

My code

Arduino
Code of my project!
// Alexis Santiago Allende 10/7/2017
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <Adafruit_INA219.h>

#define PIN1            15
#define NUMPIXELS       24

// WiFi network info.
char ssid[] = "INFINITUMl9mc";
char wifiPassword[] = "MoMoCo01";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "f86bdf80-e5d6-11e6-bac1-91ed518c84d3";
char password[] = "ea8532f6aab491e4cf27c10e4cc83e1b60bb4cc7";
char clientID[] = "513c7450-9a7f-11e7-8802-49bbc5641530";

unsigned long lastMillis = 0;
int r1=0,g1=0,b1=0,r2=0,g2=0,b2=0,i=0,j=0,valor1,boton1;
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power = 0;

Adafruit_INA219 ina219;
Adafruit_NeoPixel pixels1 = Adafruit_NeoPixel(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(9600);
  pinMode(5,OUTPUT);
  pinMode(12,INPUT);
  pixels1.begin(); 
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  uint32_t currentFrequency;
  ina219.begin();
}

void loop() {
  Cayenne.loop();
  valor1=digitalRead(12);
  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  loadvoltage = busvoltage + (shuntvoltage / 1000);
  power=loadvoltage*current_mA;
  
  if(i==1 && boton1==0)
  {
    for(int m=0;m<NUMPIXELS/2;m++){
    pixels1.setPixelColor(m, pixels1.Color(r1,g1,b1)); // Moderately bright green color.
    pixels1.show(); // This sends the updated pixel color to the hardware.

  }
  }
  else if(i==0 && boton1==0)
  {
    for(int m=0;m<NUMPIXELS/2;m++){
    pixels1.setPixelColor(m, pixels1.Color(0,0,0)); // Moderately bright green color.
    pixels1.show(); // This sends the updated pixel color to the hardware.

  }
  }
  if(j==1 && boton1==0)
  {
    for(int n=12;n<NUMPIXELS;n++){
    pixels1.setPixelColor(n, pixels1.Color(r2,g2,b2)); // Moderately bright green color.
    pixels1.show(); // This sends the updated pixel color to the hardware.

  }
  }
  else if(j==0 && boton1==0)
  {
    for(int n=12;n<NUMPIXELS;n++){
    pixels1.setPixelColor(n, pixels1.Color(0,0,0)); // Moderately bright green color.
    pixels1.show(); // This sends the updated pixel color to the hardware.

  }
  }
  //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 1000) {
    lastMillis = millis();
    //Write data to Cayenne here. This example just sends the current uptime in milliseconds.
    Cayenne.virtualWrite(0,current_mA);
    Cayenne.virtualWrite(12,loadvoltage);
    Cayenne.virtualWrite(13,power);
  }
  if(boton1==1)
  {
  if(valor1==1)
  {
    for(int o=0;o<NUMPIXELS;o++){
    pixels1.setPixelColor(o, pixels1.Color(r1,g1,b1)); // Moderately bright green color.
    pixels1.show(); // This sends the updated pixel color to the hardware.

  }
  }
  else if(valor1==0)
  {
    for(int o=0;o<NUMPIXELS;o++){
    pixels1.setPixelColor(o, pixels1.Color(0,0,0)); // Moderately bright green color.
    pixels1.show(); // This sends the updated pixel color to the hardware.

  }
  }
  }
}

//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN(1)
{
  i = getValue.asInt();
}

CAYENNE_IN(2)
{
  r1 = getValue.asInt();
}

CAYENNE_IN(3)
{
  g1 = getValue.asInt();
}

CAYENNE_IN(4)
{
  b1 = getValue.asInt();
}

CAYENNE_IN(5)
{
  j = getValue.asInt();
}

CAYENNE_IN(6)
{
  r2 = getValue.asInt();
}

CAYENNE_IN(7)
{
  g2 = getValue.asInt();
}

CAYENNE_IN(8)
{
  b2 = getValue.asInt();
}

CAYENNE_IN(9)
{
  boton1 = getValue.asInt();
}

Credits

Alexis Santiago Allende

Alexis Santiago Allende

0 projects • 75 followers
Im a person who since young feel a passion for electronics, I also like to cook pizza and travel. Now Im working on the internet of things

Comments