บทความ

งานที่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 ); }

งานที่17

รูปภาพ
Water flow Sensor กับ Arduino วัดน้ำไหลในท่อ Arduino Uno R3 volatile int flow_frequency; unsigned int l_hour, f_val; unsigned long ctTime, flow_val, cloopTime; void flow () // Water flow Interrupt function { flow_frequency++; f_val++; } void setup () { Serial. begin ( 9600 ); attachInterrupt ( 1 , flow, RISING); sei (); ctTime = millis (); cloopTime = ctTime; // Water flow } void loop () { ctTime = millis (); if (ctTime >= (cloopTime + 1000 )) { cloopTime = ctTime; l_hour = (flow_frequency * 60 / 7.5 ); flow_frequency = 0 ; Serial. print ( " Water Sensor : " ); Serial. print (l_hour, DEC); Serial. print ( " L/hour " ); } if (f_val >= 450 ) { flow_val++; f_val = 0 ; } Serial. print ( " \t " ); Serial. print (flow_val); Serial. println ( " L " ); }

งานที่16

รูปภาพ
DS3231 โมดูลนาฬิกา ตั้งเวลา include < Wire.h > # include < SPI.h > # include < RTClib.h > RTC_DS3231 RTC; void setup () { Serial. begin ( 9600 ); Wire. begin (); RTC. begin (); RTC. adjust ( DateTime (__DATE__, __TIME__)); // จุดนี้เป็นการตั้งเวลา ตั้งครั้งแรกเสร็จแล้วให้ // ไว้ด้วย if (! RTC. isrunning ()) { Serial. println ( " RTC is NOT running! " ); RTC. adjust ( DateTime (__DATE__, __TIME__)); } DateTime now = RTC. now (); RTC. setAlarm1Simple ( 21 , 58 ); // เป็นการตั้งเวลาปลุก เวลา 22.58 น. RTC. turnOnAlarm ( 1 ); // ปลุกช่วงเวลาที่ 1 if (RTC. checkAlarmEnabled ( 1 )) { Serial. println ( " Alarm Enabled " ); } } void loop () { DateTime now = RTC. now (); Serial. print (now. year (), DEC); Serial. print ( ' / ' ); Serial. print (now. month (), DEC); Serial. print ( ' / ' ); Serial. print (now. day (