I am trying to build a simple arduino thermometer that lights up a different LED depending on the temperature. I am using an adafruit 5v trinket and a 12 neopixel ring with a tmp36 temperature sensor. My problem is that only LED 11 lights up. I have tried changing the range to test the temperature and I know that my room is colder than this.Here is the code I'm using:
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 3
#define NUMPIXELS 12
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500;
int sensorPin = 1;
void setup() {
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
pixels.begin();
}
void loop() {
int reading = analogRead(sensorPin);
int voltage = reading * 5.0;
voltage /= 1024;
int temp = (voltage - 0.5) * 100;
temp = constrain(temp, 23, 35);
temp = map(temp, 23, 35, 0, 11);
pixels.setPixelColor(temp, 0, 255, 38);
pixels.show();
delay(100);
}
Help would be much appreciated. Thanks :)