智慧電子應用設計導論 (1/3) Sensors III

9
Autumn, 2012 C.-S. Shieh, EC, KUAS, T aiwan 1 智智智智智智智智智智 (1/3) Sensors III Chin-Shiuh Shieh ( 智智智 ) http://bit.kuas.edu.tw/~csshieh Department of Electronic Engineeri ng National Kaohsiung University of A pplied Sciences, Taiwan

description

智慧電子應用設計導論 (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() { - PowerPoint PPT Presentation

Transcript of 智慧電子應用設計導論 (1/3) Sensors III

Page 1: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 1

智慧電子應用設計導論 (1/3)Sensors III

Chin-Shiuh Shieh (謝欽旭 )http://bit.kuas.edu.tw/~csshieh

Department of Electronic Engineering

National Kaohsiung University of Applied Sciences, Taiwan

Page 2: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 2

Humidity

Page 3: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 3

Humidity (cont)

void setup() {

Serial.begin(9600);

}

void loop() {

Serial.println(analogRead(A0));

delay(500);

}

Page 4: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 4

Temperature/ Humidity

• https://github.com/practicalarduino/SHT1x

Page 5: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 5

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");}

Page 6: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 6

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);}

Page 7: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 7

3-Axis Accelerometer

• http://code.google.com/p/mma-7455-arduino-library/

Page 8: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 8

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);

}

Page 9: 智慧電子應用設計導論 (1/3) Sensors III

Autumn, 2012 C.-S. Shieh, EC, KUAS, Taiwan 9

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);}