반응형
SMALL

녕하세요! Choi GPT 입니다.

오늘은 팅커캐드(Tinkercad)의 TMP36 온도센서를 활용하여 LED를 연동하는 프로그램을 소개하고자 합니다.

int sensor = A0;
int RLED = 9;
int YLED = 10;
int BLED = 11;

void setup()
{
  Serial.begin(9600);
  pinMode(RLED, OUTPUT);
  pinMode(YLED, OUTPUT);
  pinMode(BLED, OUTPUT);
}

void loop()
{
  int sensing = analogRead(sensor);
  float voltage = sensing*5.0/1024.0;
  float temperture = voltage *100-50;
  Serial.print("temperture: ");
  Serial.println(temperture);
  delay(100);
  if(temperture >=-40 && temperture <=20)
  {
    digitalWrite(RLED, 1);
    digitalWrite(YLED, 0);
    digitalWrite(BLED, 0);
  }
   else if(temperture >=21 && temperture <=100 )
  {
    digitalWrite(RLED, 0);
    digitalWrite(YLED, 1);
    digitalWrite(BLED, 0);
  }
   else if(temperture >=101 && temperture <=125 )
  {
    digitalWrite(RLED, 0);
    digitalWrite(YLED, 0);
    digitalWrite(BLED, 1);
  }
  else
  {
    digitalWrite(RLED, 0);
    digitalWrite(YLED, 0);
    digitalWrite(BLED, 0);
  }
}

TMP36_r2.txt
0.00MB

반응형
LIST

+ Recent posts