Task26 - 3071976 - Muhammad Nurcholish PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Tanggal : 04 Oktober 2022

Nama Lengkap : Muhammad Nurcholish


Asal Universitas : Politeknik Negeri Jember
NIM : H43201360
Asal Kelas : Blynk

Praktikum Proyek Serial Monitor, Sensor Cahaya, Suhu Kelembapan, dan


Jarak

1. Screenshot Full Screen dan foto Hasil Praktikum Pembacaan “Sensor


Cahaya dengan Serial Monitor”
➢ Program
int LDR = A0;

void setup() {
Serial.begin(115200); // Buka komunikasi serial pada baudrate
115200
pinMode (LDR, INPUT);
}
void loop() {
int sensorValue = analogRead(LDR);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.print("Analog = ");
Serial.println(sensorValue);
Serial.print("Tegangan = ");
Serial.print(voltage);
Serial.println(" V");
delay(1000);
}
➢ Hasil Percobaan

1
2. Screenshot Full Screen dan foto Hasil Praktikum Pembacaan “Sensor
DHT11 dengan Serial Monitor”
➢ Program
#include "DHT.h"

#define DHTPIN D2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));

dht.begin();
}

void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}

float hif = dht.computeHeatIndex(f, h);


float hic = dht.computeHeatIndex(t, h, false);

Serial.print(F("Humidity: "));
Serial.print(h);
Serial.println(F("% "));
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(F("°C "));
}

2
➢ Hasil Percobaan

3. Screenshot Full Screen dan foto Hasil Praktikum Pembacaan “Sensor


Ultrasonic dengan Serial Monitor”

➢ Program
#define triggerPin D7
#define echoPin D8

void setup() {
Serial.begin (115200);
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration, jarak;
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
duration = pulseIn(echoPin, HIGH);
jarak = (duration/2) / 29.1;
Serial.print("jarak :");
Serial.print(jarak);
Serial.println(" cm");
delay(500);
}

3
➢ Hasil percobaan

4
Challenge yang Harus Dikerjakan :
1. Membuat LED menyala ketika kondisi gelap dan mati ketika kondisi terang
menggunakan sensor LDR
➢ Program
int ldr = A0;
int led = D2;

void setup() {
Serial.begin(115200); // Buka komunikasi serial pada baudrate
115200
pinMode (ldr, INPUT);
pinMode (led, OUTPUT);
}
void loop() {
int sensorValue = analogRead(ldr);
float voltage = sensorValue * (5.0 / 1023.0);
if (sensorValue > 300) {
digitalWrite(led, HIGH);
Serial.println("Led On");
}
if (sensorValue <= 300) {
digitalWrite(led, LOW);
Serial.println("Led Off");
}

Serial.print("Analog = ");
Serial.println(sensorValue);
Serial.print("Tegangan = ");
Serial.print(voltage);
Serial.println(" V");
delay(1000);
}
➢ Hasil percobaan

5
2. Relay otomatis mati ketika suhu diatas 50, dan ketika suhu di bawah 50
maka relay menyala dengan bantuan sensor DHT11
➢ Program
#include "DHT.h"

#define DHTPIN D2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

#define relay D3

void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
pinMode (relay,OUTPUT);

dht.begin();
}

void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}

float hif = dht.computeHeatIndex(f, h);


float hic = dht.computeHeatIndex(t, h, false);

Serial.print(F("Humidity: "));
Serial.print(h);
Serial.println(F("% "));
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(F("°C "));
if (t > 50){
digitalWrite(relay,LOW);
Serial.println("Relay OFF");
}
if (t <= 50){
digitalWrite(relay,HIGH);
Serial.println("Relay ON");

6
}
}
➢ Hasil Percobaan

3. Apabila sensor jarak lebih dari 15 cm maka LED akan menyala, jika
sensor jarak bernilai kurang dari 15 cm maka LED akan mati
➢ Program
#define led D2
#define triggerPin D7
#define echoPin D8

void setup() {
Serial.begin (115200);
pinMode(led, OUTPUT);
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration, jarak;
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
duration = pulseIn(echoPin, HIGH);
jarak = (duration/2) / 29.1;
Serial.print("jarak :");
Serial.print(jarak);
Serial.println(" cm");
if (jarak > 15) {
digitalWrite(led, HIGH);
Serial.println("Led On");
}
if (jarak <= 15) {

7
digitalWrite(led, LOW);
Serial.println("Led Off");
}

delay(500);

}
➢ Hasil Percobaan

You might also like