Temperature Controlled Pulsing Neopixels Question

Hi all,

I am very much a beginner at this and have attempted to do research before hand to fix the issue but keep hitting walls. Thanks in advance for input or assistance.

I am working with an contactless temperature sensor (MLX90614) and a 12 LED Neopixel Ring on a mini metro and am attempting to have different temperature thresholds trigger the LED’s up to a certain temperature. I’ve got the basic structure of it working in my code and can have LED’s triggered by temp ranges, however, I would like to have a setting where I can set up another rule and have a LED pulsing in brightness.

For example: If temperature is above between 50-70F then LED 0 is on solid and LED 1 is pulsing in brightness. Then once it hits 70F LED’s 0/1 are on solid and LED 2 is pulsing in brightness between 70-90. etc.

Thank you all.

#include <Wire.h>
#include <SparkFunMLX90614.h>

IRTherm temp; 

#include <Adafruit_NeoPixel.h>  
#define PIN 5 // the pin your strip is connected to 
#define COUNT 12 // how many led's are on that strip  

Adafruit_NeoPixel pixels(COUNT, PIN, NEO_GRB + NEO_KHZ800);


void setup() {
  Serial.begin(115200);
  Serial.println("Water Temperature Test");
Wire.begin();
temp.begin();
temp.setUnit(TEMP_F);


pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
for (int pinNumber = 2; pinNumber <5; pinNumber++) {
  pinMode(pinNumber, OUTPUT);

  }
}


void loop() {
pixels.clear(); // Set all pixel colors to 'off'

if (temp.read()) // Read from the sensor
{ // If the read is successful:
  float objectT = temp.object(); // Get updated object temperature
  Serial.println("Object: " + String(objectT));

if (temp.object() <=40){
    Serial.println("LED 0 - Temp Setting 0");
    for(int i=0;i<1;i++){
       pixels.setPixelColor(i, pixels.Color(0,15,0));
       pixels.show();
    }
    }

if (temp.object() <=50 & temp.object() >40){
    Serial.println("LED 0/1 - Temp Setting 1");
    for(int i=0;i<1;i++){
       pixels.setPixelColor(i, pixels.Color(0,15,0));
       pixels.show();

    }
    }

if (temp.object() <=80 & temp.object() >50){
    Serial.println("LED 0/1/2 - Temp Setting 2");
    for(int i=0;i<3;i++){
       pixels.setPixelColor(i, pixels.Color(0,15,0));
       pixels.show();
    }
    }

delay(1500);

    }
}

Thanks everyone.

Look at the Blink Without Delay example (File->examples->02.Digital->BlinkWithoutDelay) as it will show you how to do things like pulse an LED each time through loop() rather than waiting....

Once you understand that code, you can apply it to whatever pixel is the "pulsating" pixel that you will have to keep track of (hint: a variable)

Great, thank you so much! Looks like my biggest issue has been using delay() to drive it all.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.