89
edits
(Created page with "The project „under the bridge“ is dealing with site specific movements that are send from their origin place to another place. Movements of passing vehicles are bringing m...") |
No edit summary |
||
Line 1: | Line 1: | ||
(new text) | |||
Technical aspects | |||
Hardware | |||
a) 2 microcontrollers with wifi | |||
b) distance sensor | |||
c) servo motor | |||
Software | |||
d) Codes for distance sensor and servo motor | |||
e) web-hoster for data transfer | |||
a) There are several possibilities for microcontrollers. Instead of using a expansive arduino wifi module I decided to go first with a SIM 800L (http://www.ayomaonline.com/programming/quickstart-sim800-sim800l-with-arduino/) as I was coming across with hardware failures of that module, I decided to try out WEMOS D1 mini (https://www.wemos.cc/product/d1-mini-pro.html#). This module has great functions as you can directly hook up sensors on it (but also you can do a lot of different stuff with it, see here: https://www.youtube.com/watch?v=G73fiaOpUAc). The great thing about them is that they are easy to use because you can work with the Arduino IDE on it, they are small, they come with wifi (ESP 8266 chip) and they are cheap (check out aliexpress.com). | |||
So I used two of these modules: One on the sensing and one on the retrieving site. | |||
b) | |||
microcontroller 1 was connected with the Hc-Sr04 distance sensor (http://www.micropik.com/PDF/HCSR04.pdf). It was meassuring the movement of the metal plate that was created whenever there was a car passing by. The code below contains already the hosting information for the data transfer. More information on that under e) | |||
Here the arduino code: | |||
#include <ESP8266WiFi.h> | |||
#include <FirebaseArduino.h> | |||
// Set these to run example. | |||
#define FIREBASE_HOST "xxxxxxxxx.firebaseio.com" // firebase host site | |||
#define FIREBASE_AUTH "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // firbase authentification code | |||
#define WIFI_SSID "pipapowifi" // wifi name | |||
#define WIFI_PASSWORD "xxxxxxxx" // wifi password | |||
#define echoPin D7 // Echo Pin | |||
#define trigPin D6 // Trigger Pin | |||
long duration, distance; // Duration used to calculate distance | |||
void setup() { | |||
Serial.begin(115200); | |||
pinMode(trigPin, OUTPUT); | |||
pinMode(echoPin, INPUT); | |||
// connect to wifi. | |||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | |||
Serial.print("connecting"); | |||
while (WiFi.status() != WL_CONNECTED) { | |||
Serial.print("."); | |||
delay(500); | |||
} | |||
Serial.println(); | |||
Serial.print("connected: "); | |||
Serial.println(WiFi.localIP()); | |||
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); | |||
} | |||
void loop() { | |||
digitalWrite(trigPin, LOW); | |||
delayMicroseconds(2); | |||
digitalWrite(trigPin, HIGH); | |||
delayMicroseconds(10); | |||
digitalWrite(trigPin, LOW); | |||
duration = pulseIn(echoPin, HIGH); | |||
//Calculate the distance (in cm) based on the speed of sound. | |||
float distance = duration*0.0343/2; | |||
Serial.println(distance); | |||
Serial.println ( " cm"); | |||
delay (200); | |||
digitalWrite(echoPin, HIGH); | |||
//send data to firebase | |||
Firebase.setFloat("dist", distance); | |||
digitalWrite(echoPin, LOW); | |||
delay(1000); | |||
} |
edits