My project is an HMI interface that will collect temperature, humidity and wind information from the external environment where I am. The chosen category is Smart Terminal.
I will use humidity and temperature sensors (DHT11) and wind speed sensors (anenometer, model HWFS-1)
The Unihiker will be mounted in a 3D printed case (which is printing as I write this) and I will use the system to collect weather data outside my workspace.
Now that I realize how easy it is to program and configure the Unihiker, I intend to add two more sensors: one for UV rays and another for air quality.
For download .stl files: CLICK HERE
Note that the conversion values of the AD signal to the wind speed sensor are approximate.
I obtained it based on empirical data using the same wind source to read the analog values (0 to 1023) and checking with a portable wind meter that I have here in my laboratory.
After some averages and approximations, I arrived at a reasonable value of 2.8 m/s for each ADC value read.
I'm already doing some research to better understand this sensor and in the future get a more accurate reading. So far, it's been a lot of fun creating with it and the Unihiker.
The HWFS-1 wind sensor has written on its body that for each variation from 0 to 4V it could be multiplied by 14 m/s.
But it was far beyond what I saw in practice with the portable meter here in the laboratory. So I used a ratio and proportion system and now the values are similar.
In the code, following the parameter of 14m/s, for average values of 300 (adc, analog) it resulted in speeds of 12 to 13 m/s... but on the AN-3070 meter the indicated speeds were 2 to 3m/s.
First, we can calculate the new conversion factor based on your readings:
Current analog value: 300
Corresponding voltage:
(300/1023)∗3.3 = 0.968 𝑉
Currently measured speed:
0.968V∗14=13.55m/s
Desired actual speed:
2.5m/s (average between 2 and 3 m/s)
Now, we can find the new conversion factor:
New Factor = Actual Speed / Measured Voltage = 2.5 / 0.968 ≈ 2.58
With this modification, the code used is now as follows:
# ----------------------------------------------------------------------------
# Unihiker Weather Project v1.0
# Designed by Gerson Sena, @aplicarciencias
# Oct 14th, 2024
# ----------------------------------------------------------------------------
# -*- coding: utf-8 -*-
import time
from pinpong.board import Board, Pin, DHT11, ADC # Importação da classe ADC
from pinpong.extension.unihiker import *
from unihiker import GUI # Biblioteca para a GUI
# Inicialização da placa UNIHIKER
Board("UNIHIKER").begin()
# Inicialização da GUI (tela touchscreen)
gui = GUI()
# Configuração dos sensores
dht11 = DHT11(Pin(Pin.P21)) # DHT11 no Pino P21
anemometer_adc = ADC(Pin(Pin.P22)) # ADC no Pino Analógico 22 para o anemômetro
# Desenha o retângulo ao redor do título
gui.draw_rect(x=10, y=5, w=220, h=80, outline="#000000") # Retângulo ao redor do texto
# Define a fonte para negrito
bold_font = ("Arial", 17, "bold") # Definindo a fonte Arial, tamanho 17, em negrito
# Textos de interface para DHT11
txt1 = gui.draw_text(text="Monitor de Temperatura, Umidade e Vento", x=120, y=45, w=240, origin='center',
font=bold_font, color="#000000") # Título em preto e negrito
txt2 = gui.draw_text(text="Temperatura:", x=10, y=130, font_size=14, color="#0000FF")
txt3 = gui.draw_text(text="Umidade:", x=10, y=160, font_size=14, color="#0000FF")
txt4 = gui.draw_text(text="℃", x=185, y=130, font_size=14, color="#0000FF")
txt5 = gui.draw_text(text="%RH", x=185, y=160, font_size=14, color="#0000FF")
txt6 = gui.draw_text(text="Ventos:", x=10, y=190, font_size=14, color="#0000FF")
txt7 = gui.draw_text(text="m/s", x=185, y=190, font_size=14, color="#0000FF")
# Valores dinâmicos na tela
value1 = gui.draw_text(x=135, y=130, text='25', font_size=14) # Temperatura
value2 = gui.draw_text(x=135, y=160, text='25', font_size=14) # Umidade
value3 = gui.draw_text(x=135, y=190, text='0', font_size=14) # Velocidade do vento em m/s
while True:
# Leitura do sensor DHT11
temp = dht11.temp_c() # Leitura da temperatura em Celsius
print("Temperatura DHT11:", temp)
value1.config(text=temp) # Atualiza temperatura na tela
humi = dht11.humidity() # Leitura da umidade
print("Umidade DHT11:", humi)
value2.config(text=humi) # Atualiza umidade na tela
# Leitura do anemômetro usando ADC
wind_analog = anemometer_adc.read() # Leitura do valor analógico (0-1023)
print("Valor analógico do anemômetro:", wind_analog)
# Converte o valor analógico para tensão (0 a 3.3V)
wind_voltage = (wind_analog / 1023.0) * 3.3
print("Tensão do anemômetro (V):", wind_voltage)
# Converte a tensão para velocidade do vento (multiplica pelo novo fator 2.58 m/s)
wind_speed = wind_voltage * 2.58
print("Velocidade do vento (m/s):", wind_speed)
value3.config(text=f"{wind_speed:.2f}") # Atualiza velocidade do vento na tela
time.sleep(1) # Atualiza leituras a cada segundo
Watch a short video of the project: CLICK HERE
For any questions, feel free to contact me here or on my social networks @aplicarciencias.