เขียนโปรแกรมแสดงค่าอุณหภูมิจากเซนเซอร์แอนาลอกแสดงผลที่ LCD 16x2
ฟังก์ชั่นที่ใช้ในกลุ่ม LCD http://arduino.cc/en/Tutorial/LiquidCrystal (http://arduino.cc/en/Tutorial/LiquidCrystal)
-lcd.begin()http://arduino.cc/en/Reference/LiquidCrystalBegin (http://arduino.cc/en/Reference/LiquidCrystalBegin)
-lcd.print() http://arduino.cc/en/Reference/LiquidCrystalPrint (http://arduino.cc/en/Reference/LiquidCrystalPrint)
-lcd.setCursor() http://arduino.cc/en/Reference/LiquidCrystalSetCursor (http://arduino.cc/en/Reference/LiquidCrystalSetCursor)
-Liquid Crystal Library (ฟังก์ชั่นอื่น ๆ ที่มีให้ใช้งาน) http://arduino.cc/en/Reference/LiquidCrystal (http://arduino.cc/en/Reference/LiquidCrystal)
*ไลบารี่ LiquidCrystal.h มีมาให้แล้วพร้อมโปรแกรม Arduino IDE ไม่ต้องติดตั้งเพิ่ม
ฟังก์ชั่นทั่วไป
-delay() http://arduino.cc/en/Reference/Delay (http://arduino.cc/en/Reference/Delay)
-delayMicroseconds() http://arduino.cc/en/Reference/DelayMicroseconds (http://arduino.cc/en/Reference/DelayMicroseconds)
-analogRead() http://arduino.cc/en/Reference/AnalogRead (http://arduino.cc/en/Reference/AnalogRead)
-map() http://arduino.cc/en/Reference/Map (http://arduino.cc/en/Reference/Map)
โจทย์โปรแกรม
-เขียนโปรแกรมแสดงอุณหภูมิปัจจุบัน (องศาเซลเซียส) โดยใช้เซนเซอร์แอนาลอกแล้วแสดงค่าบน LCD
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino
(http://www.praphas.com/PhotoForum/arduino/Lab-35-01.png)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)
(http://www.praphas.com/PhotoForum/arduino/Lab-35-02.png)
บริเวณใช้งานบอร์ดทดลอง
(http://www.praphas.com/PhotoForum/arduino/Lab-35-03.png)
โปรแกรมตัวอย่างการแสดงผลจอ LCD
#include <LiquidCrystal.h>
/* The circuit:
* LCD RS pin to digital pin 7
* LCD E pin to digital pin 6
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
*/
LiquidCrystal lcd(7,6,5,4,3,2); // set up the LCD's connection pins
void setup()
{
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.print("hello, world!");
}
void loop() {}
ตัวอย่างโปรแกรมแสดงอุณภูมิเบื้องต้น
#include <math.h>
double Thermistor(int RawADC)
{
double Cal;
Cal = log(10000.0/((1024.0/RawADC-1)));
Cal = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Cal * Cal ))* Cal );
Cal = Cal - 273.15; // Convert Kelvin to Celcius
return Cal;
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
int Temp=Thermistor(analogRead(A3));
Serial.println(Temp);
delay(1000);
}