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;
}
//==========================================





沒有留言:

張貼留言

WOKWI DHT22 & LED , Node-Red + SQLite database

 WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...