Arduino_Genuino
Published

NeoPixel LEDs: Cloud controlled RGB lamp

Light up your world with these programmable fountains of photons, and control them from the Arduino IoT Cloud!

IntermediateFull instructions provided1 hour2,101
NeoPixel LEDs: Cloud controlled RGB lamp

Things used in this project

Hardware components

Arduino Nano 33 IoT
Arduino Nano 33 IoT
Or another cloud compatible board
×1
LED Stick, NeoPixel Stick
LED Stick, NeoPixel Stick
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Story

Read more

Code

IoTNeopixel

Arduino
Upload this sketch from the IoT Cloud
/*
Sketch generated by the Arduino IoT Cloud Thing "Neopixel"
https://create.arduino.cc/cloud/things/eca61fa1-affd-46b5-b9ff-e41cacea1d0a
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudColoredLight neopixel;
Variables 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>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN            5
#define NUMPIXELS      8
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// 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);
pixels.begin(); // This initializes the NeoPixel library.
// 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();
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since Neopixel is READ_WRITE variable, onNeopixelChange() is
executed every time a new value is received from IoT Cloud.
*/
void onNeopixelChange()  {
// Add your code here to act upon Neopixel change
uint8_t r, g, b;
neopixel.getValue().getRGB(r, g, b);
if (neopixel.getSwitch()) {
Serial.println("R:" + String(r) + " G:" + String(g) + " B:" + String(b)); //prints the current R, G, B values
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(r, g, b));
pixels.show(); // This sends the updated pixel color to the hardware.
}
}
else {
Serial.println("Lamp Off");
//the following code simply turns everything off
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show(); // This sends the updated pixel color to the hardware.
}
}
}

Credits

Arduino_Genuino

Arduino_Genuino

91 projects • 11339 followers

Comments