Skip to content

Instantly share code, notes, and snippets.

@penpencool
Last active December 16, 2019 16:01
Show Gist options
  • Save penpencool/6c37a7eda7fa950d954782f5c21a7cf6 to your computer and use it in GitHub Desktop.
Save penpencool/6c37a7eda7fa950d954782f5c21a7cf6 to your computer and use it in GitHub Desktop.
//Example By ArduinoAll
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 //กำหนดว่าขาของเซนเซอร์ 18B20 ต่อกับขา 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void) {
Serial.begin(9600);
Serial.println("ArduinoAll Test Temperature 18B20");
sensors.begin();
}
void loop(void) {
sensors.requestTemperatures(); //สั่งอ่านค่าอุณหภูมิ
Serial.print(sensors.getTempCByIndex(0)); // แสดงค่าอุณหภูมิ
Serial.println(" *C");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment