Here’s a rather lengthy introduction to Arduino, FastLED, and debugging with the Arduino IDE’s serial plotting tool. Parts and basic electrical engineering are outside the scope of this video. While the voltage in this project isn’t enough to harm you, a short could damage the USB port on your computer. Take proper ESD and isolation precautions.
Softwares:
https://www.arduino.cc/en/Main/Software
http://fastled.io/
Documentation:
https://www.arduino.cc/reference/en/
http://fastled.io/docs/3.1/
Time Stamps:
00:00 – Introduction
00:23 – Downloading and Installing Arduino IDE
01:20 – Installing the FastLED Library
02:11 – Breadboard Overview
03:14 – Arduino I/O Overview
03:50 – Code Setup
06:00 – Compile and Upload
06:49 – Reading and Writing the Photo-resistor
08:00 – Prepping for Serial Plotting
09:08 – Using the Serial Plotter
10:10 – Prepping for map() and constrain()
12:02 – Implementing map()
13:07 – Debugging map() with the Serial Plotter
14:27 – Implementing constrain()
16:50 – Outro
Electronics used in video:
Arduino Uno R3
Photoresistors
Pixel Strip
Breadboard
Jumper Wires
Code used in video:
#include <fastLED.H>
#define NUM_LEDS 8 //number of leds in the strand
#define DATA_PIN 10 //A digital I/O pin on the Arduino, will be used to write data to the LEDs
#define sensPin A0 //An Analog pin on the Arduino, will be used to read a photoresistorCRGB ledArray[NUM_LEDS]; //a FastLED array
int sensorValue; //the variable to store photoresistor data
int roomDark = 400; //Calibration Variable. After reading the serialPlotter, change this value to 100 above the max value observed
int roomLit = 750; //Calibration Variable. After reading the serialPlotter, change this value to 100 over the max value observed
int brightMin = 0; //Calibration Variable. Between 0-255 (0% – 100%), set the minimum brightness.
int brightMax = 255; //Calibration Variable. Between 0-255 (0% – 100%), set the maximum brightness.
void setup() {
delay(2000); //safety-delay
Serial.begin(9600); //COMPORT for calibration
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(ledArray, NUM_LEDS);
}void loop() {
sensorValue = analogRead(sensPin); //analog values from photoresistor are read from sensPin and assigned to sensorValue)
// Serial.println(sensorValue); //raw sensor value
sensorValue = constrain(sensorValue, roomDark, roomLit); //constrains value of sensorValue.
//If sensorValue is below roomDark, sensorValue is given a value floor of roomDark
//If sensorValue is above 1023(the sensors maximum value), sensorValue is given a value ceiling of 1023
//If sensorValue is between roomDark and 1023, sensorValue is unchangedFastLED.setBrightness(map(sensorValue, roomDark, roomLit, brightMin, brightMax)); //Map finds sensorValue’s value between roomDark and roomLit, and remaps between brightMin and brightMax
Serial.println(map(sensorValue, roomDark, roomLit, brightMin, brightMax));
ledArray[0] = CRGB(255,0,0); //red
ledArray[1] = CRGB(255,125,0); //yellow
ledArray[2] = CRGB(125,255,0); //lime
ledArray[3] = CRGB(0,255,0); //green
ledArray[4] = CRGB(0,255,125); //teal
ledArray[5] = CRGB(0,125,255); //cyan
ledArray[6] = CRGB(0,0,255); //blue
ledArray[7] = CRGB(255,255,255); //white
FastLED.show();
//delay(100);
}