Board Parameters
board_parameters.h
// env.h Header File for general configuration.
// OPERATING MODE
// Operating mode will be 'D' (Development) or "P" (Production)
// This is mainly because we are using the TX and RX pins to connect a sensor
// and all Serial.println commands need to be stopped.
// During dev they can be used by temporarily disconnecting the sensor on the TX/RX pins.
#define OPERATING_MODE 'D'
// SENSOR PROCESSING SEQUENCE
#define DHT_SENSOR 1
#define GAS_SENSOR 2
#define SOUND_SENSOR 3
#define AMBIENT_LIGHT_SENSOR 4
#define SOIL_MOISTURE_SENSOR 5
#define ULTRASONIC_DISTANCE_SENSOR 6
#define PIR_MOTION_SENSOR 7
#define RTC_TIME 8
// GLOBAL CONSTANTS
#define LIGHT_RELAY 1
#define PUMP_RELAY 2
// PIN DEFINITIONS
// Since we are using the default TX/RX pins for a sensor
// we need to disconnect sensor when uploading code.
// Also we cannot use Serial.println when the sensor is connected.
#define SOIL_MOISTURE_SENSOR_POWER_PIN 0
#define SOIL_MOISTURE_SENSOR_DIGITAL_PIN 1 // Disconnect sensor when uploading code.
#define DHT_PIN 2
#define PIR_MOTION_SENSOR_PIN 3 // Needs to be an interrupt pin.
#define GAS_SENSOR_DIGITAL_PIN 4
#define SERVO_PIN 5 // Need to be a PWM pin
#define BUZZER_PIN 6
#define LIGHT_RELAY_PIN 7
#define PUMP_RELAY_PIN 8
#define RED_LED_PIN 9 // Need to be a PWM pin
#define GREEN_LED_PIN 10 // Need to be a PWM pin
#define BLUE_LED_PIN 11 // Need to be a PWM pin
#define ULTRASOUND_SENSOR_ECHO_PIN 12
#define ULTRASOUND_SENSOR_TRIGGER_PIN 13
#define SOUND_SENSOR_PIN A0
#define AMBIENT_LIGHT_SENSOR_ANALOG_PIN A1
#define AMBIENT_LIGHT_SENSOR_DIGITAL_PIN 16 // A2 being used a digital pin.
#define SOIL_MOISTURE_SENSOR_ANALOG_PIN A3
// A4 and A5 are the SDA and SCL pins respectively used for the I2C LCD.
// MQTT PARAMETERS
// BROKER CONFIG
// Cloud MQTT
/*
const char* MQTT_SERVER = "m13.cloudmqtt.com";
const int MQTT_PORT = 19034; //Use the TCP port, not the WebSocket port which is used in the app
const char* MQTT_USER = "tfzpyakl";
const char* MQTT_PASSWORD = "9-McjdgBOLnB";
*/
// HiveMQ
const char* MQTT_SERVER = "broker.hivemq.com";
const int MQTT_PORT = 1883; //Use the TCP port, not the WebSocket port which is used in the app
const char* MQTT_USER = "";
const char* MQTT_PASSWORD = "";
// The board name will be used as the BLE peripheral name (with spaces if desired).
// The same board name will be used as a topic prefix with all small and spaces removed.
// Thus, if multiple boards are used, each board will have a different topic on the MQTT broker.
// There will be two topics for each board:
// one for sensor data and one for control signals (similar to services in BLE).
// Topics should ideally be named with the following convention:
// boardname.sensor.data: The board will publish to this topic and the app will subscribe to it.
// boardname.control.signals: The app will publish to this topic and the board will subscribe to it.
const char* SENSOR_DATA_TOPIC = "arduinoekr4.sensor.data";
const char* CONTROL_SIGNALS_TOPIC = "arduinoekr4.control.signals";
// BLE CONFIG
// Peripheral name is the baord name.
#define PERIPHERAL_NAME "Arduino Ek R4"
// BLE UUIDS
// Service and characteristic UUIDs are created for each BLE central (the IoT App in this case)
// with which this peripheral communicates. Create the UUIDs on the app and copy them here.
// The name is just a variable name, does not have to be the same as the sensor or device name.
// Only the UUIDs have to match exactly.
// Number of services and characteristics per service are both limited to 7
// A characteristic value can be up to 512 bytes long.
// SERVICE UUIDS
// There will be 2 services, one for sending sensor data and one for receiving control signals.
#define SENSOR_DATA_SERVICE_UUID "b6039853-39c0-4486-8d6e-b410c345b9ed"
#define CONTROL_SIGNAL_SERVICE_UUID "ead0e35a-fe0f-4765-992b-45b349367358"
// CHARACTERISTIC UUIDS
// One characteristic for each sensor and device.
// SENSOR CHARACTERISTICS (limit to 7 per service)
#define TEMPERATURE_CHARACTERISTIC_UUID "2e98fdd6-26df-416f-b0ed-e31feb44042c"
#define HUMIDITY_CHARACTERISTIC_UUID "086e29c8-9c07-4a16-9a49-69eaf718d70e"
#define HEAT_INDEX_CHARACTERISTIC_UUID ""
#define GAS_CHARACTERISTIC_UUID "5eba607e-8e83-4785-97e1-ee56fb0d8e72"
#define SOUND_CHARACTERISTIC_UUID ""
#define SOIL_MOISTURE_CHARACTERISTIC_UUID "4889019c-2725-4ade-8248-28548d2f820e"
#define AMBIENT_LIGHT_CHARACTERISTIC_UUID "045c6ab5-7837-4d71-8179-fd8127e267e5"
#define DISTANCE_CHARACTERISTIC_UUID "d950d945-f9d4-4ad9-8669-2f81dafa09f4"
#define MOTION_CHARACTERISTIC_UUID "ff4aa668-a29d-421e-be43-f6958a1d34f4"
// DEVICE CHARACTERISTICS (limit to 7 per service)
// Thie two switch characteristics will take a binary input from the app.
#define LIGHT_SWITCH_CHARACTERISTIC_UUID "cfaf0d90-a9f9-4a05-9b33-8bffe2627332"
#define PUMP_SWITCH_CHARACTERISTIC_UUID "fee31455-b9b8-474b-882b-d21d89707fc6"
// The servo characteristic will take an analog input from the app and
// move the servo to the degree selected.
#define SERVO_MOVEMENT_CHARACTERISTIC_UUID "5862dbd4-6283-4187-8e3c-fe73b03bf46c"
// GLOBAL VARIABLES
// Connection status for WiFi and BLE.
// The board can connect and send data via both BLE and MQTT. The IoT App should read only either one.
bool is_wifi_connected = false;
bool is_ble_connected = false;
// Are light and pump on (to toggle with sound or to display status)
bool is_light_on = false;
bool is_pump_on = false;
// If the sensor reads data based on an interrupt it uses an ISR
// An ISR cannot return a value to this sketch, nor can it print to LCD.
// We will use global variables that the ISR will set
// and the main sketch will process those values in the loop.
// Text to be displayed on the LCD.
// In the main loop write this string if not empty.
String lcd_text = "";
uint8_t lcd_row = 0;
// PIR Motion sensor value (read by an ISR)
uint8_t pir_motion_sensor_value = 0;
// GLOBAL structs
// Any custom data types like structs must be declared globally so they can be used anywhere.
// For the DHT sensor which returns three values.
struct structDHTData {
float temperature;
float humidity;
float heat_index;
};
// For any sensor that returns two value, one digital, one analog.
struct structDigitalAnalogValues {
uint8_t digital_value;
uint8_t analog_value;
};