Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
fmattiussi
Published © CERN-OHL

NeoPixel Thermometer!

Transform a NeoPixel ring into a cool thermometer

BeginnerProtip5,006
NeoPixel Thermometer!

Things used in this project

Hardware components

Adafruit NeoPixel Ring - 12x 5050 RGB LED
×1
Arduino UNO
Arduino UNO
×1
SparkFun Temperature Sensor - TMP36
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Schematics of project

Useful to know how to wiring the parts

Measure Sheet

Code

Code

C/C++
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
// named constant for the pin the sensor is connected to
#define PIN            6

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      12

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 20.0;

void setup() {
  // open a serial connection to display values
  Serial.begin(9600);
  pixels.begin();
  // set the LED pins as outputs
  // the for() loop saves some extra coding
  for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
}

void loop() {
  
  // read the value on AnalogIn pin 0
  // and store it in a variable
  int sensorVal = analogRead(sensorPin);


  float voltage = (sensorVal / 1024.0) * 5.0;


  Serial.print(", degrees C: ");
  float temperature = (voltage - .5) * 100;
  Serial.print(temperature);

  if (temperature > 11 && temperature < 12.5  ) {
    Serial.println("cold-01");
    for(int i=0;i<2;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(49,0,225)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

  }
  }
  
  if (temperature > 12.6 && temperature < 14  ) {
    Serial.println("cold");
    for(int i=0;i<2;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,106,225)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

  }
  }
  if (temperature > 14.1 && temperature < 15.5 ) {
    Serial.println("cold1");
for(int i=0;i<3;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,203,225)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware

  }
  }
  if (temperature > 15.6 && temperature < 17 ) {
    Serial.println("cold2");
for(int i=0;i<4;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,225,148)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

  }
  }
  if (temperature > 17.1 && temperature < 18.5 ) {
    Serial.println("cold3");
for(int i=0;i<5;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,225,21)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.


  }
  }
  if (temperature > 18.6 && temperature < 20 ) {
    Serial.println("cold4");
for(int i=0;i<6;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(115,225,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.


  }
  }
  if (temperature > 21.1 && temperature < 22.5 ) {
    Serial.println("cold5");
for(int i=0;i<7;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(216,225,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.


  }
  }
  if (temperature > 22.6 && temperature < 24 ) {
    Serial.println("cold6");
for(int i=0;i<8;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(225,179,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.


  }
  }
  if (temperature > 24.1 && temperature < 25.5 ) {
    Serial.println("cold7");
for(int i=0;i<9;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(225,62,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.



  }
  }
  if (temperature > 25.6 && temperature < 27 ) {
    Serial.println("cold8");
for(int i=0;i<10;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(225,0,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.



  }
  }
  if (temperature > 27.1 && temperature < 28.5 ) {
    Serial.println("cold9");
for(int i=0;i<11;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(225,0,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.


  }
  }
  if (temperature > 28.6 && temperature <30) {
    Serial.println("cold10");
for(int i=0;i<12;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(225,0,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.



  }
  }
delay(5000);
pixels.clear();

}

Credits

fmattiussi

fmattiussi

5 projects • 2 followers

Comments