A quick course in Binary


project #20: creating a digital thermometer



Download 2,72 Mb.
bet11/17
Sana03.07.2022
Hajmi2,72 Mb.
#736533
1   ...   7   8   9   10   11   12   13   14   ...   17
Bog'liq
6 bo`lim

project #20: creating a digital thermometer


In this project we’ll add the TMP36 temperature sensor we created in Chapter 4 to the double-digit circuit constructed for Project 19 to create a digital thermometer. The algorithm is simple: we read the voltage returned from the TMP36 (using the method from Project 12) and convert the reading to degrees Celsius.

The Hardware


The following hardware is required:

  • The double-digit circuit from Project 19

  • One TMP36 temperature sensor

Connect the center output lead of the TMP36 to analog pin 5, the left lead to 5 V, and the right lead to GND, and you’re ready to measure.

The Sketch


Here is the sketch:
// Project 20 - Creating a Digital Thermometer
#define DATA 6 // connect to pin 14 on the 74HC595
#define LATCH 8 // connect to pin 12 on the 74HC595 #define CLOCK 10 // connect to pin 11 on the 74HC595
int temp = 0; float voltage = 0; float celsius = 0; float sensor = 0; int digits[]={
252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142};
void setup()
{
pinMode(LATCH, OUTPUT);
pinMode(CLOCK, OUTPUT); pinMode(DATA, OUTPUT);
}
void displayNumber(int n)
{
int left, right = 0; if (n < 10) {
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, LSBFIRST, digits[n]); shiftOut(DATA, CLOCK, LSBFIRST, digits[0]); digitalWrite(LATCH, HIGH);
}
if (n >= 10)
{ right = n % 10; left = n / 10; digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, LSBFIRST, digits[right]); shiftOut(DATA, CLOCK, LSBFIRST, digits[left]); digitalWrite(LATCH, HIGH);
} }
void loop() {
sensor = analogRead(5);
voltage = (sensor * 5000) / 1024; // convert raw sensor value to millivolts voltage = voltage - 500; // remove voltage offset celsius = voltage / 10; // convert millivolts to Celsius temp = int(celsius); // change the floating point temperature to an int displayNumber(temp); delay(500);
}
The sketch is simple and borrows code from previous projects: displayNumber() from Project 19 and the temperature calculations from Project 12. The delay(500); function in the second-to-last line of the sketch keeps the display from changing too quickly when the temperature fluctuates.

Download 2,72 Mb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   ...   17




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish