---
# System prepended metadata

title: Temperature and humidity measurement for golf club selection insights

---

# Temperature and humidity measurement for golf club selection insights

By: Jacob Liljestrand,  jl225wb

**Description**

The scope of this project was to combine IoT with my interest in golf. Based on pure physics it's known that humidity and temperature affects the carry of golf shot. Therefore, I measured the temperature and humidity on the golf course and displyed the results on my phone with a dashboard using Adafruit, which gives me more information to base my golf club selection on. This was made using a HelTec LoRa 32, a DHT11 sensor and by conecting the board to my mobile WiFi-hotspot.

Approximated time needed to complete this project: 10 to 20 hours.

# Objective

I choosed this project mainly because of my big interst in golf and technology. Therefore, I found this project to be a perfect combination of the two otherwise, different areas. Golf is a very traditional and conservative sport, that I wanted to change with IoT.

The purpose it serves is to give the golf player more information to base his club selection on. As we all know, we often make better decisions if we possess more  information.  In today's golf, espically amature golf, we only base our club of choice on the distance to the hole and some human estimation of wind direction and speed. With the knowledge that temperature and humidity affects the density of the air and therefore also the carry of the ball, we can take this into a count when choosing the right golf club.  

The insights that it gives is wether or not to choose the club you normally use at that perticular distance or to change club into a more fitting one based on the addtional information you got. Accorading to Mastrangelo, (n.d.) a decrease with 10 farenheits will take away 1 yard from your carry. A decreasing humidity also slashes some carry but not to the same extent. 

# Material



| No. | Name                    | Specification                                                                                                                            | Task                                                                         | Cost and link    |
| --- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- | --- |
| 1   | HelTech LoRa 32         | AZDelivery NodeMCU ESP32 Heltec with 0,96 inch OLED-display and SX1276 868MHz LoRa                                                         | Run specific program                                                         |   329,99 SEK https://www.amazon.se/dp/B08243JHMW/ref=pe_24982401_503747021_TE_SCE_dp_1  |
| 2   | Multicolor Duplex Cable | 40 Pin Male to Female, 40 Pin Male to Male, 40 Pin Female to Female Breadboard Jumper Wire Strapping Cable Kit for Arduino                 | Allows electrical currents to travel from one point to another in the circut |   79,99 SEK https://www.amazon.se/dp/B01EV70C78/ref=pe_24982401_503747021_TE_SCE_dp_1?language=en_GB  |
| 3   | Solder                  | Soldering iron (30 W), soldering iron stand, cleaning sponge, tin suction and 17 g solder. Operated directly from the wall socket (230 V). | Solder pins to microcontroller                                               | 149 SEK https://www.kjell.com/se/produkter/el-verktyg/verktyg/lodning/lodkolvar/dibotech-lodkolvset-30-w-p40060    |
| 4   | DHT11                   | Driving voltage: 5 V DC. Temperature: 0-50° C (±2°C). Humidity: 20-90 % RH (±5 % RH). Measure: 39x23x10 mm                                 | Measure temprature and humidity                                              |    99,90 SEK https://www.kjell.com/se/produkter/el-verktyg/arduino/moduler/temperatur-och-luftfuktighetssensor-for-arduino-p87086 |
5|  Breadboard    |       Set of three clutch tires. 170, 400 and 830 connections respectively. For fast and solder-free connections. Hole spacing: 2.54 mm.                  |Building temporary circuts|149,90 SEK https://www.kjell.com/se/produkter/el-verktyg/elektronik/elektroniklabb/luxorparts-set-med-3-kopplingsdack-mix-pack-p36085

# Computer setup


**1. Set up your heltec LoRa 32 controller** 
First you need to solder the pins to your microcontroller to later be able to use the breadboard. Be **careful** with the LED-display if you are using a HelTec device.

