Sensor Module #2 - Tutorial
The second sensing module is a fun little package of environmental sensing which includes temperature, humidity and photodiode(Lux) sensing.
From our previous three lessons, we have worked to combine these three sensors into a neat little board that provides easy plug and play into the carrier board.
https://spaceops.com.au/education/microbit-picosat-series-prototyping-board-temperature-sensor
https://spaceops.com.au/education/microbit-prototyping-module-humidity-sensor
https://spaceops.com.au/education/microbit-picosat-series-sensor-module-1-humidity-sensor
The value of humidity is dependant on the temperature. The light levels are independant of both meaning, the light levels are not affected by the environments temperature and humidity.
We have included code below the image to allow for fast setup.
//Space Ops Australia Pty Ltd //code for Sensor Module #2 //temperature, humidity and photodiode sensors. let temperature = 0 let H = 0 let rho = 0 let coeffC = 0 let coeffB = 0 let coeffA = 0 let R = 0 let logR = 0 let logH = 0 let T = input.temperature() let R1 = 150000 let lux = 0; let Rhumidity = 0; let rho_humidity = 0; let Rlux = 39000; // the circuits inbuilt resistor basic.forever(function () { basic.pause(5000) temperature = Math.round((pins.analogReadPin(AnalogPin.P0) * 0.002932 - 0.5) / 0.01) serial.writeValue("temp", temperature) //basic.showString("" + temperature) coeffA = 0 * temperature - 0.0052 coeffB = -0.0013 * temperature - 0.0209 coeffC = 0.0061 * temperature + 5.06 rho = pins.analogReadPin(AnalogPin.P1) / 1023 R = R1 * rho / (1 - rho) logR = Math.log(R); logH = coeffA * logR ** 2 + coeffB * logR + coeffC H = Math.round(10 * Math.exp(logH)) / 10 serial.writeValue("Relative Humidity (%)", H) //basic.showString("H:" + Math.round(H) + "%") rho_humidity = pins.analogReadPin(AnalogPin.P2) / 1023; //find the sensor voltage proportional to input voltage Rhumidity = Rlux * rho_humidity / (1 - rho_humidity); // calculate the resistance of the humidity sensor lux = Math.exp(-0.7925 * Math.log(Rhumidity) + 12.43); // formula to calculate value of lumens based on the resistance measured. serial.writeValue("Lux (Lumens)", lux) //print the value of lumens after calculation basic.showString("T:" + temperature + " H:" + Math.round(H) + "% " + "L:" + Math.round(lux)) })