0% found this document useful (0 votes)
23 views8 pages

Listing Program M4 Mikro

This document contains code for four Arduino projects: 1. Displaying LM35 temperature sensor readings on 7-segment displays and LCD. 2. Displaying ultrasonic sensor distance readings on 7-segment displays and LCD. 3. Testing all LEDs on an 8x8 LED matrix using shift registers. 4. Controlling DC motor speed based on LM35 temperature sensor readings displayed on LCD.

Uploaded by

Ilham F Fajri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views8 pages

Listing Program M4 Mikro

This document contains code for four Arduino projects: 1. Displaying LM35 temperature sensor readings on 7-segment displays and LCD. 2. Displaying ultrasonic sensor distance readings on 7-segment displays and LCD. 3. Testing all LEDs on an 8x8 LED matrix using shift registers. 4. Controlling DC motor speed based on LM35 temperature sensor readings displayed on LCD.

Uploaded by

Ilham F Fajri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Listing Program

A. Menampilkan Pembacaan Input LM35 pada 7


Segment dan LCD
#include <LiquidCrystal.h>
#define LM35 A8
// RS E D4 D5 D6 D7 LiquidCrystal lcd(22 ,23 ,24 ,25 ,26 ,27); //
abcdefg
byte _7segmen[10][7]={{1 ,1 ,1 ,1 ,1 ,1 ,0}, // 0
{0 ,1 ,1 ,0 ,0 ,0 ,0}, // 1
{1 ,1 ,0 ,1 ,1 ,0 ,1}, // 2
{1 ,1 ,1 ,1 ,0 ,0 ,1}, // 3
{0, 1 ,1 ,0 ,0, 1 ,1}, // 4
{1, 0 ,1 ,1 ,0 ,1 ,1}, // 5
{1, 0 ,1 ,1 ,1 ,1 ,1}, // 6
{1 ,1 ,1 ,0 ,0 ,0 ,0}, // 7
{1 ,1 ,1 ,1 ,1 ,1 ,1}, // 8
{1 ,1 ,1 ,1 ,0 ,1 ,1}}; // 9
// a b c d e f g int pin7segmen[]={7 ,8 ,9 ,10 ,11 ,12 ,13};
// Puluhan Satuan int pinKontrol[]={ 6, 5};
int satuan, puluhan;
int nilaiSuhu;
void kode7segmen()
{
satuan=nilaiSuhu%10;
puluhan=nilaiSuhu/10;

puluhan=puluhan%10;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LM35 Sensor Suhu");
lcd.setCursor(7,1);
lcd.print(nilaiSuhu);
for (int i=0; i<30; i++)
{
for (int kolom=0; kolom<7; kolom++)
{
digitalWrite(pinKontrol[0],0);
digitalWrite(pinKontrol[1],1);
digitalWrite(pin7segmen[kolom],_7segmen[satuan]
[kolom]);
delay(1);
digitalWrite(pin7segmen[kolom],0);
}
delay(10); for (int kolom=0; kolom<7; kolom++)
{ digitalWrite(pinKontrol[0],1);
digitalWrite(pinKontrol[1],0);
digitalWrite(pin7segmen[kolom],_7segmen[puluha n][kolom]);
delay(1);
digitalWrite(pin7segmen[kolom],0);
}
delay(10);

}
void setup()
{
pinMode(LM35,INPUT);
for (int Kontrol=0; Kontrol<3; Kontrol++)
{
pinMode(pinKontrol[Kontrol],OUTPUT);
digitalWrite(pinKontrol[Kontrol],1);
}
for (int Kontrol=0; Kontrol<7; Kontrol++)
{ pinMode(pin7segmen[Kontrol],OUTPUT);
}
lcd.begin(16,2);
}
void loop()
{
nilaiSuhu=((5*analogRead(LM35)*100.00)/1024)- 76;
kode7segmen();
}

B. Menampilkan hasil input sensor ultrasonic PING pada


7 Segment dan LCD
#include <LiquidCrystal.h>
int pinPing= 53;

float duration, distance;


LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
pinMode(pinPing, OUTPUT);
digitalWrite(pinPing, LOW);
delayMicroseconds(2);
digitalWrite(pinPing, HIGH);
delayMicroseconds(5);
digitalWrite(pinPing, LOW);
pinMode(pinPing, INPUT);
duration = pulseIn(pinPing, HIGH);
distance=(duration/2)/29.1;
lcd.print(distance);
lcd.print("cm");
delay(500);
lcd.clear();
}

C. Shift Register pada Dot Matrik


// matriks - pengujian semua LED di matriks LED 8x8

// Baris-> 1 2 3 4 5 6 7 8 int baris[] = {-1, 6, 7, 8, 9, 10, 11, 12, 13};


// Kolom-> 1 2 3 4 5 6 7 8 int kolom[] = {-1, A0, A1, A2, A3, 2, 3, 4,
5};
void setup()
{
for (int indeks = 1; indeks <=8; indeks++)
{
pinMode(baris [indeks], OUTPUT);
pinMode(kolom [indeks], OUTPUT);
digitalWrite(baris[indeks], LOW);
digitalWrite(kolom[indeks], HIGH);
}}
void loop()
{
for (int i = 1; i <= 8; i++)
{
for (int j = 1; j <= 8; j++)
{ digitalWrite(kolom[j], HIGH);
digitalWrite(baris[i], HIGH);
delay(50);
digitalWrite(kolom[j], HIGH);
digitalWrite(baris[i], LOW);
}}
for (int i = 1; i <= 8; i++)
{

for (int j = 1; j <= 8; j++)


{
digitalWrite(kolom[j], LOW);
digitalWrite(baris[i], LOW);
delay(500);
digitalWrite(kolom[j], HIGH);
digitalWrite(baris[i], LOW);
}}}

D. Mengatur kecepatan Motor DC berdasarkan nilai


input LM35
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,10,9,8,7);
int m0=6;
int m1=5;
int m2=4;
int m3=3;
void setup()
{
lcd.begin(16, 2);
pinMode(A8,INPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
pinMode(3,OUTPUT);

}
void loop()
{
int sensorValue = analogRead(A8);
float suhu=((5*sensorValue*100.00)/1024)- 76;
lcd.clear();
lcd.print("suhu :");
lcd.setCursor(7,0);
lcd.print(suhu);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("PWM :");
lcd.setCursor(6,1);
lcd.print(sensorValue-61);
delay(500);
if(suhu>=15)
{
analogWrite(m0,sensorValue);
analogWrite(m1,0);
analogWrite(m2,sensorValue);
analogWrite(m3,0 );
}
else { analogWrite(m0,0);
analogWrite(m1,0);
analogWrite(m2,0);

analogWrite(m3,0);
}}

You might also like