0% found this document useful (0 votes)
30 views13 pages

Lapres 6

This document describes two experiments monitoring light intensity with an Arduino and Processing. The first experiment uses an LDR and photodiode to read light intensity values, which are displayed in Processing. The second experiment uses an LDR and piezo buzzer, where the buzzer tone duration depends on the LDR reading. Both experiments transmit sensor readings from Arduino to Processing for visualization.

Uploaded by

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

Lapres 6

This document describes two experiments monitoring light intensity with an Arduino and Processing. The first experiment uses an LDR and photodiode to read light intensity values, which are displayed in Processing. The second experiment uses an LDR and piezo buzzer, where the buzzer tone duration depends on the LDR reading. Both experiments transmit sensor readings from Arduino to Processing for visualization.

Uploaded by

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

Nama Anggota : Dicky Ihza Permana P.

/ 1210191045

Pradono Kristio Putro / 1210191053

Moch. Raditya A.A. / 1210191059

Kelas : 3 D4 TB

Mata Kuliah / Dosen : Praktikum Mikroprosesor dan Antarmuka 2 / Moh. Ridwan

Tanggal : Senin, 04 Oktober 2021

PRAKTIKUM 6

MONITORING INTENSITAS CAHAYA DENGAN ARDUINO DAN PROCESSING

A. Percobaan

1. Percobaan 1 (Dengan LDR)

a. Rangkaian

b. Listing Code Arduino

int sensorPin = A2;


int ledPins=13;
int val = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPins,OUTPUT);
}
void loop() {
val = analogRead(sensorPin);
Serial.println(val);
digitalWrite(ledPins, HIGH);
delay(300);
digitalWrite(ledPins, LOW);
delay(300);
}

c. Listing Code Processing

import processing.serial.*;
Serial portSerial;
int dataSekarang;
int inByte;
int[] nilaiY;
int w;
void setup(){
size (700,400);
w = width-10;
strokeWeight(3);
smooth();
nilaiY = new int[w];
//sesuikan dengan nomer COM
portSerial = new Serial(this, "COM4", 9600);
}
void draw(){
String inString = portSerial.readStringUntil('\n');
if(inString != null){
inString = trim(inString);
inByte = int(inString);
println(inByte);
dataSekarang = int(map(inByte, 0, 1023, 0+10,
height-50));
dataSekarang = height-dataSekarang;
background(0);
for(int i = 1; i < w; i++) {
nilaiY[i-1] = nilaiY[i];
}
nilaiY[w-1] = dataSekarang;
textSize(32);
text(inByte, 10, 30);
stroke(255);
line(w, dataSekarang, width, dataSekarang);
strokeWeight(1);
line(0, dataSekarang, width, dataSekarang);
strokeWeight(3);
for(int i=2; i<w; i++) {
strokeWeight(3);
stroke(220, 10, nilaiY[i]);
line(i, nilaiY[i-1], i, nilaiY[i]);
}
}
}

d. Output

- Nilai LDR 3.1


- Nilai LDR 1.1
Percobaan 1 (Dengan Photodiode)

a. Rangkaian

b. Listing Code Arduino

int sensorPin = A2;


int ledPins=13;
int val = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPins,OUTPUT);
}
void loop() {
val = analogRead(sensorPin);
Serial.println(val);
digitalWrite(ledPins, HIGH);
delay(300);
digitalWrite(ledPins, LOW);
delay(300);
}

c. Listing Code Processing

import processing.serial.*;
Serial portSerial;
int dataSekarang;
int inByte;
int[] nilaiY;
int w;
void setup(){
size (700,400);
w = width-10;
strokeWeight(3);
smooth();
nilaiY = new int[w];
//sesuikan dengan nomer COM
portSerial = new Serial(this, "COM4", 9600);
}
void draw(){
String inString = portSerial.readStringUntil('\n');
if(inString != null){
inString = trim(inString);
inByte = int(inString);
println(inByte);
dataSekarang = int(map(inByte, 0, 1023, 0+10,
height-50));
dataSekarang = height-dataSekarang;
background(0);
for(int i = 1; i < w; i++) {
nilaiY[i-1] = nilaiY[i];
}
nilaiY[w-1] = dataSekarang;
textSize(32);
text(inByte, 10, 30);
stroke(255);
line(w, dataSekarang, width, dataSekarang);
strokeWeight(1);
line(0, dataSekarang, width, dataSekarang);
strokeWeight(3);
for(int i=2; i<w; i++) {
strokeWeight(3);
stroke(220, 10, nilaiY[i]);
line(i, nilaiY[i-1], i, nilaiY[i]);
}
}
}

d. Output
2. Percobaan 2 (Dengan LDR)

a. Rangkaian

b. Listing Code Arduino

int piezoPin = 7;
int ldrPin = A2;
int ldrValue = 0;
void setup() {
Serial.begin(9600);
} void loop() {
ldrValue = analogRead(ldrPin);
tone(piezoPin,500);
delay(25);
noTone(piezoPin);
delay(ldrValue);
Serial.println(ldrValue);
}
c. Listing Code Processing

import processing.serial.*;
Serial port;
float val;
int x;
float easing = 0.05;
float easedVal;
void setup() {
size(440, 440);
frameRate(30);
smooth();
String arduinoPort = Serial.list()[0];
port = new Serial(this, arduinoPort, 9600);
background(0); }
void draw() {
if ( port.available() > 0) {
val = port.read();
val = map(val, 0, 255, 0, height);
} float targetVal = val; easedVal += (targetVal -
easedVal) * easing;
stroke(0);
line(x, 0, x, height);
stroke(255);
line(x+1, 0, x+1, height);
line(x, 220, x, val);
line(x, 440, x, easedVal + 220);
x++;
if (x > width) {
x = 0;
}
}
d. Output
Percobaan 2 (Dengan Photodiode)

a. Rangkaian

b. Listing Code Arduino

int piezoPin = 7;
int ldrPin = A2;
int ldrValue = 0;
void setup() {
Serial.begin(9600);
} void loop() {
ldrValue = analogRead(ldrPin);
tone(piezoPin,500);
delay(25);
noTone(piezoPin);
delay(ldrValue);
Serial.println(ldrValue);
}
c. Listing Code Processing

d.

import processing.serial.*;
Serial port;
float val;
int x;
float easing = 0.05;
float easedVal;
void setup() {
size(440, 440);
frameRate(30);
smooth();
String arduinoPort = Serial.list()[0];
port = new Serial(this, arduinoPort, 9600);
background(0); }
void draw() {
if ( port.available() > 0) {
val = port.read();
val = map(val, 0, 255, 0, height);
} float targetVal = val; easedVal += (targetVal -
easedVal) * easing;
stroke(0);
line(x, 0, x, height);
stroke(255);
line(x+1, 0, x+1, height);
line(x, 220, x, val);
line(x, 440, x, easedVal + 220);
x++;
if (x > width) {
x = 0;
}
}
e. Output

You might also like