![](https://i.imgur.com/sZnIHhU.jpg)

Your now ready to mount your microcontroller  to your breadboard and get started. 

**2. Get the software running**
Firstly, connect the microcontroller to your computer with an micro-USB cable **that can handle data transfer**. Now let's get your microcontroller to flash. Proceed to the following link and download **the latest version** of Node.js to your computer [here](https://nodejs.org/en/).
My IDE of choice was Atom, since I found it easy to navigate. Altough, keep in mind that it seems to lag a bit from time to time.   
Download Atom.io [here](https://atom.io).

Now, open Atom.io and install the pymakr plug in, see the exact steps in this turtorial from LNU [here](https://hackmd.io/@lnu-iot/SydH7MTcw).

Once Pymakr is installed you may **close atom and reopen** it again. 

**3. Update firmware**
Download the following [file](https://github.com/H-Ryan/Heltec/blob/main/PyCom%20MicroPython/Heltec%20PyCom%20MicroPython.zip?raw=true).
and proceed to this [website](https://nabucasa.github.io/esp-web-flasher/) and follow the numbred steps in the borrowed picture from LNU below.

![](https://i.imgur.com/JuWIyJ0.png)
Then **write down your device adress** (step 3), press "Erase" and upload the file you downloaded previously. See borrowed picture from LNU below.

![](https://i.imgur.com/XJzJ9zc.png)

You are now ready to connect your device to Atom.io. But before running and uploading code, make sure to fill in the device address and unmark "Auto connect" and "Safe-boot" in global settings. 

**4. Flash device**
To flash the device, run the following code. And to upload the code, press "Upload projectd to device".
```
from machine import Pin             # Used for LED pin addressing
import time                         # Used for the delay between blinking

led = Pin('P22', mode=Pin.OUT)      # Used LED pin as output
# Loop for blinking
while True:
    led.value(1)
    time.sleep(1)
    led.value(0)
    time.sleep(1)
```
Congratualtion, your device should be flashing!

# Putting everything togehter

The wiring is very basic since I only use one sensor. With reference to the picture of the circut below, the DTH11 comes in various forms and therefore it's important to read the manual before attaching the wires. In this case we can see that the data output cable conects to the left pin, the ground cable connects to the centre pin and the power cable connects to the right pin of the sensor. The power cable is later attached to the 3V3 pin on the HelTec. It's important to carefully read what voltage your specific sensor runs on. The data cable is attached to a free pin that's not used by LoRa. Lastly, the ground cable is attached to the GND pin, next to the 3V3 power connection. **Be carefull to check that everything looks good before powering on the HelTec.**

![](https://i.imgur.com/fRZSOtz.jpg)


![](https://i.imgur.com/mrbbEVJ.png)

# Platform

I choosed Adafruit as my platform to generate a dashboard, which is a cloud platform using MQTT broker. It was chosen mainly because it is easy to build and design informative dashboards and because MQTT is a well fit for sending data within IoT since it uses QoS levels to ensure that the data can be delivered even if the connection is unreliable. Some functionality that is benefitial within Adafruit is that you can control motors connected to your IoT project and store sensor data to get valuable insights displayed in the dashboard. Furthermore, you can easily connect your IoT project to a web service. Some examples could be Twitter or several different weather services.

To begin with, you will have to open an free Adafruit IO account [here](https://accounts.adafruit.com). Keep in mind that the free version is limitied in datapoints.

For future continuation in this project I would like to set up an application with backround calculations based on humidity, air preasure, temprature and distance to hole. This would enable me to present exactly which club to choose in the dashboard. Altough, this would require an golf course gps-API, which could be expensive. Furthermore, I would concider to get a premium account on Adafruit to avoid being limited in data points.

# The code

In the below section you can overlook some parts of the code that was used during the project. 
To be able to run the code you would have to dowload the libraries [dht.py](https://github.com/iot-lnu/applied-iot/blob/master/sensor-examples/DHT11%20%26%20DHT22%20-%20Humidity%20%26%20Temperature%20Sensor/lib/dht.py) and [mqtt.py](https://github.com/iot-lnu/applied-iot/blob/master/network-examples/mqtt_ubidots/mqtt.py).

The structure of the code is based on LNU:s tutorial for Adafruit, found [here](https://hackmd.io/@lnu-iot/ByPRkQTF9). The code was later redesigned to handle the information red from my DHT11 and to display this information in both figures and text. The text will vary depending on the values measured from the DHT11 sensor, and indicate if I should change golf club or not.

```
wdt = WDT(timeout=50000)  #Watch dog timeout used to reset board in case of innactivity

# Connecting to mobile WiFi-hotspot
wlan = WLAN(mode=WLAN.STA)
wlan.connect(WIFI_SSID, auth=(WLAN.WPA2, WIFI_PASS))

while not wlan.isconnected():   # Code waits here until WiFi connects
    pass


# FUNCTIONS
########################################################################
# Read data from sensor
def send_data():

    th = DHT(Pin('P23', mode=Pin.OPEN_DRAIN), 0)
    time.sleep(2)
    result = th.read()

    while not result.is_valid():
        time.sleep(.5)
        
        result = th.read()

    time.sleep(5)

    # Depending on the measured values, a text message will be displayed on the dashboard
    if result.temperature > 24:
        tempmessage = 'It is very warm outside, choose a shorter club'
    else:
        tempmessage = 'It is NOT warm outside, play a regular club'

    if result.humidity > 70:
        humidmessage = 'It is very humid outside, choose a shorter club'
    else:
        humidmessage = 'It is NOT humid, play a regular club'
    try:
        #Publishing the data
        client.publish(topic=AIO_HUMIDITY_FEED, msg=str(result.humidity))
        client.publish(topic=AIO_TEMPERATURE_FEED, msg=str(result.temperature))
        client.publish(topic=AIO_HumidText_FEED, msg=str(humidmessage))
        client.publish(topic=AIO_TempText_FEED, msg=str(tempmessage))
        
    except Exception as e:
        pass

##################################################
#  MQTT protocol to connect to Adafruit IO


client = MQTTClient(AIO_CLIENT_ID, AIO_SERVER, AIO_PORT, AIO_USER, AIO_KEY)
client.connect()
message_interval = 1
time.sleep(message_interval)
try:                      # Code between try: and finally: may cause an error
                          # so ensure the client disconnects the server if something happends
    while 1:              # Repeat this loop forever
        client.check_msg()# Action a message if one is received. Non-blocking.
        time.sleep(180)
        send_data()
        wdt.feed()     
finally:                  # If an exception is thrown ...
    client.disconnect()   # ... disconnect the client and clean up.
    client = None
    wlan.disconnect()
    wlan = None
```
# Transmitting the data / connectivity

**Wireless protocol**

Using WiFi to transmitt the data was choosed since the golf club in Umea is not covred by "The Things Network" or "Helium". Furthermore, I wanted to be sure that I could use my project at any golfcourse, and thats why I connect the device to my mobile WiFi-hotspot. Altough WiFi does not posess long coveredge and that it has high power consumption, it does not affect the area of usage. Since I always have my phone with me on the course and that the phones today have such good batteries, it works out great. Further, I use a powerbank as a power source to the board.

**Transport protocol**

My HelTec LoRa 32 device publishes the data collected from the DHT11 with MQTT to the Adafruit IO MQTT broker. This works by connecting Adafruit feeds with the credentials entered in the code. In the point of view of security, this also helps you to protect your feeds of information. The data is sent every third minute to not overpass the limitation on 30 datapoints per minute.

# Presenting the data

**Setting up the dashboard**

When setting up the dashboard you will first have to set up a feed that you later will connect to a block of your choice.
![](https://i.imgur.com/YFPAsMd.png)

When the feed is set you can choose a block that is able to present your measured data in a pedagogical way.

![](https://i.imgur.com/9AW8y0N.png)

Once the feed is conected to the block and the credentials from the feed is entered into main.py, you are ready to send and present your data.

**Finished dashboard**

![](https://i.imgur.com/X8XscDn.png)

The data as mentioned before is sent every third minute and Adafruit.io saves the data connected to your dashboard for 30 days.

![](https://i.imgur.com/BsLy5vL.png)
Here you can see how the humidity changes.

![](https://i.imgur.com/F7ljbR9.png)
Here you can see how the temperature changes.



# Finalizing the design

I'm happy with the outcome of the project, especially since I'm new to IoT in terms of hardware and some of the softwe that were used. I'm especially happy since i was able to find usage for IoT even within golf. This has broadened my view regarding areas where IoT could be usfull to gain insights and extract valuable information. Below you can see the device in action on the golf course.
![](https://i.imgur.com/BqiohlZ.jpg)

![](https://i.imgur.com/o9qAw2J.jpg)

**Final thoughts**

My finals thoughts regarding my golf project is that it is a good ground to build upon. I believe that you can expand this project so much more if you have more time. For example, try to get the course gps-data and use distances to decide what club to use in what situation in combination with the measured data. Furthermore, you could build a case for the board to attach to the golf bag. I also belive that these kind of projects can be used in simular ways in other sports as well. For example in tennis: How hard should the strings be on the racket based on the climate? In down hill skiing: What skies should I use based on climate and snow quality etc. So as a final word, please use my project to expand the implementation of IoT in sports and decisions regarding material in sports. 

# Refrenses

1. David Mozart, (2022), Part 1: Installing Atom IDE, Avalible at: https://hackmd.io/@lnu-iot/SydH7MTcw

2. Hamed Talebi, (2022), Adafruit IO (MQTT & Webhooks), Available at: https://hackmd.io/@lnu-iot/ByPRkQTF9

3. Reegan Mastrangelo, (n.d.), Available at: https://projectgolfau.com/golf-balls-fly-farther-in-humidity/
 




































