You are on page 1of 4

PERCOBAAN 04: Input Output Analog

4.1 Dasar Program Input Analog


A. Komponen Yang digunakan :
1. Modul Arduino
2. Potensiometer 10K Ohm
3. Resistor 220 Ohm
4. Kabel jumper
5. Protoboard

B. Langkah kerja :
1. Buat rangkaian sebagai berikut menggunakan protoboard

Gambar 4.1 Rangkaian Input Analog

MIKROPOSESOR DAN ANTARMUKA| Modul 04: ADC

2. Buat program baru sebagai berikut:

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13;
// select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

3. Lihat nyala LED pin 13.


4. Putar-putar potensio, lihat perubahan nyala LED yang terjadi.

C. Tugas
Edit program contoh agar perubahan LED berkebalikan dengan contoh.

4.2 Input Analog ditampilkan di LCD


A. Langkah kerja :
1. Tambahkan rangkaian skema LCD berikut ke rangkaian pada Gambar 4.1

MIKROPOSESOR DAN ANTARMUKA| Modul 04: ADC

2.
Gambar 4.2 Rangkaian LCD

3. Buat program sebagai berikut


#include <LiquidCrystal.h>
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13;
// select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("Analog Input:");
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
lcd.setCursor(0,1);
lcd.print("
");
delay(5);
lcd.setCursor(0,1);

MIKROPOSESOR DAN ANTARMUKA| Modul 04: ADC

lcd.print(sensorValue);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

4. Compile dan upload program, lihat hasil yang terjadi pada LCD.

B. Tugas
1. Buat program untuk menampilkan hasil input analog dan nilai pengolahan dengan rumus
sebagai berikut :
Y = 0 jika x < 100;
Y = 0.5x jika 100 <= x <=500;
Y = 250 jika x > 500

Tampilan pada display :

Baris atas: nilai adc = x


Baris bawah: nilai olah = y

MIKROPOSESOR DAN ANTARMUKA| Modul 04: ADC

You might also like