Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESPSendMail.h>
- #define TRIGGER_PIN 16
- #define ECHO_PIN 5
- #define EMPTY_TANK 30 //cm
- #define WIFINAME "your_wifi_name"
- #define WIFIPWD "your_wifi_password"
- #define MAILSERVER "your_mailserver"
- #define MAILUSERNAME "your_mailserver_username"
- #define MAILUSERPWD "our_mailserver_password"
- // 20 Liter Füllmenge (Wasser) = 5cm
- // 1 Liter Füllmenge (Wasser) = 2cm
- float AVG_WATER = 0.00;
- uint8_t AVG_WATER_CNT = 0;
- WiFiClientSecure client;
- void setup()
- {
- Serial.begin(9600);
- // Connect to WiFi network
- Serial.print("Connecting to ");
- Serial.println(WIFINAME);
- WiFi.begin(WIFINAME, WIFIPWD);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("My IP address: ");
- Serial.println(WiFi.localIP());
- delay(1000);
- pinMode(TRIGGER_PIN,OUTPUT);
- pinMode(ECHO_PIN,INPUT);
- pinMode(ECHO_PIN, INPUT_PULLUP);
- ESPSendMail SendMail(MAILSERVER,MAILUSERNAME,MAILUSERPWD, &client);
- SendMail.From = "examples@gmail.com"; //put your address here
- SendMail.DisplayFrom = "From_Name"; //put display name here
- SendMail.To = "testtest@gmail.com"; //recipient address
- SendMail.Subject = "Test e-mail"; //subject
- SendMail.ClearMessage();
- SendMail.AddMessageLine("First line of message"); //lines of message
- SendMail.AddMessageLine("Second line");
- SendMail.Send();
- }
- void loop() {
- for ( uint8_t x = 0 ; x < 30 ; x++ )
- {
- AVG_WATER += GetDistance();
- AVG_WATER_CNT++;
- delay(500);
- }
- AVG_WATER /= AVG_WATER_CNT;
- AVG_WATER_CNT = 0;
- Serial.println(AVG_WATER);
- }
- float GetDistance()
- {
- float lDistance = 0;
- float lLength = 0;
- digitalWrite(TRIGGER_PIN, LOW);
- delayMicroseconds(5);
- digitalWrite(TRIGGER_PIN,HIGH);
- delayMicroseconds(10);
- digitalWrite(TRIGGER_PIN,LOW);
- lLength = pulseIn(ECHO_PIN,HIGH);
- lDistance = (lLength / 2) * 0.03432;
- return EMPTY_TANK - (lDistance);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement