12 Mayıs 2015 Salı


Led delays according to the temperature sensor and its brightness changes due to photo sensor value.
Photo sensor and temperature sensor are connected with analog pins of Arduino. Photo sensor values are mapped into leds brightness value and temperature is mapped into time intervals.
In the below code sample and video is shown :



Codes:

const byte sensorPin=0,sensorTemp=1;
const byte ledPin=11;
int lightLevel,low=300,high=1000,tmpLevel;
void setup()
{
  // We'll set up the LED pin to be an output.
  // (We don't need to do anything special to use the analog input.)
  Serial.begin(9600);
}
void loop(){
  lightLevel=analogRead(sensorPin);
  tmpLevel=analogRead(sensorTemp);
  Serial.print("Analog Read Value ");
  Serial.println(lightLevel);
  Serial.print("Temp read value ");
  Serial.println(tmpLevel);
  float voltage = getVoltage(tmpLevel);
  float degreesC = (voltage - 0.5) * 100.0;
  Serial.print("  deg C: ");
  Serial.println(degreesC);
  tune();
  digitalWrite(ledPin,HIGH);
  analogWrite(ledPin,lightLevel);
  delay(tmpLevel*10);
  digitalWrite(ledPin,LOW);
    delay(tmpLevel*10);
}

void tune(){
  lightLevel=map(lightLevel,low,high,0,255);
  Serial.print("Light map value = ");
  Serial.println(lightLevel);
  lightLevel=constrain(lightLevel,0,255);
  Serial.print("Light constrain value = ");
  Serial.println(lightLevel);
}
float getVoltage(int tmp_Level)
{

  return (tmp_Level * 0.004882814);

}

Hiç yorum yok:

Yorum Gönder