Elijah Maluleke
Published

Smart Water Tap Leakage Controller IoT Project

Loss of water through water taps that are either left unclosed is a problem. A Smart Water Tap Leakage Controller IoT Project is a solution.

AdvancedFull instructions provided710

Things used in this project

Hardware components

Nordic Thingy:53
Nordic Semiconductor Nordic Thingy:53
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
DC POWER JACK 2.1MM BARREL-TYPE PCB MOUNT
TaydaElectronics DC POWER JACK 2.1MM BARREL-TYPE PCB MOUNT
×1
USB Cable, USB Type C Plug
USB Cable, USB Type C Plug
×1
SparkFun USB Type A Female Breakout
SparkFun USB Type A Female Breakout
×1
Terminal Block Interface, Terminal Block
Terminal Block Interface, Terminal Block
×1
Electrolytic Capacitor, 10 µF
Electrolytic Capacitor, 10 µF
×1
Bipolar (BJT) Single Transistor, General Purpose Amplifiers/Switches
Bipolar (BJT) Single Transistor, General Purpose Amplifiers/Switches
×1
Resistor 1k ohm
Resistor 1k ohm
×2
Resistor 4.75k ohm
Resistor 4.75k ohm
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×4
1N4148 – General Purpose Fast Switching
1N4148 – General Purpose Fast Switching
×1
HKD G1/2IN WATER FLOW SOLENOID
×1

Software apps and online services

VS Code
Microsoft VS Code
nRF Connect SDK
Nordic Semiconductor nRF Connect SDK

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Mini Side Cutter, 120mm Length with 25mm Jaw Capacity
Mini Side Cutter, 120mm Length with 25mm Jaw Capacity
Plier, Long Nose
Plier, Long Nose
Soldering Iron Tip, Knife
Soldering Iron Tip, Knife
Premium Female/Male 'Extension' Jumper Wires, 40 x 3" (75mm)
Premium Female/Male 'Extension' Jumper Wires, 40 x 3" (75mm)

Story

Read more

Schematics

Smart Water Tap Leakage Controller IoT Project Fritzing

Fritzing Breadboard, Schematic and PCB files for production.

Code

Smart_Water_Tap_Leakage_Controller_IoT_Project

C/C++
main.c program is pasted on the below space and the other files have been uploaded as a zip folder.
/*
 * Copyright (c) 2021 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */
#include <app_event_manager.h>

#define MODULE main
#include <caf/events/module_state_event.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(MODULE);

/* */
#include <zephyr/zephyr.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>

/********************************************************************************
 *
 ********************************************************************************/
/* 1000 msec = 1 sec */
#define WATER_VALVE_PIN 4

/* 1000 msec = 1 sec */
#define MOTION_DETECTOR_PIN 5

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   1000

#define SLEEP_TIME_10M 10 * 60 * 1000

/* Option 1: by node label */
#define MY_GPIO0 DT_NODELABEL(gpio0)

// const struct device *gpio_dev;
const struct device *gpio_dev = DEVICE_DT_GET(MY_GPIO0);
//
struct k_timer my_timer;
//extern void my_expiry_function(struct k_timer *timer_id);

/********************************************************************************
 *
 ********************************************************************************/
/* STEP 4 - Define the callback function */
void motion_detected(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
	gpio_pin_set(gpio_dev, WATER_VALVE_PIN, true);
	// gpio_pin_toggle(gpio_dev, WATER_VALVE_PIN);
	/* start periodic timer that expires once every second */
	k_timer_start(&my_timer, K_SECONDS(50), K_NO_WAIT);
}

/* STEP 5 - Define a variable of type static struct gpio_callback */
static struct gpio_callback motion_cb_data;

void my_expiry_function(struct k_timer *timer_id) {
	gpio_pin_set(gpio_dev, WATER_VALVE_PIN, false);
}

/********************************************************************************
 *
 ********************************************************************************/
void main(void) {
	int ret;

	if (!device_is_ready(gpio_dev)) { /* Not ready, do not use */
		return;
	}

	ret = gpio_pin_configure(gpio_dev, WATER_VALVE_PIN, GPIO_OUTPUT_INACTIVE);
	if (ret < 0) {
		return;
	}

	ret = gpio_pin_configure(gpio_dev, MOTION_DETECTOR_PIN, GPIO_INPUT | GPIO_PULL_DOWN);
	if (ret < 0) {
		return;
	}

	/* STEP 3 - Configure the interrupt on the button's pin */
	ret = gpio_pin_interrupt_configure(gpio_dev, MOTION_DETECTOR_PIN, GPIO_INT_EDGE_TO_ACTIVE);
	if (ret < 0) {
		return;
	}

	/* STEP 6 - Initialize the static struct gpio_callback variable */
	gpio_init_callback(&motion_cb_data, motion_detected, BIT(5));

	/* STEP 7 - Add the callback function by calling gpio_add_callback() */
	gpio_add_callback(gpio_dev, &motion_cb_data);

	//
	k_timer_init(&my_timer, my_expiry_function, NULL);

	//
	if (app_event_manager_init())
	{
		LOG_ERR("Application Event Manager initialization failed");
	}
	else
	{
		module_set_state(MODULE_STATE_READY);
	}
}
  

Smart_Water_Tap_Leakage_Controller_IoT_Project.zip

C/C++
Zip folder containing the complete Zephry RTOS project
Binary file (no preview)  

Credits

Elijah Maluleke

Elijah Maluleke

2 projects • 1 follower

Comments

Add projectSign up / Login