Temperature Sensor with Arduino & LED

This is a mini project using Arduino. This uses a temperature sensor and Arduino Uno.


int pin = 2;
int temperaturePin=0;

void setup() { 
  Serial.begin(9600);
  for(pin = 2; pin < = 9; pin += 1){
    pinMode(pin,OUTPUT);
  }
} 
  
void loop() {
  float temperature = getVoltage(temperaturePin);
  temperature = (temperature - .5) * 100;
  
  int toLit = map(temperature,20,80,2,9);
  lightsToLit(2,toLit);
  delay(250);
} 

void lightsToLit(int start,int end){
  for(pin = 2; pin <= 9; pin += 1){
    digitalWrite(pin,LOW);
  }
  for(pin = start; pin <= end; pin += 1){
    digitalWrite(pin,HIGH);
  }
}

float getVoltage(int pin){
 return (analogRead(pin) * .004882814);
}

Reference: SparkFun Inventor's Kit Sample Project - 02, SparkFun Inventor's Kit Sample Project - 10

By Imthiaz

Programmer, SAAS, CMS & CRM framework designer, Love Linux & Apple products, Currently addicted to mobile development & working @bluebeetle

1 comment

Comments are closed.