Advertisement
jh_elec

Untitled

Jul 9th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <ESPSendMail.h>
  3.  
  4. #define TRIGGER_PIN 16
  5. #define ECHO_PIN 5
  6.  
  7. #define EMPTY_TANK 30 //cm
  8.  
  9. #define WIFINAME "your_wifi_name"
  10. #define WIFIPWD "your_wifi_password"
  11. #define MAILSERVER "your_mailserver"
  12. #define MAILUSERNAME "your_mailserver_username"
  13. #define MAILUSERPWD "our_mailserver_password"
  14.  
  15. // 20 Liter Füllmenge (Wasser) = 5cm
  16. // 1 Liter Füllmenge (Wasser) = 2cm
  17.  
  18.  
  19. float AVG_WATER = 0.00;
  20. uint8_t AVG_WATER_CNT = 0;
  21.  
  22. WiFiClientSecure client;
  23.  
  24. void setup()
  25. {
  26.  
  27. Serial.begin(9600);
  28.  
  29. // Connect to WiFi network
  30. Serial.print("Connecting to ");
  31. Serial.println(WIFINAME);
  32.  
  33. WiFi.begin(WIFINAME, WIFIPWD);
  34. while (WiFi.status() != WL_CONNECTED) {
  35. delay(500);
  36. Serial.print(".");
  37. }
  38. Serial.println("");
  39. Serial.println("My IP address: ");
  40. Serial.println(WiFi.localIP());
  41. delay(1000);
  42.  
  43.  
  44. pinMode(TRIGGER_PIN,OUTPUT);
  45. pinMode(ECHO_PIN,INPUT);
  46. pinMode(ECHO_PIN, INPUT_PULLUP);
  47.  
  48.  
  49. ESPSendMail SendMail(MAILSERVER,MAILUSERNAME,MAILUSERPWD, &client);
  50. SendMail.From = "examples@gmail.com"; //put your address here
  51. SendMail.DisplayFrom = "From_Name"; //put display name here
  52. SendMail.To = "testtest@gmail.com"; //recipient address
  53. SendMail.Subject = "Test e-mail"; //subject
  54. SendMail.ClearMessage();
  55. SendMail.AddMessageLine("First line of message"); //lines of message
  56. SendMail.AddMessageLine("Second line");
  57.  
  58. SendMail.Send();
  59.  
  60.  
  61. }
  62.  
  63. void loop() {
  64.  
  65. for ( uint8_t x = 0 ; x < 30 ; x++ )
  66. {
  67. AVG_WATER += GetDistance();
  68. AVG_WATER_CNT++;
  69. delay(500);
  70. }
  71. AVG_WATER /= AVG_WATER_CNT;
  72. AVG_WATER_CNT = 0;
  73.  
  74. Serial.println(AVG_WATER);
  75.  
  76. }
  77.  
  78. float GetDistance()
  79. {
  80. float lDistance = 0;
  81. float lLength = 0;
  82.  
  83. digitalWrite(TRIGGER_PIN, LOW);
  84. delayMicroseconds(5);
  85. digitalWrite(TRIGGER_PIN,HIGH);
  86. delayMicroseconds(10);
  87. digitalWrite(TRIGGER_PIN,LOW);
  88.  
  89. lLength = pulseIn(ECHO_PIN,HIGH);
  90. lDistance = (lLength / 2) * 0.03432;
  91.  
  92. return EMPTY_TANK - (lDistance);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement