Elektrik elektronik eğitimi ile ilgili bilgiler, kitap özetleri, kitap sınav soruları ve eğitime dair her şey
Sayfalar
▼
30 Ağustos 2019 Cuma
Arduino UNO ve LM335 Sıcaklık Sensörü ile 7 Segment Displayli Uygulama Devresi ve Program Kodu
Yukarıdaki devredeArduino UNO ve LM335 Sıcaklık Sensörü ile 7 Segment Displayli Uygulama Devresi görülmektedir.
Bu devrede LM335 sıcaklık sensörü ile yapılan ölçüm 7 segment displayde görülmektedir.
LM335 sıcaklık sensörü 10 mV/°K. 10 mV çıkışı 1 Kelvi derecesini göstermektedir. Örneğin LM335 çıkış gerilimi 3.03 V (3030 mV) olduğunda sıcaklık 303 Kelvin = 30 °Celsius (30 derece) olur.
Kullanılan Devre Elemanları :
Arduino UNO board
3-digit veya 4-digit ortak anotlu 7 segment display
LM335 sıcaklık sensörü
3 x PNP transistor (2SA1015, 2S9015, 2N3906 …)
7 x 100 ohm direnç
3 x 4.7k ohm direnç
2.2k ohm direnç
Breadboard
Arduino Kodu
/*
* Interfacing Arduino with LM335 temperature sensor and 7-segment display.
* Common anode 7-segment display is used.
* This is a free software with NO WARRANTY.
* http://elektrikelektronikegitimi.blogspot.com
*/
// define LM335 data pin connection
#define LM335_pin A0
// segment pins definitions
#define SegA 12
#define SegB 11
#define SegC 10
#define SegD 9
#define SegE 8
#define SegF 7
#define SegG 6
// common pins of the three digits definitions
#define Dig1 4
#define Dig2 3
#define Dig3 2
// variable declarations
byte current_digit;
int temp;
void setup()
{
pinMode(SegA, OUTPUT);
pinMode(SegB, OUTPUT);
pinMode(SegC, OUTPUT);
pinMode(SegD, OUTPUT);
pinMode(SegE, OUTPUT);
pinMode(SegF, OUTPUT);
pinMode(SegG, OUTPUT);
pinMode(Dig1, OUTPUT);
pinMode(Dig2, OUTPUT);
pinMode(Dig3, OUTPUT);
disp_off(); // turn off the display
// Timer1 module overflow interrupt configuration
TCCR1A = 0;
TCCR1B = 1; // enable Timer1 with prescaler = 1 ( 16 ticks each 1 µs)
TCNT1 = 0; // set Timer1 preload value to 0 (reset)
TIMSK1 = 1; // enable Timer1 overflow interrupt
}
ISR(TIMER1_OVF_vect) // Timer1 interrupt service routine (ISR)
{
disp_off(); // turn off the display
byte abs_temp = abs(temp); // abs: absolute value
switch (current_digit)
{
case 1:
if(temp < 0 || temp >= 100){
if(temp < 0)
disp(10); // print minus sign (-)
else
disp(1); // print 1
digitalWrite(Dig1, LOW); // turn on digit 1
}
break;
case 2:
disp( (abs_temp / 10) % 10); // prepare to display digit 2
digitalWrite(Dig2, LOW); // turn on digit 2
break;
case 3:
disp(abs_temp % 10); // prepare to display digit 3
digitalWrite(Dig3, LOW); // turn on digit 3
}
current_digit = (current_digit % 3) + 1;
}
// main loop
void loop()
{
int kelvin = analogRead(LM335_pin) * 0.489; // get temperature in degree Kelvin
temp = kelvin - 273; // convert to degree Celsius
delay(1000); // wait 1 second
}
void disp(byte number)
{
switch (number)
{
case 0: // print 0
digitalWrite(SegA, LOW);
digitalWrite(SegB, LOW);
digitalWrite(SegC, LOW);
digitalWrite(SegD, LOW);
digitalWrite(SegE, LOW);
digitalWrite(SegF, LOW);
digitalWrite(SegG, HIGH);
break;
case 1: // print 1
digitalWrite(SegA, HIGH);
digitalWrite(SegB, LOW);
digitalWrite(SegC, LOW);
digitalWrite(SegD, HIGH);
digitalWrite(SegE, HIGH);
digitalWrite(SegF, HIGH);
digitalWrite(SegG, HIGH);
break;
case 2: // print 2
digitalWrite(SegA, LOW);
digitalWrite(SegB, LOW);
digitalWrite(SegC, HIGH);
digitalWrite(SegD, LOW);
digitalWrite(SegE, LOW);
digitalWrite(SegF, HIGH);
digitalWrite(SegG, LOW);
break;
case 3: // print 3
digitalWrite(SegA, LOW);
digitalWrite(SegB, LOW);
digitalWrite(SegC, LOW);
digitalWrite(SegD, LOW);
digitalWrite(SegE, HIGH);
digitalWrite(SegF, HIGH);
digitalWrite(SegG, LOW);
break;
case 4: // print 4
digitalWrite(SegA, HIGH);
digitalWrite(SegB, LOW);
digitalWrite(SegC, LOW);
digitalWrite(SegD, HIGH);
digitalWrite(SegE, HIGH);
digitalWrite(SegF, LOW);
digitalWrite(SegG, LOW);
break;
case 5: // print 5
digitalWrite(SegA, LOW);
digitalWrite(SegB, HIGH);
digitalWrite(SegC, LOW);
digitalWrite(SegD, LOW);
digitalWrite(SegE, HIGH);
digitalWrite(SegF, LOW);
digitalWrite(SegG, LOW);
break;
case 6: // print 6
digitalWrite(SegA, LOW);
digitalWrite(SegB, HIGH);
digitalWrite(SegC, LOW);
digitalWrite(SegD, LOW);
digitalWrite(SegE, LOW);
digitalWrite(SegF, LOW);
digitalWrite(SegG, LOW);
break;
case 7: // print 7
digitalWrite(SegA, LOW);
digitalWrite(SegB, LOW);
digitalWrite(SegC, LOW);
digitalWrite(SegD, HIGH);
digitalWrite(SegE, HIGH);
digitalWrite(SegF, HIGH);
digitalWrite(SegG, HIGH);
break;
case 8: // print 8
digitalWrite(SegA, LOW);
digitalWrite(SegB, LOW);
digitalWrite(SegC, LOW);
digitalWrite(SegD, LOW);
digitalWrite(SegE, LOW);
digitalWrite(SegF, LOW);
digitalWrite(SegG, LOW);
break;
case 9: // print 9
digitalWrite(SegA, LOW);
digitalWrite(SegB, LOW);
digitalWrite(SegC, LOW);
digitalWrite(SegD, LOW);
digitalWrite(SegE, HIGH);
digitalWrite(SegF, LOW);
digitalWrite(SegG, LOW);
break;
case 10: // print -
digitalWrite(SegA, HIGH);
digitalWrite(SegB, HIGH);
digitalWrite(SegC, HIGH);
digitalWrite(SegD, HIGH);
digitalWrite(SegE, HIGH);
digitalWrite(SegF, HIGH);
digitalWrite(SegG, LOW);
}
}
void disp_off()
{
digitalWrite(Dig1, HIGH);
digitalWrite(Dig2, HIGH);
digitalWrite(Dig3, HIGH);
}
// end of code.
Hiç yorum yok:
Yorum Gönder