Hey guys, how are you?
Here + 1 project of mine using the 1.2 V soil sensor
I don't know if the calculations are correct and it works for me
Thank you for being part of this community
Here + 1 project of mine using the 1.2 V soil sensor
I don't know if the calculations are correct and it works for me
Thank you for being part of this community
B4R:
Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private timer1 As Timer
Private ssd As AdafruitSSD1306
Private ESPin As D1Pins
Dim sensorUmidadeSolo As Pin
Dim valorUmidade As Int
' Defina os valores de calibração para seco e molhado
Dim valorSeco As Int = 700 ' Ajuste este valor com base na sua calibração ADC 656
Dim valorMolhado As Int = 300 ' Ajuste este valor com base na sua calibração ADC 289
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
sensorUmidadeSolo.Initialize(sensorUmidadeSolo.A0, sensorUmidadeSolo.MODE_INPUT)
ssd.InitializeI2C(ESPin.D6,0x3C) 'initialise SSD1306 0x78
ssd.ClearDisplay
ssd.GFX.SetCursor(0, 0)
ssd.GFX.ConfigureText(1, ssd.WHITE, False)
ssd.GFX.DrawText("Inicializando...").DrawText(CRLF).DrawText(CRLF)
ssd.Display
'example of connecting to a local network
If wifi.Connect2(" "," ") Then
Log("Conectador a Internet")
ssd.ClearDisplay
ssd.GFX.SetCursor(0, 0)
ssd.GFX.ConfigureText(1, ssd.WHITE, False)
ssd.GFX.DrawText("Conectado wifi").DrawText(CRLF).DrawText(CRLF)
ssd.Display
Else
Log("Falha ao se conectar a Internet")
End If
timer1.Initialize("timer1_Tick",2000) ' Lê o valor a cada 2 segundos
timer1.Enabled = True
End Sub
Sub Timer1_Tick
valorUmidade = sensorUmidadeSolo.AnalogRead
' Calcula o percentual de umidade
Dim percentualUmidade As UInt = Map(valorUmidade, valorSeco, valorMolhado, 0, 100)
percentualUmidade = Max(Min(percentualUmidade, 100), 0) ' Garante que o valor esteja entre 0 e 100
Log("Umidade do Solo: ", percentualUmidade, "%")
ssd.ClearDisplay
ssd.GFX.SetCursor(2,0)
ssd.GFX.ConfigureText(1,ssd.WHITE,False)
ssd.GFX.DrawText("IP:")
ssd.GFX.DrawText(wifi.LocalIp)
ssd.GFX.SetCursor(10,17)
ssd.GFX.ConfigureText(2,ssd.WHITE,False)
ssd.GFX.DrawText("U: ").DrawText(NumberFormat(percentualUmidade,0,0))
ssd.GFX.DrawText(" %")
ssd.Display
End Sub
'Função para mapear os valores
Sub Map(x As UInt, in_min As UInt, in_max As UInt, out_min As UInt, out_max As UInt) As UInt
Return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
End Sub