## 코드
int tempPin = 0;
int motorPin = 3;
void setup() {
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int val = analogRead(tempPin);
float voltage = (val / 1024.0) * 5000.0;
float tempVal = (voltage - 500) / 10;
Serial.println(tempVal);
if(tempVal > 24){
analogWrite(motorPin, 100);
} else {
analogWrite(motorPin, 0);
}
}
## 시뮬레이션
## 더 해보기
주변 온도에 따라 단계적으로 모터 속도를 제어하기. 예를 들면 25도 이상이면 모터 속도가 100, 28도 이상이면 모터 속도가 200, 30도 이상이면 모터 속도가 250이 되도록 한다.