Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan1 智慧電子應用設計導論 (1/3) Sensors I Chin-Shiuh Shieh ( 謝欽旭 ) Department of Electronic Engineering National Kaohsiung University of Applied Sciences, Taiwan
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan2 Light
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan3 Light (cont) void setup() { Serial.begin(9600); } void loop() { int sensorReading = analogRead(A0); Serial.println(sensorReading); int thisPitch = map(sensorReading, 400, 1000, 120, 1500); tone(2, thisPitch, 10); delay(10); }
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan4 Pressure
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan5 Pressure (count) void setup() { Serial.begin(9600); } void loop() { int sensorReading = analogRead(A0); Serial.println(sensorReading); int thisPitch = map(sensorReading, 0, 800, 120, 1500); tone(2, thisPitch, 10); delay(1); }
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan6 PIR
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan7 PIR (cont) int ledPin = 13; int switchPin = 2; int value = 0; void setup() { pinMode(ledPin, OUTPUT); pinMode(switchPin, INPUT); } void loop() { value = digitalRead(switchPin); if (HIGH == value) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan8 PING )))
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan9 PING ))) (cont) const int pingPin = 2; void setup() { Serial.begin(9600); } void loop() { long duration, inches, cm; pinMode(pingPin, OUTPUT);digitalWrite(pingPin, LOW); delayMicroseconds(2);digitalWrite(pingPin, HIGH); delayMicroseconds(5);digitalWrite(pingPin, LOW); pinMode(pingPin, INPUT);duration = pulseIn(pingPin, HIGH); cm = microsecondsToCentimeters(duration); Serial.print(cm);Serial.print("cm");Serial.println(); delay(100); }
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan10 PING ))) (cont) long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan11 Temperature Wirehttp:// Wire
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan12 Loudness
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan13 Loudness (cont) void setup() { Serial.begin(9600); } void loop() { Serial.println(analogRead(A0)); delay(500); }