งานที่18
Sensor DS18B20 Arduino วัดอุณหภูมิในน้ำ include < OneWire.h > # include < DallasTemperature.h > # define ONE_WIRE_BUS 2 // กำหนดขา OneWire oneWire (ONE_WIRE_BUS); DallasTemperature sensors (&oneWire); void setup ( void ) { Serial. begin ( 9600 ); Serial. println ( " Dallas Temperature IC Control Library " ); Serial. println ( " by 9arduino.com " ); sensors. begin (); } void loop ( void ) { Serial. print ( " Requesting temperatures... " ); sensors. requestTemperatures (); // อ่านข้อมูลจาก library Serial. print ( " Temperature is: " ); Serial. print (sensors. getTempCByIndex ( 0 )); // แสดงค่า อูณหภูมิ sensor 0 delay ( 1000 ); }