Page 1 of 1

Measurement of dust&gas: controlled heating by ESP8266

Posted: Thursday 19 March 2020 14:56
by Toulon7559
Measurement of environmental dust and gasses like NO2 improves if dust & gas is flowing over the sensor at a constant temperature & humidity.
Difficult to achieve, but a simple, first approach seems to fan & funnel the air over the sensor through a tube which has heating at the entrance. Drying is most difficult, but heating must be possible, indirectly providing some drying.
For controlled heating at least need to know the temperature at the sensor.

Have in operation the basically needed elements as sensors GP2Y10 (for dust), MiCS6814 (for the gasses) and LM35 (for the temperature) on top of it, all read by the associated ESP8266&ESPEasy.
To be enclosed by the tube mentioned above.
Heating control may simply be by a relais switching the heaterpower under processor control, but big, 'blunt force' and not really power efficient.
Perhaps too detailled 'micro management', but more efficient seems to apply transistor-switching of the heater, and the ESP8266 has GPIO to perform that job, even proportional by means of the PWM-function in ESPEasy.
If the cooling-side of the power transistor is fitted to the tube, ;) even power 'lost' in the transistor can be applied.
With the PWM-function the power transistor may be applied in switch-mode or as emitter-follower, dependent on the type of primary power and on the type of heater.

Waiting for the heaters ordered from China presently means plenty of time to develop the related software.
See the code below for my setup:
- the data from the BME280 is applied to get the 'environmental' temperature & humidity, to determine whether it is meaningful to heat based on characteristics of incoming air.
Assumption: not useful if air temp >25 degrees and humidity <80%. If humidity > 90%, then heating may be some help at any temperature.
- the LM35 measures the temperature at the sensors, to determine whether still required to heat: 25~30 degrees seems sufficient.
Big overshoot should be prevented.
- Heater control is aimed at following approach:
# 'full blast' for < 0 degrees at the sensor
# proportional control between 0 and 25 degrees at the sensor
# no heating if temperature > 25 degrees at sensor, and humidity <90%
# burstwise heating if humidity >90% while temperature >25 degrees in the housing
# the timing of the control loop determines the accuracy & speed of heater control.
Experience will tell whether this approach is OK: software is easy to adapt ......

Code: Select all

-- Lua-script for info-upload to ESP8266_ESPEasy_LM35 for PWM to control heater
-- (c)2020 Toulon7559 rev. 00
print ('Start of PWM-script 00')
-- Line 04 = Inputs & Settings
House_Temp_RV = 'BME280_Temp_RV_Baro' -- from BME280 in Housing
LM35_Temp = 'ESP8266I_ADC0' -- Sensor-value near gassensor, with ADC ADS1115 set on full-scale = 1024 mV
-- If ADC of ESP8266_WEMOS is used, then ADC_full-scale is 3300mV on 1024bits and rescale is required!
Interval = 1; Offset = 0 -- settings in minutes for timing of script loop
GPIO = 13 -- GPIO of ESP8266 selected for PWM-signal output
-- Line 10 = Definition of function(s)
local function Round(num, idp)
   return tonumber(string.format("%." ..(idp or 0).. "f", num))
end

-- Line 15 = Define basic url for upload of PWM-command to ESP8266&ESPEasy
-- Basic command = PWM,<GPIO>,<state> or PWM,<GPIO>,<state>,<duration>
-- with <GPIO> 0...15, and <state> & <duration> 0...1024
-- <duration> causes fading expressed in ms
-- Example layout = http://<espeasyip>/control?cmd=PWM,13,500
baseurl = "http://192.168.0.140/control?cmd=PWM"

-- Line 22 = Extract current date&time as date.year, date.month, date.day, date.hour, date.min, date.sec
date = os.date("*t")
if (date.min % Interval == Offset) then
-- Line 25 = Call House-Info
    sTemp1, sRV1, sComfort1, sBaro1 = otherdevices_svalues[House_Temp_RV]:match("([^;]+);([^;]+);([^;]+);([^;]+)")
    sTemp1 = Round(tonumber(sTemp1),1);
    print ('Temp1 = '.. sTemp1)
    sRV1 = Round(tonumber(sRV1),1);
    print ('RV1 = '.. sRV1)
-- Line 31 = Read Gas-Temp
   sTemp2 = otherdevices_svalues[LM35_Temp]
   sTemp2 = tonumber(sTemp2) / 1  -- scaling to get value in degrees from ADC [see lines 06+07!]
   sTemp2 = Round(sTemp2,1)
   print ('GasTemp = '.. sTemp2)
-- Line 37 = Calculation of PWM-Setting for controlled heating
   if ((sTemp1 > 25) and (sRV1 < 90)) then
       State = 0 -- No heating & drying required
   else  -- Check on Temp
       if sTemp2 >= 25 then
           Factor = 0 -- No heating required
       end   
       if ((sTemp2 > 0) and (sTemp2 < 25)) then
           Factor = (25 - sTemp2)/25 -- Proportional heating
       end
       if sTemp2 <= 0 then
           Factor = 1 -- Full heating required
       end
   end
   State = 1024 * Factor; State = Round(State,0);
   print ('Factor = '..Factor.. ' => State    = '.. State)

-- Line 54 = Check on Humidity while High Temp & Compile upload-URL
   if ((sTemp1 > 25)  and (sRV1 > 90)) then
       State = 1024; Duration = 1024  -- For heating burst for drying
       UploadURL1 = baseurl .. ","..GPIO..",".. State .. "," .. Duration
   else
       UploadURL1 = baseurl .. ","..GPIO..",".. State
   end
   print (UploadURL1)
   print ('End of PWM-script 00')
end -- end of timed loop
-- Line 67 = Perform upload to ESP8266
commandArray = {}
-- in next line -- in front deactivates the upload; remove -- for upload-activation
-- commandArray['OpenURL']= UploadURL1

return commandArray