Assalamualaikum wr.wb..
Pada postingan kali ini, saya akan membuat sebuah projek menggunakan sensor suhu. Sensor suhu yang digunakan pada projek kali ini adalah LM35. Untuk melihat datasheet dari LM35 klik disini. Board yang digunakan pada projek ini adalah board PASID_UNO. Sebelumnya teman-teman pasti bingung, apa itu PASID_UNO? bentuknya gimana?. ini adalah bentuk dan fisik dari board_pasid_uno.
Saya akan menjelaskan sedikit tentang board ini. board PASID_UNO merupakan hasil cloningan dari arduino uno. Board ini menggunakan atmega328 yang sebelumnya telah diisi bootloader arduino uno. Board ini mempunyai fungsi yang sama dengan arduino uno, yaitu sama sama bisa menggunakan arduino software. Untuk proses uploading program, PASID_UNO menggunakan komunikasi rx & tx (komunikasi serial). Untuk penjelasan lengkapnya tentang board ini, insyaallah ke depannya saya akan buat postingan mengenai PASID_UNO,,,
Kembali ke projek, sensor suhu dalam projek dihubungkan ke A0. sedangkan tampilannya yaitu 7segment dihubungkan mulai dari pin D2, D3, D4, D5, D6, D7 dan D8. Projek ini menggunakan 4 buah 7segment common anode. Untuk menampilkan data ke 7segment, saya menggunakan metode scanning, yaitu menggunakan transistor untuk men-switch dari masing-masing 7segment. Jadi ke empat transistor dihubungkan ke pin D9, D10, D11, dan D12.
Adapun listing programnya :
const int digit1=9;
const int digit2=10;
const int digit3=11;
const int digit4=12;
const int indikator=13;
const int sensor = A0;
int angka=0;
int data_sensor=0;
int data_suhu=0;
const byte numeral[10] = {
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11110110, // 9
};
const int segmentPins[8] = { 9,8,7,6,5,4,3,2};
void setup()
{
for(int i=0; i < 8; i++)
{
pinMode(segmentPins[i], OUTPUT);
}
pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
pinMode(digit3, OUTPUT);
pinMode(digit4, OUTPUT);
pinMode(indikator, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(data_suhu>30)
{
digitalWrite(indikator, HIGH);
}
else
{
digitalWrite(indikator,LOW);
}
Serial.println(data_suhu);
delay(1);
baca_sensor();
showDigit(data_suhu/10);
digitalWrite(digit1, LOW);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
delay(7);
showDigit(data_suhu%10);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, LOW);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
delay(7);
tampil_derajat();
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
digitalWrite(digit4, HIGH);
delay(7);
tampil_celcius();
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, LOW);
delay(7);
}
void showDigit( int number)
{
boolean isBitSet;
for(int segment = 1; segment < 8; segment++)
{
if( number < 0 || number > 9){
isBitSet = 0;
}
else{
isBitSet = bitRead(numeral[number], segment);
}
isBitSet = ! isBitSet;
digitalWrite( segmentPins[segment], isBitSet);
}
}
void baca_sensor()
{
data_sensor=analogRead(sensor);
data_suhu=float(data_sensor)*433/1023;
}
void tampil_adc()
{
baca_sensor();
showDigit(data_sensor/1000);
digitalWrite(digit1, LOW);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
delay(3);
showDigit((data_sensor%1000)/100);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, LOW);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
delay(3);
showDigit((data_sensor%100)/10);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
digitalWrite(digit4, HIGH);
delay(3);
showDigit(data_sensor%10);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, LOW);
delay(3);
}
void tampil_derajat()
{
digitalWrite(segmentPins[1],LOW);
digitalWrite(segmentPins[2],LOW);
digitalWrite(segmentPins[3],HIGH);
digitalWrite(segmentPins[4],HIGH);
digitalWrite(segmentPins[5],HIGH);
digitalWrite(segmentPins[6],LOW);
digitalWrite(segmentPins[7],LOW);
digitalWrite(segmentPins[8],LOW);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
digitalWrite(digit4, HIGH);
}
void tampil_celcius()
{
digitalWrite(segmentPins[0],HIGH);
digitalWrite(segmentPins[1],HIGH);
digitalWrite(segmentPins[2],LOW);
digitalWrite(segmentPins[3],LOW);
digitalWrite(segmentPins[4],LOW);
digitalWrite(segmentPins[5],HIGH);
digitalWrite(segmentPins[6],HIGH);
digitalWrite(segmentPins[7],LOW);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, LOW);
}
const int digit2=10;
const int digit3=11;
const int digit4=12;
const int indikator=13;
const int sensor = A0;
int angka=0;
int data_sensor=0;
int data_suhu=0;
const byte numeral[10] = {
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11110110, // 9
};
const int segmentPins[8] = { 9,8,7,6,5,4,3,2};
void setup()
{
for(int i=0; i < 8; i++)
{
pinMode(segmentPins[i], OUTPUT);
}
pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
pinMode(digit3, OUTPUT);
pinMode(digit4, OUTPUT);
pinMode(indikator, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(data_suhu>30)
{
digitalWrite(indikator, HIGH);
}
else
{
digitalWrite(indikator,LOW);
}
Serial.println(data_suhu);
delay(1);
baca_sensor();
showDigit(data_suhu/10);
digitalWrite(digit1, LOW);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
delay(7);
showDigit(data_suhu%10);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, LOW);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
delay(7);
tampil_derajat();
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
digitalWrite(digit4, HIGH);
delay(7);
tampil_celcius();
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, LOW);
delay(7);
}
void showDigit( int number)
{
boolean isBitSet;
for(int segment = 1; segment < 8; segment++)
{
if( number < 0 || number > 9){
isBitSet = 0;
}
else{
isBitSet = bitRead(numeral[number], segment);
}
isBitSet = ! isBitSet;
digitalWrite( segmentPins[segment], isBitSet);
}
}
void baca_sensor()
{
data_sensor=analogRead(sensor);
data_suhu=float(data_sensor)*433/1023;
}
void tampil_adc()
{
baca_sensor();
showDigit(data_sensor/1000);
digitalWrite(digit1, LOW);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
delay(3);
showDigit((data_sensor%1000)/100);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, LOW);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
delay(3);
showDigit((data_sensor%100)/10);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
digitalWrite(digit4, HIGH);
delay(3);
showDigit(data_sensor%10);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, LOW);
delay(3);
}
void tampil_derajat()
{
digitalWrite(segmentPins[1],LOW);
digitalWrite(segmentPins[2],LOW);
digitalWrite(segmentPins[3],HIGH);
digitalWrite(segmentPins[4],HIGH);
digitalWrite(segmentPins[5],HIGH);
digitalWrite(segmentPins[6],LOW);
digitalWrite(segmentPins[7],LOW);
digitalWrite(segmentPins[8],LOW);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
digitalWrite(digit4, HIGH);
}
void tampil_celcius()
{
digitalWrite(segmentPins[0],HIGH);
digitalWrite(segmentPins[1],HIGH);
digitalWrite(segmentPins[2],LOW);
digitalWrite(segmentPins[3],LOW);
digitalWrite(segmentPins[4],LOW);
digitalWrite(segmentPins[5],HIGH);
digitalWrite(segmentPins[6],HIGH);
digitalWrite(segmentPins[7],LOW);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, LOW);
}
Hasil setelah program di upload ke PASID_UNO,,,
No comments:
Post a Comment