Greenhouse Temperature and Humidity Monitor.

Place your projects here
Post Reply
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 120 times
Been thanked: 132 times

Greenhouse Temperature and Humidity Monitor.

Post by AndyGadget »

This is the sensing and transmit side of a monitor for my greenhouse which transmits internal and external temperature and humidity values to ThingSpeak as well as atmospheric pressure, battery voltage and signal strength. This data is picked up by a display module in the house which I'll post details of separately.
See the data feed at https://thingspeak.com/channels/1283507

The sensor module uses an ESP32 TTGO display module with the display removed (as I couldn't get it to work with Annex) which is an excellent compact device with LIPO charge control, 2 on-board buttons and a very low sleep current of 120uA. Also in the 3D printed case is a BME280 module with another in a small case mounted on the outside of the greenhouse. I've put the 3D case designs on Thingiverse at https://www.thingiverse.com/thing:4857472 .

The sensor is around 30 metres from the AP in the house (by a window behind the tree in the photo) and I found the PCB antenna barely adequate so I cut the antenna track and soldered on a spare 2.4GHz stick antenna which give a much better signal.

The BME280 modules take a couple of milliamps which I didn't want as a constant battery drain so they are powered from ESP32 output pins and only activated when the ESP32 is awake. The wake / sense / transmit cycle takes around 8 seconds before the next sleep. The unit uses a 900mAh mobile phone li-ion battery which lasts about 3 months between recharges.

Code: [Local Link Removed for Guests]

' *********************************
' Temperature and Humidity Monitor.
' *********************************

pause 50
Dbg = 0                ' Set to 1 for debug mode
' Debug mode pauses for 15 seconds between measurements instead of sleeping for 10 minutes.
' Can also be entered by holding either of the on-board buttons on power-up. 

' Pin assignments
I2C.SETUP 13,15
pin.mode 12, output
pin.mode 2, output
pin.mode 32, output
pin(12) = 1
pin(2) = 1
pin(32) = 1

pin.mode 0, input, pullup
pin.mode 35, input, pullup

if (pin(0) = 0) or (pin(35) = 0) then Dbg = 1

' Required, otherwise Tidy function throws an error
TmpE$ = "" : HumE$ = "" : PreE$ = ""
TmpI$ = "" : HumI$ = "" : PreI$ = ""
VBatt$ = "" 

I2C.SETUP 13,15
API_KEY$ = "YourKeyHere"
TSpeak$ = "54.88.253.164/update?api_key=" + API_KEY$

if Dbg = 0 then
  option.WDT 60000
end if


' MAIN SECTION
' ============

do
  gosub GetBatteryVoltage
  gosub GetIntTPH
  gosub GetExtTPH
  gosub SendThingSpeak
  
  if Dbg = 1 then
  wlog
    wlog "Wifi    : " + RSSI$
    wlog "Batt    :  " + VBatt$
    wlog "Temp  :  " + TmpI$ + chr$(9) + TmpE$
    wlog "Hum   :  " + HumI$ + chr$(9) + HumE$
    wlog "Press :  " + PreI$ + chr$(9) + PreE$ + chr$(13)
  end if
  
  ' Go back to sleep for 10 minutes
  if Dbg = 0 then
    print "Going to sleep"
    wifi.sleep
    pause 20
    OPTION.CPUFREQ 80
    sleep 600 '  10 minutes
  else
    pause 15000
  end if
loop

' End of main Section
' ===================


GetBatteryVoltage:
'=====================
V1 = adc(34)
wlog V1
VBatt = int(V1 * 3.3/2048 * 1.068 * 10) /10
Tidy1  VBatt, VBatt$

RSSI$ = str$(100+wifi.rssi)
return

GetIntTPH:
'===============
if bme280.setup(&h76) = 0 then wlog "Int. BME280 error"

TmpI = bme280.temp
HumI = bme280.hum
PreI = bme280.qfe + 21

Tidy1 TmpI, TmpI$
Tidy0 HumI, HumI$
Tidy0 PreI, PreI$
return

GetExtTPH:
'===============
if bme280.setup(&h77) = 0 then wlog "Ext. BME280 error"

TmpE = bme280.temp
HumE= bme280.hum
PreE = bme280.qfe + 21

Tidy1 TmpE, TmpE$
Tidy0 HumE, HumE$
Tidy0 PreE, PreE$
return

SendThingspeak:
'==============
TSSend$ = TSpeak$+"&field1="+VBatt$+"&field2="+RSSI$+"&field3="+PreE$+"&field4="+TmpI$+"&field5="+HumI$+"&field6="+TmpE$+"&field7="+HumE$
TSRet$ = WGET$(TSSend$, 80)
if val(TSRet$) = 0 then wlog "TS error" + TSRet$
return

SUB Tidy0(x,R$)
' Tidy and round
  r$ = str$(cint(x))
end sub

SUB Tidy1(x,R$)
' Tidy to 1 decimal place
  r$ = str$(cint(x * 10) /10 , "%2.1f")
end sub
You do not have the required permissions to view the files attached to this post.
Last edited by AndyGadget on Thu May 13, 2021 10:51 am, edited 2 times in total.
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1269 times
Contact:

Re: Greenhouse Temperature and Humidity Monitor.

Post by cicciocb »

HI Andy,
thanks for sharing your nice project.
Post Reply