Smart Line Sensor
Circuit Diagram
//include appropriate libraries
#include
#include
//Set pin #5 for LED strip
#define LED_PIN 5 //Connect D6 on Arduino nano to NeoPixel Din
//Define how many LEDs are in strip (16)
#define LED_COUNT 16
#define BRIGHTNESS 200 // NeoPixel brightness, 0 (min) to 255 (max)
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
uint32_t rgbcolor1; //variable for red
uint32_t rgbcolor2; //variable for other
long maxValue = 65536; //max value for HSV color spectrum
int FSR_pin = A0; //set A0 as FSR input
int lightPower = 2; //set pin 2 as voltage source for LED strip
int force = 0; //initialize force variable
int force2 = 0; //initialize force variable 2
int delta = 0; //initialize change in force
long hue1 = 0; //initialize color variable 1
int value = 200; //set value for HSV color
int saturation = 220; //set desired saturation (0--> 255), 150 will be pastel tones
int threshold = 25; //threshold for when LED turns on
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT); //define D6 as an output pin
pinMode(FSR_pin, INPUT); // set A0 pin to input
pinMode(lightPower, OUTPUT); //define D2 as an output pin
digitalWrite(lightPower, HIGH); //set power pin to always high
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.clear(); //clear the strip
strip.setBrightness(BRIGHTNESS); //set brightness for strip
hue1 = random(maxValue / 6, maxValue); //set strip to random color that is not red
rgbcolor1 = strip.gamma32(strip.ColorHSV(hue1, saturation, value));
//Strip.ColorHSV will utilize HSV color library
//strip.gamma32 will help crispen the HSV colors.
//without strip.gamma32 your HSV colors may be washed out
strip.fill(rgbcolor1, 0, (LED_COUNT)); //fill the strip with the rgb color
//from 0 (first pixel) to 16 (last pixel)
strip.show(); //show the color
}
void loop() { //this loop runs forever
digitalWrite(lightPower, LOW); //turn off light
force = analogRead(FSR_pin); //read FSR value
delay(25); //wait 25 milliseconds
force2 = analogRead(FSR_pin); //read FSR again
delta = abs(force2 - force); //calculate change in value
if (delta > threshold) { //if change is greater than 25
digitalWrite(lightPower, HIGH); //turn on LED strip
delay(100); //wait 100ms
hue1 = random(0, maxValue); //randomize color
rgbcolor1 = strip.gamma32(strip.ColorHSV(hue1, saturation, value));
//Strip.ColorHSV will utilize HSV color library
//strip.gamma32 will help crispen the HSV colors.
//without strip.gamma32 your HSV colors may be washed out
strip.fill(rgbcolor1, 0, (LED_COUNT)); //fill the strip with the rgb color
//from 0 (first pixel) to 16 (last pixel)
strip.show(); //show the color
delay(5000); //wait 5 seconds before turning off light
}
}