Skip to content

Commit c93b7ef

Browse files
authored
Add files via upload
1 parent 8ad2c9a commit c93b7ef

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <DHT.h>
2+
#define DHTPIN 2 // what digital pin we're connected to
3+
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
4+
DHT dht(DHTPIN, DHTTYPE);
5+
void setup() {
6+
Serial.begin(9600);
7+
Serial.println("DHTxx Robojax test!");
8+
dht.begin();
9+
}
10+
void loop() {
11+
// Wait a few seconds between measurements.
12+
delay(2000);
13+
// Robojax.com test video
14+
Serial.print("Temperature: ");
15+
16+
Serial.print(getTemp("c"));
17+
18+
Serial.print(" *C ");
19+
Serial.print(getTemp("f"));
20+
Serial.println (" *F");
21+
Serial.println("-----------------");
22+
Serial.print("Heat index: ");
23+
Serial.print(getTemp("hic"));
24+
Serial.print(" *C ");
25+
Serial.print(getTemp("hif"));
26+
Serial.println(" *F");
27+
Serial.print(getTemp("k"));
28+
Serial.println(" *K");
29+
Serial.println("-----------------");
30+
Serial.print("Humidity: ");
31+
Serial.print(getTemp("h"));
32+
Serial.println(" % ");
33+
Serial.println("===========================");
34+
}
35+
36+
float getTemp(String req)
37+
{
38+
// Reading temperature or humidity takes about 250 milliseconds!
39+
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
40+
float h = dht.readHumidity();
41+
// Read temperature as Celsius (the default)
42+
float t = dht.readTemperature();
43+
// Read temperature as Fahrenheit (isFahrenheit = true)
44+
float f = dht.readTemperature(true);
45+
// Compute heat index in Fahrenheit (the default)
46+
float hif = dht.computeHeatIndex(f, h);
47+
// Compute heat index in Celsius (isFahreheit = false)
48+
float hic = dht.computeHeatIndex(t, h, false);
49+
// Check if any reads failed and exit early (to try again).
50+
if (isnan(h) || isnan(t) || isnan(f)) {
51+
Serial.println("Failed to read from DHT sensor!");
52+
return;
53+
}
54+
// Compute heat index in Kelvin
55+
float k = t + 273.15;
56+
if(req =="c"){
57+
return t;//return Cilsus
58+
}else if(req =="f"){
59+
return f;// return Fahrenheit
60+
}else if(req =="h"){
61+
return h;// return humidity
62+
}else if(req =="hif"){
63+
return hif;// return heat index in Fahrenheit
64+
}else if(req =="hic"){
65+
return hic;// return heat index in Cilsus
66+
}else if(req =="k"){
67+
return k;// return temprature in Kelvin
68+
}else{
69+
return 0.000;// if no reqest found, retun 0.000
70+
}
71+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//program sensor suhu LM35
2+
int analogPin = A0;
3+
//Variabel untuk menyimpan data suhu
4+
5+
float suhu = 00;
6+
int suhu1=00;
7+
void setup(){
8+
//Komunikasi serial dengan baud 9600
9+
Serial.begin(9600);
10+
}
11+
12+
void loop(){
13+
//Baca pin input
14+
suhu1 = analogRead(analogPin);
15+
//1'C = 10mV (sesuai datasheet) // 5v /1023 = 4,883 mV (5v = tegangan refrensi, 1023 = resolusi 10 bit)
16+
// setiap kenaikan 1'C --> 10 / 4.883 = 2.0479
17+
//sehingga didapat rumus
18+
suhu = suhu1 / 2.0479;
19+
//hasil pembacaan akan ditampilkan di serial monitor
20+
Serial.println(suhu);
21+
delay(100);
22+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <LiquidCrystal_I2C.h>
2+
#include "DHT.h"
3+
#define DHTPIN 2 // what digital pin we're connected to
4+
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
5+
LiquidCrystal_I2C lcd(0x27, 16, 2);
6+
DHT dht(DHTPIN, DHTTYPE);
7+
void setup() {
8+
lcd.init();
9+
lcd.backlight();
10+
dht.begin();
11+
lcd.print("Suhu & Kelembaban"); //Greeting
12+
delay(2000);
13+
lcd.clear();
14+
}
15+
void loop() {
16+
delay(2000);
17+
lcd.clear();
18+
lcd.print("Suhu ");
19+
lcd.print(getTemp("c"));
20+
lcd.print("C");
21+
lcd.setCursor(0,1);
22+
lcd.print("Kelembaban ");
23+
24+
lcd.print(getTemp("h"));
25+
lcd.print(" %");
26+
//lcd.setCursor(0,3);
27+
//lcd.print("Baris Ke 3");
28+
delay(2000);
29+
}
30+
float getTemp(String req)
31+
{
32+
// Reading temperature or humidity takes about 250 milliseconds!
33+
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
34+
float h = dht.readHumidity();
35+
// Read temperature as Celsius (the default)
36+
float t = dht.readTemperature();
37+
// Read temperature as Fahrenheit (isFahrenheit = true)
38+
float f = dht.readTemperature(true);
39+
// Compute heat index in Fahrenheit (the default)
40+
float hif = dht.computeHeatIndex(f, h);
41+
// Compute heat index in Celsius (isFahreheit = false)
42+
float hic = dht.computeHeatIndex(t, h, false);
43+
// Check if any reads failed and exit early (to try again).
44+
if (isnan(h) || isnan(t) || isnan(f)) {
45+
//Serial.println("Failed to read from DHT sensor!");
46+
return;
47+
}
48+
// Compute heat index in Kelvin
49+
float k = t + 273.15;
50+
if(req =="c"){
51+
return t;//return Cilsus
52+
}else if(req =="f"){
53+
return f;// return Fahrenheit
54+
}else if(req =="h"){
55+
return h;// return humidity
56+
}else if(req =="hif"){
57+
return hif;// return heat index in Fahrenheit
58+
}else if(req =="hic"){
59+
return hic;// return heat index in Cilsus
60+
}else if(req =="k"){
61+
return k;// return temprature in Kelvin
62+
}else{
63+
return 0.000;// if no reqest found, retun 0.000
64+
}
65+
}

0 commit comments

Comments
 (0)