#include <Adafruit_NeoPixel.h>
#define NTC_PIN A0 // Pin connected to the NTC sensor
#define LED_PIN 2 // Pin connected to the NeoPixel Ring
#define NUM_LEDS 18 // Number of LEDs in the NeoPixel Ring
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Read analog input from the NTC sensor
int ntcValue = analogRead(NTC_PIN);
// Convert analog value to temperature using Steinhart-Hart equation or your own calibration
float temperature = convertToTemperature(ntcValue);
// Print temperature to serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Define temperature color ranges
int blueThreshold = 10; // Below this temperature, color is blue
int greenThreshold = 30; // Between this and blueThreshold, color is green
int orangeThreshold = 40; // Below this and greenThreshold, color is orange
// Above this temperature, color is red
// Set NeoPixel Ring color based on temperature
if ( temperature < blueThreshold) {
setRingColor(0, 0, 255, 200);
} else if ( temperature < greenThreshold) {
setRingColor(0, 255, 0, 200);
} else if ( temperature < orangeThreshold ) {
setRingColor(255, 165, 0, 200);
} else {
setRingColor(255, 0, 0, 200);
}
delay(1000); // Delay between readings
}
void setRingColor(int red, int orange, int green, int blue) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(red, orange, green, blue));
}
strip.show();
}
float convertToTemperature(int ntcValue) {
// Implement your own conversion function based on NTC characteristics
// This is a simplified example, you may need calibration
float resistance = 10000.0 / ((1023.0 / ntcValue) - 1);
float temperature = log(resistance / 10000.0);
temperature /= 3950.0;
temperature += 1.0 / (25.0 + 273.15);
temperature = 1.0 / temperature;
temperature -= 273.15;
return temperature;
}