You are on page 1of 3

#include <OneWire.

h>
#include <DallasTemperature.h>
const int oneWireBus = D7;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
float temperatureC;
float suhu_air=23;
///wifi
#include <ESP8266WiFi.h>
//cayenne
//#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
//char ssid[] = "gurulistrik";
//char wifiPassword[] = "september21";
char ssid[] = "GAME LAB MULTIMEDIA";
char wifiPassword[] = "multimedia2021";

#define VIRTUAL_CHANNEL1 1
#define VIRTUAL_CHANNEL5 5
#define VIRTUAL_CHANNEL6 6
#define ACTUATOR_PIN4 D3
#define ACTUATOR_PIN5 D4
// Do not use digital pins 0 or 1 since those conflict with the use of Serial.
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "a23ce820-17db-11ec-8da3-474359af83d7";
char password[] = "e46a9e042af48189d6babdc74bd9f20426bc3416";
char clientID[] = "677cd7a0-17e4-11ec-ad90-75ec5e25c7a4";

void setup() {
//Serial.begin(9600);
sensors.begin();
pinMode(ACTUATOR_PIN4, OUTPUT);
pinMode(ACTUATOR_PIN5, OUTPUT);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
//Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}

void loop() {

tampil();
Cayenne.loop();
sensuh();
}

//cayenne
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds
on virtual channel 0.
//ayenne.virtualWrite(0, millis());
;
Cayenne.celsiusWrite(VIRTUAL_CHANNEL1, temperatureC);

CAYENNE_IN(VIRTUAL_CHANNEL5)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as
normally open.

if (getValue.asInt() == 1) {
digitalWrite(ACTUATOR_PIN4, LOW);

}
else {
digitalWrite(ACTUATOR_PIN4, HIGH);
}

CAYENNE_IN(VIRTUAL_CHANNEL6)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as
normally open.
if (getValue.asInt() == 1) {
digitalWrite(ACTUATOR_PIN5, LOW);

}
else {
digitalWrite(ACTUATOR_PIN5, HIGH);
}

void tampil(){

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(18, 1);
display.println("aQua Scape THP");
display.setCursor(10, 10);
display.println("Suhu Air:");
display.setCursor(64,10);
display.println(temperatureC);
display.drawCircle(104,10,2, WHITE);
display.setCursor(108,10);
display.println("C");
display.setCursor(30,24);
display.println("by SMKTHPT");
display.display();
}

void sensuh() {
sensors.requestTemperatures();
temperatureC = sensors.getTempCByIndex(0);
//Serial.print(temperatureC);
//Serial.println("ºC");
// drawFontFaceDemo();
//delay(100);
delay(100);
}

You might also like