![Image](https://hobbycomponents.com/images/forum/ESP8266/HCDVBD0045/HCDVBD0045_1_1024.jpg)
![](https://hobbycomponents.com/images/forum/forum/Description.png)
Arduino library for Hobby Components ESP home sensor module. This library currently supports the following product(s):
Hobby Components ESP Home Sensor (SKU: HCDVBD0045)
Using the library
Step 1) Downloading the library
Download the latest ESPHomeSensor_Vx_x.zip library from the following link.
https://hobbycomponents.com/downloads/E ... r_V0_1.zip
Save it to somewhere convenient on your computer.
Step 2) Installing the Library
Once downloaded, open up your Arduino IDE and go to Sketch->Include Library->Add .ZIP Library.
In the file selection dialogue window that opens up, navigate to wherever you downloaded the ESPHomeSensor_Vx_x.zip file and select it, then click the ‘Open’ button.
Alternatively you can just unzip the library into your Arduino library folder usually found in the following location:
On Windows:
My Documents\Arduino\libraries\
On Mac:
Documents/Arduino/libraries/
Linux:
Usually found within the users home area under /Arduino/libraries/
Step 3) Including the library in your sketch
Adding the library to your sketch consists of 3 steps; Firstly, include the ESPHomeSensorheader file (ESPHomeSensor.h) at the top of your sketch, create an instance of the library, then finally initialise the library inside the startup() function:
- // Step 1: Include the mLink library
- #include "ESPHomeSensor.h"
- //Step 2: Create an instance of the library
- ESPHS ESPHS;
- void setup()
- {
- // Step 3: Initialise the library
- ESPHS.init(EN_PIR_INTERRUPT);
- }
- void loop()
- {
- }
ESPHomeSensor Library Functions:
ESPHS.init(mode);
Initialises the library where:
mode specifies the interrupt mode for the PIR sensor. Valid values for mode are:
DIS_PIR_INTERRUPT Interrupt on PIR pin disabled
EN_PIR_INTERRUPT Interrupt on PIR pin enabled, PIR LED automatically reflects PIR state
EN_PIR_INTERRUPT_DISLED Interrupt on PIR pin enabled, PIR LED manually controlled
Returns: void
ESPHS.DHTRead(void);
Triggers a read of the temperature and humidity sensor
Returns:
A boolean value specifying of the read was successful where:
0 (false) = Read failed
1 (true) = Read was successful
Notes:
If the read was successful the values for temperature and humidity
can be then read with the following library functions
fDHTTemp(); AND
fDHTHum();
Due to the way the DHT2 sensor works subsequent reads should be performed
no sooner than 2 seconds apart.
ESPHS.DHTTemp(void);
Returns the current temperature in oC
Returns:
A signed integer representing the temperature in 10th's of a oC.
I.e to get the temperature in oC to 1 decimal place divide the returned value by 10
Notes:
To get the current temperature you must first run the DHTRead() library function
ESPHS.DHTHum(void);
Returns the current humidity in %RH
Returns:
A signed integer representing the humidity in 10th's of a %RH.
I.e to get the humidity in %RH to 1 decimal place divide the returned value by 10
Notes:
To get the current humidity you must first run the DHTRead() library function
ESPHS.fDHTTemp(void);
Returns the current temperature in oC
Returns:
A a floating point value representing the temperature in oC to 1 decimal place.
Notes:
To get the current temperature you must first run the DHTRead() library function
ESPHS.fDHTHum(void);
Returns the current relative humidity in %RH
Returns:
A a floating point value representing the humidity in %RH to 1 decimal place.
Notes:
To get the current humidity you must first run the DHTRead() library function
ESPHS.LDRRead(void);
Reads the LDR via the ADC pin
Returns:
An unsigned int representing the light level sensed by the LDR where
0 = dark
1023 = max light
ESPHS.PIRRead(void);
Reads the current state of the PIR sensor
Returns:
A boolean value representing the state of the sensor where
0 (false) = not triggered
1 (true) = triggered
Notes:
When the PIR is triggered this value will stay high for ~4 seconds
ESPHS.PIRTrigs(void);
Returns the amount of times the PIR has been triggered since last reset where:
Returns:
An unsigned 16 bit value representing the number of time the PIR has been triggere.
Notes:
For the trigger counter to work the library must be initialised with PIR interrupt enabled. E.g.
ESPHS.init(EN_PIR_INTERRUPT); OR
ESPHS.init(EN_PIR_INTERRUPT_DISLED);
When the counter reaches a maximum value of 65534 the counter will no longer continue to increment.
This counter can be reset using the PIRTrigsReset() function
ESPHS.PIRTrigsReset(void);
Sets the PIR trigger counter back to zero.
Returns: void
ESPHS.ledState(boolean state);
Sets the state of the PIR LED where:
high = ON
low = OFF
Returns: void
Diagrams, libraries, and example code are provided as an additional free service by Hobby Components and are not sold as part of this product. We do no provide any guarantees or warranties as to their accuracy or fitness for purpose.
Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.