Created
June 12, 2019 07:34
-
-
Save fxprime/3d7142500f952395ef1be8ee61026f50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| www.arduinona.com | |
| ตัวอย่างการต่อสาย AM2320 กับ Arduino Uno | |
| โมดูล -> Arduino Uno | |
| VCC -> 3.3-5V | |
| GND -> GND | |
| SCL -> A5 | |
| SDA -> A4 | |
| ท่านสามารถตรวจสอบ pin สำหรับ i2C สำหรับบอร์ดอื่นๆที่ไม่ใช้ Uno ได้จาก | |
| https://www.arduino.cc/en/Reference/Wire | |
| */ | |
| #include <Wire.h> | |
| #include <AM2320.h> | |
| AM2320 sensor; | |
| void setup() { | |
| //Initialize การสื่อสารระหว่างคอมและบอร์ดอาดุยโน่ | |
| Serial.begin(9600); | |
| } | |
| void loop() { | |
| switch (sensor.Read()) { | |
| case 2: | |
| Serial.println("CRC failed"); | |
| break; | |
| case 1: | |
| Serial.println("Sensor offline"); | |
| break; | |
| case 0: | |
| Serial.print("humidity: "); | |
| Serial.print(th.h); | |
| Serial.print("%, temperature: "); | |
| Serial.print(th.t); | |
| Serial.println("*C"); | |
| break; | |
| } | |
| delay(200); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment