# This is the first of a series on "How to build a RV parking visualizer" (ME) Fredrik Gustafsson, fg222ja When your out camping with your RV it would be great to see where there are free parking lot's available. Living on the island of Ă–land there are plenty of parkings for RV's. But when your here you don't won't to go from parking to parking just because the parking lots are occupied. My plan is to use a proximity sensor to see if an object is direct above the sensor or perhaps even better in a short range infront of the sensor. This first part of the tutorial will be for the course and will only implement the sensor and visualize it in a diagram. Estimated time - about an hour ## Objective The reason for me to choose this project were when I saw a need for RV's to find free parkings. I guess this can have an impact on the environment when you don't need to go around looking for free parkings. I hope this project can be a help for people with RV's. ## Material #### LoPy4 and expansion board 3.0 The controller for fetching collecting data 492:- at [M.nu](https://www.m.nu/pycom/lopy4-with-headers?gclid=Cj0KCQjwgJv4BRCrARIsAB17JI6VftVvtnnWAfvEOU68UcGyaAaX5HoktZ-7Swd0_zWkZsSe1LFIq5UaAtRyEALw_wcB) #### Breadboard, wiring and resistors For connecting the sensor to the LoPy Breadboard for 59:- at [electrokit](https://www.electrokit.com/produkt/kopplingsdack-400-anslutningar/) Wiring for about 30:- [electrokit](https://www.electrokit.com/produkt/labbsladdar-100mm-hane-hane-30-pack/) Resistors for about 30:- [electrokit](https://www.electrokit.com/produkt/motstandssats-1r-8r2-x10-120-st/) #### HC-SR04 Ultrasonic Sensor Measure the distance 34:- at [M.nu](https://www.m.nu/sensorer-matinstrument/hc-sr04-ultrasonic-sensor?gclid=Cj0KCQjwgJv4BRCrARIsAB17JI49g6BqnGqpAi37iBFus4wsLPBI52lqXy93ukIe7oJ3N2SKmsXGRWYaAv0aEALw_wcB) ## Computer setup I used IDE Visual Studio with PyMakr plugin. But before I started using the LoPy4 with the IDE a made sure everything was updated. Follow the steps at [Pycom](https://docs.pycom.io/gettingstarted/installation/firmwaretool/). ## Putting everything together Before we can upload any data to the LoPy we have to make sure everything is connected as exprected. I used the great tutorial from [Core electronics](https://core-electronics.com.au/tutorials/hc-sr04-ultrasonic-sensor-with-pycom-tutorial.html) ![](https://i.imgur.com/rjXFj9q.png) As soon everythings is connected the code can be uploaded from the IDE to LoPy with the help from the PyMakr plugin. ## Platform I used pybytes platform for this exercise because the readings saved to a diagram is not something I will be saving later on. I tried LoRaWan with TTN (The things network) but didn't seem to be in range of any gateway. ## Code ```python= import utime import pycom import machine from machine import Pin echo = Pin(Pin.exp_board.G7, mode=Pin.IN) trigger = Pin(Pin.exp_board.G8, mode=Pin.OUT) trigger(0) def distance_measure(): trigger(0) utime.sleep_us(2) trigger(1) utime.sleep_us(10) trigger(0) # Wait for start pulse while echo() == 0: pass start = utime.ticks_us() # Wait for end of pulse while echo() == 1: pass finish = utime.ticks_us() utime.sleep_ms(20) distance = ((utime.ticks_diff(start, finish)) * .034)/2 return distance def distance_median(): distance_samples = [] for count in range(10): distance_samples.append(int(distance_measure())) distance_samples = sorted(distance_samples) distance_median = distance_samples[int(len(distance_samples)/2)] return int(distance_median) while True: pybytes.send_signal(1, distance_median()) ``` ## Transmitting the data / connectivity The data is send every one second from the LoPy to the computer using pybytes and MQTT. The data is stored in pybytes. ## Presenting the data ![](https://i.imgur.com/pt0F38T.png) Data is saved every second and showing when an object is moved back and from the sensor. ## Finalizing the design ![](https://i.imgur.com/SB0yMMl.jpg) As mentioned before, this is only a part of my goal. I would like to take this further by adding a case for the sensor. Test if the best fit for the sensor is under or infront of the vehicle. I would also like to add a phone app so it can be visible to see on a map were the free parkings are. I struggled a lot with LoRaWan, a lot more than I thought I would do, and never got it to work. A sensor stopped working so my initial readings were gone. I don't know what happened. I guess for testing it would be great to have a couple of sensors just in case of failure.