90 likes | 193 Views
智慧電子應用設計導論 (1/3) Sensors III. Chin-Shiuh Shieh ( 謝欽旭 ) http://bit.kuas.edu.tw/~csshieh Department of Electronic Engineering National Kaohsiung University of Applied Sciences, Taiwan. Humidity. Humidity (cont). void setup() { Serial.begin(9600); } void loop() {
E N D
智慧電子應用設計導論(1/3)Sensors III Chin-Shiuh Shieh (謝欽旭) http://bit.kuas.edu.tw/~csshieh Department of Electronic Engineering National Kaohsiung University of Applied Sciences, Taiwan C.-S. Shieh, EC, KUAS, Taiwan
Humidity C.-S. Shieh, EC, KUAS, Taiwan
Humidity (cont) void setup() { Serial.begin(9600); } void loop() { Serial.println(analogRead(A0)); delay(500); } C.-S. Shieh, EC, KUAS, Taiwan
Temperature/ Humidity • https://github.com/practicalarduino/SHT1x C.-S. Shieh, EC, KUAS, Taiwan
Temperature/ Humidity (cont) #include <SHT1x.h> #define dataPin 2 #define clockPin 3 SHT1x sht1x(dataPin, clockPin); void setup() { Serial.begin(9600); Serial.println("Starting up"); } C.-S. Shieh, EC, KUAS, Taiwan
Temperature/ Humidity (cont) void loop() { float temp_c; float temp_f; float humidity; // Read values from the sensor temp_c = sht1x.readTemperatureC(); temp_f = sht1x.readTemperatureF(); humidity = sht1x.readHumidity(); // Print the values to the serial port Serial.print("Temperature: "); Serial.print(temp_c, DEC); Serial.print("C / "); Serial.print(temp_f, DEC); Serial.print("F. Humidity: "); Serial.print(humidity); Serial.println("%"); delay(2000); } C.-S. Shieh, EC, KUAS, Taiwan
3-Axis Accelerometer • http://code.google.com/p/mma-7455-arduino-library/ C.-S. Shieh, EC, KUAS, Taiwan
3-Axis Accelerometer (cont) #include <Wire.h> #include <MMA_7455.h> MMA_7455 mySensor = MMA_7455(); char xVal, yVal, zVal; void setup() { Serial.begin(9600); // Set the sensitivity you want to use // 2 = 2g, 4 = 4g, 8 = 8g mySensor.initSensitivity(2); // Calibrate the Offset, that values corespond in // flat position to: xVal = -30, yVal = -20, zVal = +20 // !!!Activate this after having the first values read out!!! //mySensor.calibrateOffset(0.23, -43.2, 12.43); } C.-S. Shieh, EC, KUAS, Taiwan
3-Axis Accelerometer (cont) void loop() { xVal = mySensor.readAxis('x'); yVal = mySensor.readAxis('y'); zVal = mySensor.readAxis('z'); Serial.print(xVal,DEC);Serial.print(" "); Serial.print(yVal,DEC);Serial.print(" "); Serial.print(zVal,DEC);Serial.print(" "); Serial.println(); delay(500); } C.-S. Shieh, EC, KUAS, Taiwan