Interfacing sensors
The two sensors we will use in this project are fairly simple to interface with Arduino, as both use a simple digital signal. We will now look at the electrical connection between the sensors and Arduino and the configuration required in the Arduino code for each sensor.
In the code for the sensor nodes (the rf_network/SensorNode_Arduino
directory), there are two important variables related to the configuration of sensors on a given node: NUM_SENSORS
and sensors
. The first is a count of how many sensors are attached to the current sensor node and the second is an array of configurations for each sensor.
The configuration for each sensor is stored in a struct with the following initialization:
{"MQTT_TOPIC", PIN, ACTIVE_LOW, PULL_UP}
Here, MQTT_TOPIC
is the MQTT topic where the changes to the state of the sensor will be published, PIN
is the Arduino IO pin the sensor is connected to, and ACTIVE_LOW
shows whether the sensor should be considered as triggered when the input is...