0% found this document useful (0 votes)
22 views5 pages

Define BLYNK

This document defines constants and pins for an Arduino project that uses an ESP8266 module to connect to Blynk and monitor water level and TDS (total dissolved solids) using an ultrasonic sensor and TDS sensor. It initializes the OLED display, WiFi connection, and Blynk connection. The main loop calls functions to take sensor readings and send them to the Blynk app at set intervals.

Uploaded by

yanuartw7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

Define BLYNK

This document defines constants and pins for an Arduino project that uses an ESP8266 module to connect to Blynk and monitor water level and TDS (total dissolved solids) using an ultrasonic sensor and TDS sensor. It initializes the OLED display, WiFi connection, and Blynk connection. The main loop calls functions to take sensor readings and send them to the Blynk app at set intervals.

Uploaded by

yanuartw7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#define BLYNK_TEMPLATE_ID "TMPL0pY6ULvF"

#define BLYNK_DEVICE_NAME "ALAT PENDETEKSI AIR PADA FUEL DI TANGKI"

#define BLYNK_AUTH_TOKEN "mLe88qRif6Fu2e4GEyKNTtZyuPlZCqzG"

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "NAJMA 2019"; // type your wifi name

char pass[] = "RAWILASE"; // type your wifi password

BlynkTimer timer;

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define echoPin D5

#define trigPin D6

#define TdsSensorPin A0
#define VREF 3.3 // analog reference voltage(Volt) of the ADC

#define SCOUNT 30 // sum of sample point

WidgetLED pump (V1);

long duration;

int relayInput = 2;

int distance;

int depth =0;

int status = WL_IDLE_STATUS ;

WiFiClient client;

void ultrasonic (){

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

long t = pulseIn(echoPin, HIGH);

long cm = t / 29 / 2;

Serial.println(cm);

long level= depth-cm;

if (level<0)

level=0;

level = map(level,7,2,0,100);

Blynk.virtualWrite(V2, level);

}
void sendSensor()

int tdsValue = analogRead (TdsSensorPin);

float analogRead= (tdsValue/1205.0)* 330;

if (tdsValue >= 17) {

digitalWrite ( relayInput, LOW) ;

delay(500);

digitalWrite (relayInput,HIGH);

delay (5000);

pump.on();

else {

digitalWrite (relayInput, HIGH);

pump.off();

Serial.print("Kadar Air:");

Serial.print(tdsValue,0);

Serial.println("ppm");

Blynk.virtualWrite(V0, tdsValue);

delay(1000);

display.clearDisplay();

display.setTextSize(2);

display.setCursor(20,0);

display.print("Kadar Air");
display.setTextSize(3);

display.setCursor(30,30);

display.print(tdsValue);

display.display();

void setup(){

Serial.begin(115200);

WiFi.disconnect ();

Serial.println ("Connecting...");

WiFi.begin (ssid,pass);

Serial.println(WiFi.status());

Serial.println("Connected!");

Serial.println("");

if(!display.begin(SSD1306_SWITCHCAPVCC,0x3c))

Serial.println(F("SSD1306 allocation failed"));

for(;;);//Dont proceed

display.display();

delay(2);

display.clearDisplay();

display.clearDisplay();

display.setTextColor(WHITE);

display.setTextSize(1);

display.setCursor(0,5);

display.print(" ");
display.display();

delay(3000);

pinMode(TdsSensorPin,INPUT);

pinMode (relayInput, OUTPUT);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

delay (1000);

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))

Serial.println(F("SSD1306 allocation failed"));

for(;;);

delay(500);

Blynk.begin(auth, ssid, pass);

timer.setInterval(100L, sendSensor);

void loop(){

Blynk.run();

timer.run();

ultrasonic ();

You might also like