2015年7月23日 星期四

Arduino using PWM Controlled a Fan

//Arduino Fan Control

//  * SoftwarePWM.pde
const int pin = 3;
boolean Q=1;
void setup()
{
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  if (Q) {
    FullRun();
  }

 int sensorValue = analogRead(A0);
 int sensor1 = map(sensorValue, 0, 1023, 0 ,255);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.print("Analog VR Read: ");
  Serial.print(sensor1);
  Serial.print("   Voltage:  Analoag Read * (5.0 / 1023.0)= ");
  Serial.println(voltage);

  analogWrite(pin, sensor1);
 }
//==========================================

void FullRun() {
analogWrite(pin, 255);
delay(1500);
Q=0;
}
//==========================================





沒有留言:

張貼留言

Node-Red 抓取 opendata 的資料集產生AQI 空氣品質指

Node-Red 抓取 opendata 的資料集產生AQI 空氣品質指標 實現透過 Node-RED 抓取環境部 OpenData(空氣品質 AQI)資料,最核心的流程為: 注入觸發(Inject) → HTTP 請求(http request) → 解析 JSON 資料(Fu...