ผมเขียนโค้ดแล้วค่า GAUGE ใน Blynk ไม่แสดงอะครับ ต้องปรับเป็น ADC0 ถึงจะแสดงแต่ก็แสดงเป็นค่า Analog ผมอยากให้แสดงค่าเป็น%อะครับผมต้องทำยังไงหรอครับ ผมใช้เป็นเซนเซอร์วัดความชื้นในดินอะครับ
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "C-wIdXfFJPm2QDp7vH1YMTwjHbKAcKiT";
char ssid[] = "Kanchanaaot2,4";
char pass[] = "637256338";
char server[] = "blynk-cloud.com";
const int analogInPin = A0;
const int relay = D1;
int port = 80;
int sensorValue = 0;
int outputValue = 0;
void moisture() {
int value = analogRead(A0);
value = map(value, 0, 1023, 0, 100);
Blynk.virtualWrite(V0, value);
Serial.println(value);
}
void setup()
{
Serial.begin(9600);
pinMode(analogInPin, INPUT);
pinMode(relay, OUTPUT);
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
}
void loop()
{
Blynk.run();
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 100, 0);
Serial.print("Soil Moisture = ");
Serial.print(outputValue);
Serial.println(" %");
if (outputValue > 60) {
digitalWrite(relay, HIGH);
}
else {
digitalWrite(relay, LOW);
}
delay(1000);
}
Remy_Martin
(Permpol Thanapunnamas)
3
นำค่าที่ได้ไป เข้าฟังก์ชัน map ครับ ตัวอย่าง
ตัวอย่างคำสั่งในการแปลง เราต้องรู้ค่าสูงสุด และต่ำสุดด้วย เพื่อนำมาแปลงในสเกล 100
int SoilSensorValue_1 = analogRead(SoilSensor_1);
int mapSoilSensorValue_1 = map(SoilSensorValue_1, 0, 4095, 100, 0);
ต้องใส่เพิ่มใช่มั้ยครับ แล้วในโค้ดต้องแก้ตรงไหนมั้ยครับ
Remy_Martin
(Permpol Thanapunnamas)
7
แล้วได้ค่าออกมาใน Serial เท่าไหร่
Remy_Martin
(Permpol Thanapunnamas)
9
ลองใช้โค้ตนี้แล้วดูว่าค่าก่อน map ได้เท่าไหร่
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "C-wIdXfFJPm2QDp7vH1YMTwjHbKAcKiT";
char ssid[] = "Kanchanaaot2,4";
char pass[] = "637256338";
char server[] = "blynk-cloud.com";
const int analogInPin = A0;
const int relay = D1;
int port = 80;
int sensorValue = 0;
int outputValue = 0;
void moisture() {
int value = analogRead(A0);
value = map(value, 0, 1023, 0, 100);
Blynk.virtualWrite(V0, value);
Serial.println(value);
}
void setup()
{
Serial.begin(9600);
pinMode(analogInPin, INPUT);
pinMode(relay, OUTPUT);
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
}
void loop()
{
Blynk.run();
sensorValue = analogRead(analogInPin);
Serial.print("sensorValue = ");
Serial.println(sensorValue);
outputValue = map(sensorValue, 0, 1023, 100, 0);
Serial.print("Soil Moisture = ");
Serial.print(outputValue);
Serial.println(" %");
if (outputValue > 60) {
digitalWrite(relay, HIGH);
}
else {
digitalWrite(relay, LOW);
}
delay(1000);
}
ดูจากตรงSerial เหมือนเดิมใช่มั้ยครับ
Remy_Martin
(Permpol Thanapunnamas)
12
สถานะเซนเซอร์เป็นยังไง ถ่ายมาดูหน่อย
Remy_Martin
(Permpol Thanapunnamas)
14
ลองจุ่มน้ำดูครับว่าค่ามันได้เท่าไหร่ เปลี่ยนแปลงหรือไม่
Remy_Martin
(Permpol Thanapunnamas)
16
แสดงว่าเรื่องการต่อ กับโปรแกรม โอเคละ ทีนี้เหลืออะไร?
อันนี้ในแอปครับ ผมยังไม่ได้ต่อพวกOUTPUT เกี่ยวมั้ยครับตัวRelayที่ต่อกับปั๊ม
Remy_Martin
(Permpol Thanapunnamas)
18
อ่อประเด็นคือเรามี ฟังก์ชัน ในการอ่านค่าเซ็นเซอร์อยู่แล้วแต่เราไม่ได้เอามาใช้อ่ะครับ มันเลยไม่อ่านค่า แล้วส่งไปที่ blynk
ต้องทำยังไงหรอครับ ลบตรงส่วนไหนออกครับ
Remy_Martin
(Permpol Thanapunnamas)
20
ก็เอามาใช้ครับ เอาชื่อฟังก์ชัน มาใส่ใน void loop การทำงาน
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "C-wIdXfFJPm2QDp7vH1YMTwjHbKAcKiT";
char ssid[] = "Kanchanaaot2,4";
char pass[] = "637256338";
char server[] = "blynk-cloud.com";
const int analogInPin = A0;
const int relay = D1;
int port = 80;
int sensorValue = 0;
int outputValue = 0;
void moisture() {
int value = analogRead(A0);
value = map(value, 0, 1023, 0, 100);
Blynk.virtualWrite(V0, value);
Serial.println(value);
}
void setup()
{
Serial.begin(9600);
pinMode(analogInPin, INPUT);
pinMode(relay, OUTPUT);
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
}
void loop()
{
Blynk.run();
sensorValue = analogRead(analogInPin);
Serial.print("sensorValue = ");
Serial.println(sensorValue);
outputValue = map(sensorValue, 0, 1023, 100, 0);
Serial.print("Soil Moisture = ");
Serial.print(outputValue);
Serial.println(" %");
moisture(); //ใช้งานการอ่านเซนเซอร์ แล้วส่งค่าไปที่ blynk
if (outputValue > 60) {
digitalWrite(relay, HIGH);
}
else {
digitalWrite(relay, LOW);
}
delay(1000);
}
ได้แล้วครับ ขอบคุณมากๆเลยครับ ดีใจมากกก