วันอาทิตย์ที่ 25 กันยายน พ.ศ. 2565

ESP32 (Current leak sensor)

///////////////////////////

#define BLYNK_PRINT Serial

#include <WiFi.h>

#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>


//Auth Token ของ Blynk App.

char auth[] = "**********";//Auth Token ของ Project IoT-WaterFlow



//Set password WIFI เชื่อมต่อ Access point(WPA).

char ssid[] = "**********";

char pass[] = "**********";


//ZMPT101B Voltage-sensor

const int sensorPin1=36;  //ต่อกับขา GPIO36

const int sensorPin2=39;  //ต่อกับขา GPIO39

const int ledRED=32;  //ต่อกับขา GPIO32

const int ledGREEN=33;  //ต่อกับขา GPI33

double sensorValue1 = 0;

double sensorValue2 = 0;


void setup() {

  Serial.begin(115200);

  pinMode(sensorValue1,INPUT);

  pinMode(sensorValue2,INPUT);

  pinMode(ledRED,OUTPUT);

  pinMode(ledGREEN,OUTPUT);

  

 // Blynk.begin(auth, ssid, pass);

  delay(1000);

}


void loop(){

  sensorValue1 = analogRead(sensorPin1);

  sensorValue2 = analogRead(sensorPin2);


  if(sensorValue1 < 2340 && sensorValue2 < 1850){

    int sta_ee = 0; //ไม่พบไฟรั่ว

    digitalWrite(ledGREEN,HIGH);

    digitalWrite(ledRED,LOW);

    delay(1000);

  }else{

    int sta_ee = 1; //พบไฟรั่ว

    digitalWrite(ledRED,HIGH);

    digitalWrite(ledGREEN,LOW);

    delay(1000);

  }

  Serial.print("S1="); Serial.print(sensorValue1);Serial.print(" : "); 

  Serial.print("S2="); Serial.println(sensorValue2);

  

  delay(500);    

  Blynk.virtualWrite(V0, sensorValue1);

  Blynk.virtualWrite(V1, sensorValue2); 

  Blynk.virtualWrite(V2, sta_ee);       //สถานะไฟรั่ว

  Blynk.run();

}

ออกแบบการทำงานของ บอร์ด ESP32 เชื่อมต่อกับ PH sensor และ Turbidity sensor ส่งข้อมูลไปยัง Blynk 2.0

        ตรวจสอบคำสั่งการเชื่อมต่อกับ Blynk ที่เว็บไซต์  https://examples.blynk.cc  โดยตัวอย่างโค้ดนี้ได้ใช้รูปแบบคำสั่ง  

          Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

        ในการเชื่อมต่อกับ Blynk 2.0

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Code ESP32 Board ( PH sensor & Turbidity sensor)

///////////////////////////////////
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

//Auth Token ของ Blynk App.
char auth[] = "**********";//Auth Token ของ Project IoT-WaterFlow


//Set password WIFI เชื่อมต่อ Access point(WPA).
char ssid[] = "**********";
char pass[] = "**********";

//PH-sensor
const int phPin=36;  //ต่อกับขา GPIO36
float ph; float phValue=0;
//Turbidity -sensor
const int turbidityPin=39;  //ต่อกับขา GPIO39
float turbidityValue=0;

void setup() {
  Serial.begin(115200);
  pinMode(phPin,INPUT);
  pinMode(turbidityPin,INPUT);
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);  // เชื่อมต่อ Blynk 2.0
  delay(1000);
}

void loop(){
 
    phValue= analogRead(phPin);
    turbidityValue= analogRead(turbidityPin);
    
    //PH sensor
    Serial.print("PH : ");
    Serial.print(phValue);
    Serial.print(" | ");
    float voltage=phValue*(3.3/4095.0);
    ph=(3.3*voltage);
    Serial.println(ph);
    //Turbidity sensor
    float turbidity = turbidityValue * (5.0 / 1024.0);
    Serial.print("Turbidity : ");
    Serial.print(turbidityValue);
    Serial.print(" | ");
    Serial.println(turbidity);
    
    delay(500);
    Blynk.virtualWrite(V0, ph);
    Blynk.virtualWrite(V1, turbidity);
    Blynk.run();
}

โครงการ เรียนรู้ระบบปัญญาประดิษฐ์ด้วยการทำงานของหุ่นยนต์เดินตามเส้น ผู้รับผิดชอบโครงการ อ.วุฒิชัย  ปวงมณี  ผศ. ดร.รติ  วงษ์สถานและนักศึกษาส...