2016年4月8日 星期五

Arduino/讀取光敏電阻數值

使用範例/01Basics/AnalogReadSerial

CODE

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:

  int sensorValue = analogRead(A0);

  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}

數值會與亮度成正比
從序列埠間視窗可以看到數值的變化,也可從serial plotter繪出圖表,當然也能用PLX-DAQ匯出資料到excel。

CODE


int analogPin = 0;

int RED = 0;

void setup(){
  Serial.begin(9600);
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,Timer,RED");
      
}
void loop(){
      RED = analogRead(analogPin);
     
  Serial.print("DATA,TIME"); 
  Serial.print(",");
  Serial.print("TIMER"); 
  Serial.print(",");
  Serial.print(RED);
  Serial.print(",");
     
       delay(100);
}



沒有留言:

張貼留言