The next battle we have to face as human is the food shortage. This has been already happened to some countries at alarming rates. The people are encouraged to plant edible crops in their home gardens by the government but the problem is with this busy urban life-style people do not have much time to watering and look after their beloved gardens. This can be a good candidate for automation?
With Nordic Thingy:53 I am planning to build the device called "Smart Gardner" to monitor the plantation and report back to the users with the current states of the garden via Bluetooth with "Smart Gardener Mobile App". Basically, Smart Gardner can monitor environment and adjust garden environment such as if there is too much dry it will water the plants.
How the Solution Works?Thingy:53 has all the environment sensors we need to do a better gardening without our presence. The Smart Gardener sensor the environment through it temperature and humidity and pressure sensors and initiate plant watering. The light sensor can also participate in the decision making process. This decision making process and be simple logic program or machine learning model with help of EdgeImpulse. All the works are done by the device will be monitor though the mobile App.
Let's Build with Me...First make the BLE controlled water pump.
The schematic for the device.
For the programming ESP32 you need to have Arduino IDE 2 and you need to install ESP32 into the Arduino IDE. Click here to get info for setting up your development environment. Once you have done the setup part you can use below code to test your Bluetooth powered water pump.
#include "BLEDevice.h"
#include <Wire.h>
#define bleServerName "Wio Micro Agro"
#define ONBOARD_LED 2
#define PUMP_PIN 3
static BLEUUID pumpServiceUUID("180f");
static BLEUUID pumpCharacteristicUUID("2a19");
static boolean doConnect = false;
static boolean connected = false;
static BLEAddress *pServerAddress;
static BLERemoteCharacteristic* pumpCharacteristic;
const uint8_t notificationOn[] = {0x1, 0x0};
const uint8_t notificationOff[] = {0x0, 0x0};
char* pumpChar;
boolean newPumpState = false;
bool connectToServer(BLEAddress pAddress) {
BLEClient* pClient = BLEDevice::createClient();
pClient->connect(pAddress);
Serial.println(" - Connected to server");
BLERemoteService* pRemoteService = pClient->getService(pumpServiceUUID);
if (pRemoteService == nullptr) {
Serial.print("Failed to find our service UUID: ");
Serial.println(pumpServiceUUID.toString().c_str());
return (false);
}
pumpCharacteristic = pRemoteService->getCharacteristic(pumpCharacteristicUUID);
if (pumpCharacteristic == nullptr) {
Serial.print("Failed to find our characteristic UUID");
return false;
}
Serial.println(" - Found our characteristics");
pumpCharacteristic->registerForNotify(pumpNotifyCallback);
return true;
}
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
if (advertisedDevice.getName() == bleServerName) {
advertisedDevice.getScan()->stop();
pServerAddress = new BLEAddress(advertisedDevice.getAddress());
doConnect = true;
Serial.println("Device found. Connecting!");
}
}
};
static void pumpNotifyCallback(BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData, size_t length, bool isNotify) {
pumpChar = (char*)pData;
newPumpState = true;
}
void setup() {
Serial.begin(115200);
Serial.println("Starting Arduino BLE Client application...");
BLEDevice::init("");
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
pBLEScan->start(30);
pinMode(ONBOARD_LED, OUTPUT);
pinMode(PUMP_PIN, OUTPUT);
}
void loop() {
if (doConnect == true) {
if (connectToServer(*pServerAddress)) {
Serial.println("We are now connected to the BLE Server.");
pumpCharacteristic->getDescriptor(BLEUUID((uint16_t)0x4545))->writeValue((uint8_t*)notificationOn, 2, true);
connected = true;
} else {
Serial.println("We have failed to connect to the server; Restart your device to scan for nearby BLE server again.");
}
doConnect = false;
}
std::string value = pumpCharacteristic->readValue();
Serial.print("Pump state by BLE server = ");
Serial.println(value.c_str());
if(value=="on"){
Serial.println("On");
digitalWrite(ONBOARD_LED, HIGH);
digitalWrite(PUMP_PIN, HIGH);
}
else{
Serial.println("Off");
digitalWrite(ONBOARD_LED, LOW);
digitalWrite(PUMP_PIN, LOW);
}
delay(1000);
}
I used the same water pump in my another project. It is so convenient if you have these kind of components already built. So I can use it for multiple projects.
Brief Intro About Thingy:53The Nordic Thingy:53™ is an easy-to-use IoT prototyping platform. It makes it possible to create prototypes and proofs-of-concept without building custom hardware. The Thingy:53 is built around the nRF5340 SoC, our flagship dual-core wireless SoC. The processing power and memory size of its dual Arm Cortex-M33 processors enables it to run embedded machine learning (ML) models directly on the device.
The best thing of the Thingy:53 is it's environmental sensors. In my project I am going to use the temperature and humidity sensors.
Let's Get the Sensor Readings from Thingy:53
Comments