0% found this document useful (0 votes)
6 views5 pages

Laporan Projek Interfasing-Dan Panji GI

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)
6 views5 pages

Laporan Projek Interfasing-Dan Panji GI

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/ 5

LAPORAN PROJEK INTERFASING

Nama : Dan Panji Gumilang Indradewa


Kelas : TL2B
NIM : 220104031

PROGRAM STUDI DIPLOMA TIGA TEKNIK LISTRIK


JURUSAN REKAYASA ELEKTRO DAN MEKATRONIKA
POLITEKNIK NEGERI CILACAP
2024
PERCOBAAN MENGGUNAKAN
THINGSPEAK

1. Langkah percobaan
a. Buatlah channel pada thingspeak
b. Buatlah 3 field
c. Salin id channel dan API KEYS
d. Buat program di WOKWI
e. Mulai simulasi
f. Pada monitor thingspeak akan muncul grafik
2. Skema k rangkaian

3. Program
Sketch.ino
#include <WiFi.h>
#include "secrets.h"
#include "ThingSpeak.h" // always include thingspeak header file a er other header files and
custom macros
#include "DHTesp.h"

const int DHT_PIN = 15;


DHTesp dhtSensor;

char ssid[] = SECRET_SSID; // your network SSID (name)


char pass[] = SECRET_PASS; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

const float GAMMA = 0.7;


const float RL10 = 50;
// Ini alize our values

int number1 = 0;
int number2 = random(0,100);
int number3 = random(0,100);
int number4 = random(0,100);
String myStatus = "";

void setup() {
Serial.begin(115200); //Ini alize serial
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo na ve USB port only
}
dhtSensor.setup(DHT_PIN,DHTesp::DHT22);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Ini alize ThingSpeak
}

void loop() {

// Connect or reconnect to WiFi


if(WiFi.status() != WL_CONNECTED){
Serial.print("A emp ng to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open
or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
int analogValue = analogRead(35);
float voltage = analogValue*5/4095.0;
float resistance = 2000*voltage/(1-voltage/5);
float lux = pow(RL10*1e3*pow(10,GAMMA)/resistance, (1/GAMMA));
Serial.print("Lux :");
Serial.println(lux);
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("temp: "+String(data.temperature,2)+"C");
Serial.println("humidity: "+String(data.humidity,1)+ "%");
Serial.println("---");
// set the fields with the values
ThingSpeak.setField(1, data.temperature);
ThingSpeak.setField(2, data.humidity);
ThingSpeak.setField(3, lux);
ThingSpeak.setField(4, number4);

// figure out the status message

// set the status


ThingSpeak.setStatus(myStatus);

// write to the ThingSpeak channel


int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem upda ng channel. HTTP error code " + String(x));
}

// change the values


number1++;
if(number1 > 99){
number1 = 0;
}
number1 = data.temperature;
number2 = data.humidity;
number3 = lux;
number4 = 0;

delay(20000); // Wait 20 seconds to update the channel again


}

Secrets.h
#define SECRET_SSID "Wokwi-GUEST" // replace MySSID with your WiFi network name
#define SECRET_PASS "" // replace MyPassword with your WiFi password

#define SECRET_CH_ID 2593011 // replace 0000000 with your channel number


#define SECRET_WRITE_APIKEY "RMJDF8UXIDJ1P5NB" // replace XYZ with your channel
write API Key
4. Hasil dan pembahasan

Nilai grafik pada thingspeak muncul sesuai dengan simulasi pada wokwi.

5. Kesimpulan
Thingspeak berguna untuk mendaapatkan data dari sensor dengan menggunakan
internet yang memudahkan memonitoring suatu kondisi.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy