UlyssesandBloom
Published © CC BY-NC

Colour Change Outdoor Christmas Lights

Ten-year old nephews are particularly impressed when they can change the colour of the outdoor Christmas lights from a tablet.

IntermediateFull instructions provided3,601
Colour Change Outdoor Christmas Lights

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
Flora RGB Smart NeoPixel version 2
×1
Wire-Wrapping 30AWG
×1
Jumper Wires
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Capacitor 1000 µF
Capacitor 1000 µF
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1

Software apps and online services

Arduino Web Editor
Arduino Web Editor
Arduino IoT Cloud
Arduino IoT Cloud

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Ice Cream Container

An ice cream container kept the weather off the board. Leaves made good camouflage.

Schematics

Circuit

Data sent from pin 6, across a 220ohm resistor, to three strands of lights.
Power from VCC, over the 1,000uF capacitor, and to ground. Three strands connected: positive to positive, and negative to negative.
Extra wiring and buttons towards my thumb is extraneous. It was left over from experiments.

Soldering NeoPixel

Solder four NeoPixels in a strand of four lights. The light wire hangs easily on a tree branch.

Properties

Set these properties in the Arduino IoT Cloud

Code

Christmas Light Sketch

Arduino
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Christmas"
  https://create.arduino.cc/cloud/things/XXXXXX 

  Arduino IoT Cloud Properties description

  The following variables are automatically generated and updated when changes are made to the Thing properties

  bool light;
  int red;
  int blue;
  int green;

  Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <Adafruit_NeoPixel.h>
#define LED_PIN    6 //Which pin on the Arduino is connected to the NeoPixels?
#define LED_COUNT 4 // How many NeoPixels are attached to the Arduino?
int btnState;
int btnPrevState = 0;

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

void setup() {
  pinMode(LED_PIN, OUTPUT);

  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  
  strip.begin(); //call begin() to prepare the data pin for NeoPixel output:
  strip.setBrightness(64); 
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  if (light == 1) {
  strip.setPixelColor(0, red, green, blue); //strip.setPixelColor(n, red, green, blue);
  strip.setPixelColor(1, red, green, blue);
  strip.setPixelColor(2, red, green, blue);
  strip.setPixelColor(3, red, green, blue);
  strip.show();
  } else {
    uint32_t off  = strip.Color(0,0,0);
    strip.fill(off, 0, 4);
    strip.show();
  }
}

void onGreenChange() {
  // Do something
  Serial.print("Green = ");
  Serial.println(green);
}

void onRedChange() {
  // Do something
  Serial.print("Red = ");
  Serial.println(red);
}

void onBlueChange() {
  // Do something
  Serial.print("Blue = ");
  Serial.println(blue);
}

void onLightChange() {
  // Do something
  digitalWrite(LED_PIN, light);
    Serial.print("The light is ");
    if (light) {
        Serial.println("ON");
        
    } else {
        Serial.println("OFF");
    }
}

thingProperties.h

Arduino
The Arduiono IoT Cloud automatically creates these properties.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>


const char THING_ID[] = "XXXX";

const char SSID[]     = SECRET_SSID;    // Network SSID (name)
const char PASS[]     = SECRET_PASS;    // Network password (use for WPA, or use as key for WEP)

void onLightChange();
void onRedChange();
void onBlueChange();
void onGreenChange();

bool light;
int red;
int blue;
int green;

void initProperties(){

  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(light, READWRITE, ON_CHANGE, onLightChange);
  ArduinoCloud.addProperty(red, READWRITE, ON_CHANGE, onRedChange);
  ArduinoCloud.addProperty(blue, READWRITE, ON_CHANGE, onBlueChange);
  ArduinoCloud.addProperty(green, READWRITE, ON_CHANGE, onGreenChange);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Credits

UlyssesandBloom
0 projects • 1 follower

Comments