1 | /*************************************************************
|
2 | Download latest Blynk library here:
|
3 | https://github.com/blynkkk/blynk-library/releases/latest
|
4 |
|
5 | Blynk is a platform with iOS and Android apps to control
|
6 | Arduino, Raspberry Pi and the likes over the Internet.
|
7 | You can easily build graphic interfaces for all your
|
8 | projects by simply dragging and dropping widgets.
|
9 |
|
10 | Downloads, docs, tutorials: http://www.blynk.cc
|
11 | Sketch generator: http://examples.blynk.cc
|
12 | Blynk community: http://community.blynk.cc
|
13 | Follow us: http://www.fb.com/blynkapp
|
14 | http://twitter.com/blynk_app
|
15 |
|
16 | Blynk library is licensed under MIT license
|
17 | This example code is in public domain.
|
18 |
|
19 | *************************************************************
|
20 |
|
21 | This example shows how value can be pushed from Arduino to
|
22 | the Blynk App.
|
23 |
|
24 | WARNING :
|
25 | For this example you'll need Adafruit DHT sensor libraries:
|
26 | https://github.com/adafruit/Adafruit_Sensor
|
27 | https://github.com/adafruit/DHT-sensor-library
|
28 |
|
29 | App project setup:
|
30 | Value Display widget attached to V5
|
31 | Value Display widget attached to V6
|
32 | *************************************************************/
|
33 |
|
34 | /* Comment this out to disable prints and save space */
|
35 | #define BLYNK_PRINT Serial
|
36 |
|
37 |
|
38 | #include <WiFi.h>
|
39 | #include <WiFiClient.h>
|
40 | #include <BlynkSimpleEsp32.h>
|
41 | #include <RunningMedian.h>
|
42 |
|
43 | RunningMedian mediandist = RunningMedian(5);
|
44 |
|
45 | /* DS18B20 Temperature Sensor */
|
46 | #include <OneWire.h>
|
47 | #include <DallasTemperature.h>
|
48 | #define ONE_WIRE_BUS 4 // DS18B20 on arduino corresponds to D4 on physical board
|
49 | OneWire oneWire(ONE_WIRE_BUS);
|
50 | DallasTemperature DS18B20(&oneWire);
|
51 | float t; // Temperatur
|
52 |
|
53 | /* Ultrasonic Sensor - HC-SR04 */
|
54 | #define TRIGGERPIN 22
|
55 | #define ECHOPIN 23
|
56 | long duration, distance;
|
57 | long distMedian;
|
58 |
|
59 | // You should get Auth Token in the Blynk App.
|
60 | // Go to the Project Settings (nut icon).
|
61 | char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
|
62 |
|
63 | // Your WiFi credentials.
|
64 | // Set password to "" for open networks.
|
65 | char ssid[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
|
66 | char pass[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
|
67 |
|
68 | BlynkTimer timer;
|
69 |
|
70 | // This function sends Arduino's up time every second to Virtual Pin (5).
|
71 | // In the app, Widget's reading frequency should be set to PUSH. This means
|
72 | // that you define how often to send data to Blynk App.
|
73 |
|
74 | void sendSensor()
|
75 | {
|
76 | DS18B20.requestTemperatures();
|
77 | float t = DS18B20.getTempCByIndex(0);
|
78 | Serial.print(t);
|
79 | Serial.println("ºC");
|
80 |
|
81 | if (isnan(t)) {
|
82 | Serial.println("Failed to read from DS18B20 sensor!");
|
83 | Serial.print(t);
|
84 | Serial.println("ºC");
|
85 | return;
|
86 | }
|
87 | // You can send any value at any time.
|
88 | // Please don't send more that 10 values per second.
|
89 |
|
90 | Serial.print("BlynkMedian: ");
|
91 | Serial.println(distMedian);
|
92 | Serial.print("Blyndistance: ");
|
93 | Serial.println(distance);
|
94 |
|
95 | Blynk.virtualWrite(V15, distance);
|
96 | Blynk.virtualWrite(V16, distMedian);
|
97 | Blynk.virtualWrite(V10, t);
|
98 | }
|
99 |
|
100 | void setup()
|
101 | {
|
102 | // Debug console
|
103 | Serial.begin(115200);
|
104 |
|
105 | pinMode(TRIGGERPIN, OUTPUT);
|
106 | pinMode(ECHOPIN, INPUT);
|
107 |
|
108 | Blynk.begin(auth, ssid, pass, IPAddress(192,168,123,32), 8080);
|
109 | // You can also specify server:
|
110 | //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
|
111 | //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
|
112 |
|
113 |
|
114 |
|
115 | DS18B20.begin();
|
116 |
|
117 |
|
118 | // Setup a function to be called every second
|
119 | timer.setInterval(1000L, sendSensor);
|
120 |
|
121 | }
|
122 |
|
123 |
|
124 | void ultrasonic()
|
125 | {
|
126 | for (int j = 0; j < 10; j++){
|
127 | digitalWrite(TRIGGERPIN, LOW);
|
128 | delayMicroseconds(2);
|
129 |
|
130 | digitalWrite(TRIGGERPIN, HIGH);
|
131 | delayMicroseconds(10);
|
132 |
|
133 | digitalWrite(TRIGGERPIN, LOW);
|
134 | duration = pulseIn(ECHOPIN, HIGH);
|
135 | distance = (duration/2)*0.03432; // (duration/2) / 29.1;
|
136 | delay (100);
|
137 |
|
138 |
|
139 |
|
140 | //int x = distance;
|
141 |
|
142 | mediandist.add(distance); //}alt
|
143 |
|
144 | //Medianwert
|
145 | long distMedian = mediandist.getMedian();
|
146 |
|
147 | Serial.print("Median loop: ");
|
148 | Serial.print(distMedian);
|
149 | Serial.println(" Cm");
|
150 | delay(100);
|
151 |
|
152 | Serial.print("Messung loop: ");
|
153 | Serial.print(distance);
|
154 | Serial.println(" Cm");
|
155 | Serial.print("duration loop: ");
|
156 | Serial.println(duration);
|
157 |
|
158 | } //neu
|
159 | }
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | void loop()
|
165 | {
|
166 |
|
167 | delay(100);
|
168 | ultrasonic();
|
169 | Blynk.run();
|
170 | timer.run();
|
171 | }
|