สอบถามครับ จะสั่งให้กดปุ่มที่ blynk แล้วอิงที่เซนเซอร์ เพื่อไปดับ ได้หรือไม่ครับ แบบว่า กดให้เติมน้ำให้เต็มถัง โดยมีเซนเซอร์ระดับน้ำวัดพอพึงระดับก็ให้ Off ไป ขอบคุณล่วงหน้าครับ
ทำได้ครับ ขึ้นอยู่ว่าใช่เซอเซออะไรวัด ถ้าเคสนี้ น่าจะเป็นลูกลอย น่าจะเหมาะกว่า
การรับค่า จากลูกลอยมาก็ง่ายๆ รับมาเป็น 0 หรือ 1 ถ้าระดับน้ำถึงเกณฑ์ ลูกลอย on ส่ง 1 มา เข้า input 1 Pin จาก บอร์ดที่เราใช้ เอามาเข้าเงื่อนไข
If( inputSw == high ){
digitalWrite(pin, LOW);
}
ตอนนี้ใช้เป็น non contact liquid ครับ พอมีวิธีเขียนแนะนำมั้ยครับ
if (digitalRead(pinInput) == 1) {
digitalWrite(5, LOW); // Relay off
}
}else{
digitalWrite(5, HIGH); //Relay on
}
ความหมายคือกด ปุ่มที่ แอพ 1 ครั้งแล้ว ให้มันเติมน้ำมันจนถึงระดับที่เซนเซอจับได้แล้วหยุด สินะครับ
ใช่แล้วครับยังหาวิธีแก้อยู่เลยครับ
ตอนนี้เขียนแบบไหนครับ
run บน arduino ได้ แต่บน esp ไม่ได้เลยครับ
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "cd75947463db4db6af4b36885be44263";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "elecFloor6";
char pass[] = "elec6";
BlynkTimer timer;
void setup()
{
pinMode(4, OUTPUT); //ตั้งค่าขา 4 เป็น output
pinMode(5, OUTPUT); //ตั้งค่าขา 5 เป็น output
Serial.begin(115200); // เริ่มตั้นการสื่อสารที่ 115200
Blynk.begin(auth, ssid, pass);
}
void water() {
if (digitalRead(32) == 1) {
Serial.println("ArduinoAll Water Detect");
}
else {
Serial.println("No Water");
}
Serial.print(digitalRead(32: ");
delay(500); // delay in between reads for stability
}
void loop()
{
Blynk.run();
water();
delay(500); //wait for half a second, so it is easier to read
if(digitalRead(32) == 1)
{
digitalWrite(5,HIGH);
Blynk.virtualWrite(V3,1);
}else{
digitalWrite(5,LOW);
Blynk.virtualWrite(V3,0);
}
}
เดะเย็นๆ ตอบให้นะครับ
ผมดูในมือถืออยู่
มีรูปเซนเซอร์ไหมครับ มันจับจากสีของน้ำ รึป่าว
ขอบคุณล่วงหน้านะครับ
ใช้ esp อะไรครับ 8266 หรือ 32
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
int Liquid_level=0;
char auth[] = "cd75947463db4db6af4b36885be44263";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "elecFloor6";
char pass[] = "elec6";
BlynkTimer timer;
void setup()
{
pinMode(5,INPUT);
Serial.begin(115200); // เริ่มตั้นการสื่อสารที่ 115200
Blynk.begin(auth, ssid, pass);
}
void water() {
Liquid_level=digitalRead(5);
Serial.print("Liquid_level= ");
Serial.println(Liquid_level,DEC);
delay(500);
}
void loop()
{
Blynk.run();
water();
delay(500);
}
โค้นนี้รันบน 32 แต่ยังหาวิธีสั่งการอยู่ครับ
ลองดูครับ
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
int Liquid_level=0;
char auth[] = "cd75947463db4db6af4b36885be44263";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "elecFloor6";
char pass[] = "elec6";
BlynkTimer timer;
bool Relay_On = false;
void setup()
{
pinMode(4,INPUT);
pinMode(5,OUTPUT);
Serial.begin(115200); // เริ่มตั้นการสื่อสารที่ 115200
Blynk.begin(auth, ssid, pass);
}
BLYNK_WRITE(V1) {
if (param.asInt()== 1) {
Relay_On = true;
} else{
Relay_On = false;
}
}
void water() {
Liquid_level=digitalRead(5);
Serial.print("Liquid_level= ");
Serial.println(Liquid_level,DEC);
delay(500);
}
void loop()
{
Blynk.run();
water();
delay(500);
if ((digitalRead(4) == 0) && (Relay_On == true) {
digitalWrite(5, HIGH); // Relay on
}
}else{
digitalWrite(5, LOW); //Relay off
Blynk.virtualWrite(V1,0); //ปิด ปุ่มหน้า app ให้เป็น off
}
}
ได้หรือไม่ได้ ติดปัญหาอะไร แจ้งหน่อยนะครับ
ตอนนี้แสดงแล้วครับแต่ติดที่มันจะสลับ on off ตลอดเลยครับ
// inicio BLYNK ***********************************************************
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <OneWire.h>
#include<DallasTemperature.h>
int Liquid_level=0;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "cd75947463db4db6af4b36885be44263";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "elecFloor6";
char pass[] = "elec6";
//fim BLYNK *************************************************************
//inicio sensor temperatura
/* DS18B20 Temperature Sensor */
//#include <OneWire.h>
//#include<DallasTemperature.h>
#define ONE_WIRE_BUS 15 // DS18B20 on arduino pin4 corresponds to GPI12 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
//fim sensor temperatura
float phData;
BlynkTimer timer;
bool Relay_On = false;
#define SensorPin 35 //pH meter Analog output to Arduino Analog Input 2
#define Offset 0.00 //deviation compensate
//#define LED 13
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth 40 //times of collection
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
int pHArrayIndex = 0;
void config_hm(){
static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
static float pHValue, voltage;
//Serial.println((analogRead(SensorPin)*0.00122)*1);
if (millis() - samplingTime > samplingInterval)
{
//Serial.println(pHArrayIndex);
pHArray[pHArrayIndex++] = analogRead(SensorPin);
if (pHArrayIndex == ArrayLenth)pHArrayIndex = 0;
voltage = avergearray(pHArray, ArrayLenth) *5.0/4096; // 0.0012 is 5.0V / 4096 When esp32 have adc 12 bits = 4096 vcc = 5v
pHValue = 3.5 * voltage + Offset;
samplingTime = millis();
}
if (millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
// Serial.print("Voltage:");
Serial.print(voltage, 2); Serial.print(" "); Serial.println(pHValue, 2);
phData = pHValue;
// Serial.print(" pH value: ");
//Serial.println(pHValue, 2);
// digitalWrite(LED, digitalRead(LED) ^ 1);
printTime = millis();
}
Blynk.virtualWrite(V35, pHValue);
}
double avergearray(int* arr, int number)
{
int i;
int max, min;
double avg;
long amount = 0;
if (number <= 0)
{
Serial.println("Error number for the array to avraging!/n");
return 0;
}
if (number < 5) //less than 5, calculated directly statistics
{
for (i = 0; i < number; i++)
{
amount += arr[i];
}
avg = amount / number;
return avg;
}
else
{
if (arr[0] < arr[1])
{
min = arr[0]; max = arr[1];
}
else
{
min = arr[1]; max = arr[0];
}
for (i = 2; i < number; i++)
{
if (arr[i] < min)
{
amount += min; //arr<min
min = arr[i];
}
else
{
if (arr[i] > max)
{
amount += max; //arr>max
max = arr[i];
}
else
{
amount += arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount / (number - 2);
}//if
return avg;
}
void water_value1() {
Liquid_level=digitalRead(5);
Serial.print("Liquid_level= ");
Serial.println(Liquid_level,DEC);
delay(500);
}
void setup() {
// put your setup code here, to run once:
// pinMode(LED,OUTPUT);
pinMode(4,INPUT);
pinMode(12,OUTPUT);
pinMode(5,INPUT);
pinMode(13,OUTPUT);
Serial.begin(115200);
Serial.println();
Serial.println();
//BLYNK
Blynk.begin(auth, ssid, pass);
//Inicializa SENSOR TEMPERATURA
DS18B20.begin();
pinMode(12,OUTPUT);
pinMode(14,OUTPUT);
pinMode(26,OUTPUT);
pinMode(27,OUTPUT);
}
BLYNK_WRITE(V1) {
if (param.asInt()== 1) {
Relay_On = true;
} else{
Relay_On = false;
}
}
void loop() {
// put your main code here, to run repeatedly:
//BLYNK
Blynk.virtualWrite(12,HIGH);
Blynk.virtualWrite(14,HIGH);
Blynk.virtualWrite(26,HIGH);
Blynk.virtualWrite(27,HIGH);
Blynk.run();
temperatura();
//delay(1000);
config_hm();
//delay(500);
water_value1();
delay(500);
if ((digitalRead(4) == 0) && (Relay_On == true)) {
digitalWrite(12, HIGH); // Relay on
Blynk.virtualWrite(V1,1);
}
else{
digitalWrite(12, LOW); //Relay off
Blynk.virtualWrite(V1,0); //ปิด ปุ่มหน้า app ให้เป็น off
}
//Blynk.virtualWrite(15,HIGH);
}
void temperatura()
{
//inicio SENSOR TEMPERATURA
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.println("TEMPERATURA");
Serial.println(temp);
Blynk.virtualWrite(V15, temp);
Serial.println();
}
ตัวเต็มครับ
อะไร on off ตลอดครับ pin ไหน