Sei sulla pagina 1di 6

BERHASIL!

#include <SoftwareSerial.h>

SoftwareSerial ESPserial(2,3);

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

ESPserial.begin(115200);

Serial.println("Ready");

void loop() {

// put your main code here, to run repeatedly:

if(Serial.available()>0){

byte b = Serial.read();

ESPserial.write(b);

if(ESPserial.available()>0){

byte b = ESPserial.read();

Serial.write(b);

}
Tes suhu

// esp8266_test.ino

//

// Plot LM35 data on thingspeak.com using an Arduino and an ESP8266 WiFi

// module.

//

// Author: Mahesh Venkitachalam

// Website: electronut.in

#include <SoftwareSerial.h>

#include <stdlib.h>

// LED

int ledPin = 13;

// LM35 analog input

int lm35Pin = A0;

int tempC;

// replace with your channel's thingspeak API key

String apiKey = "B90REI1QSQHXMFKR";

// connect 10 to TX of Serial USB

// connect 11 to RX of serial USB

SoftwareSerial ser(2, 3); // RX, TX

// this runs once

void setup() {

// initialize the digital pin as an output.

pinMode(ledPin, OUTPUT);

// enable debug serial

Serial.begin(9600);
// enable software serial

ser.begin(115200);

// reset ESP8266

ser.println("AT+RST");

// the loop

void loop() {

//PROGRAM OFFLINE

// blink LED on board

digitalWrite(ledPin, HIGH);

delay(200);

digitalWrite(ledPin, LOW);

// read the value from LM35.

// read 10 values for averaging.

int val = 0;

for(int i = 0; i < 10; i++) {

val += analogRead(lm35Pin);

delay(500);

// convert to temp:

// temp value is in 0-1023 range

// LM35 outputs 10mV/degree C. ie, 1 Volt => 100 degrees C

// So Temp = (avg_val/1023)*5 Volts * 100 degrees/Volt

float temp = val*50.0f/1023.0f;


//int temp = val*50/1023;

// convert to string

char buf[16];

String strTemp = dtostrf(temp, 4, 1, buf);

Serial.println(strTemp);

// TCP connection

String cmd = "AT+CIPSTART=\"TCP\",\"";

cmd += "184.106.153.149"; // api.thingspeak.com

cmd += "\",80";

ser.println(cmd);

if(ser.find("Error")){

Serial.println("AT+CIPSTART error");

return;

// prepare GET string

String getStr = "GET /update?api_key=";

getStr += apiKey;

getStr +="&field1=";

getStr += String(strTemp);

getStr += "\r\n\r\n";

// send data length

cmd = "AT+CIPSEND=";

cmd += String(getStr.length());

ser.println(cmd);

if(ser.find(">")){
ser.print(getStr);

else{

ser.println("AT+CIPCLOSE");

// alert user

Serial.println("AT+CIPCLOSE");

// thingspeak needs 15 sec delay between updates

delay(1000);

MONITORING SUHU

import processing.serial.*; //Import library serial

Serial port; //Buat serial objek bernama "port"

String suhu_celcius = ""; //Variable untuk suhu Celcius

String suhu_fahrenheit = ""; //Variable untuk suhu Fahrenheit

String data = "";

int index = 0;

PFont font;

void setup()

size(400,400); //Buat objek 400x400 pixel

port = new Serial(this, "COM10", 9600); //Sesuaikan "COM3"

port.bufferUntil('.');

font = loadFont("LucidaBright-15.vlw"); //Load font

textFont(font, 200); //Jadikan size font 200

}
void draw()

background(0,0,0); //Jadikan background hitam

fill(46, 209, 2); //Warna text suhu celcius dalam (R,G,B)

text(suhu_celcius, 70, 175); //Koordinat text suhu celcius

fill(0, 102, 153); //Warna text suhu fahrenheit dalam (R,G,B)

text(suhu_fahrenheit, 70, 370); //Koordinat text suhu fahrenheit

void serialEvent (Serial port)

//Ambil seluruh string dari serial

data = port.readStringUntil('.');

//Hapus periode akhir dari data string

data = data.substring(0, data.length() - 1);

//Mencari koma antara celcius dan fahrenheit

index = data.indexOf(",");

//Mendapatkan suhu celcius

suhu_celcius = data.substring(0, index);

//Mendapatkan suhu fahrenheit

suhu_fahrenheit = data.substring(index+1, data.length());

Potrebbero piacerti anche