Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Abhinav Krishna
Published

WasteSense: A Next-Gen Waste Monitoring System

WasteSense optimizes waste management using nRF7002 DK, integrating real-time monitoring using Matter protocol for enhanced efficiency

IntermediateWork in progressOver 4 days338
WasteSense: A Next-Gen Waste Monitoring System

Things used in this project

Hardware components

nRF7002 Development Kit
Nordic Semiconductor nRF7002 Development Kit
The main controller board responsible for communication and data processing
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Mounted in waste bins for detecting waste levels
×1
TinyShield GPS
TinyCircuits TinyShield GPS
Enables geolocation tracking for waste bins, aiding in route optimization
×1
Solar Panel, 2.5 W
Solar Panel, 2.5 W
Power source for sustainability, reducing reliance on external power supplies
×1
Solar Power Manager 5V
DFRobot Solar Power Manager 5V
×1
nRF52840 Dongle
Nordic Semiconductor nRF52840 Dongle
×1
LED (generic)
LED (generic)
×2
Resistor 330 ohm
Resistor 330 ohm
×2
Nextion NX4827T043 - 4.3” TFT LCD Intelligent Touch Display
Itead Nextion NX4827T043 - 4.3” TFT LCD Intelligent Touch Display
×1
Rechargeable Battery, Lithium Ion
Rechargeable Battery, Lithium Ion
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

VS Code
Microsoft VS Code
nRF Connect SDK
Nordic Semiconductor nRF Connect SDK
Arduino IDE
Arduino IDE
Fusion
Autodesk Fusion

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Custom parts and enclosures

Casing for the device

Casing

Casing

side view

Casing

side view

BASE CODE

Schematics

Block diagram

nrf7002dk

Circuit

Code

BASE CODE

C/C++
#include "app_task.h"
#include "led_util.h"

#include <hal/nrf_gpio.h>
#include <zephyr.h>

//////////////////////////////////////////
#include <ultrasonic_driver.h>
#define ULTRASONIC_TRIGGER_PIN 32
#define ULTRASONIC_ECHO_PIN 31

#define LED_PIN 13
#define BUZZER_PIN 14
#define THRESHOLD_DISTANCE 30 // Placeholder value, replace with your actual threshold

#define ULTRASONIC_TRIGGER_BUTTON 20
#define ULTRASONIC_TRIGGER_BUTTON_MASK (1U << ULTRASONIC_TRIGGER_BUTTON)
//////////////////////////////////////////

using namespace ::chip;
using namespace ::chip::app;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;

namespace
{
    UltrasonicDriver ultrasonic(ULTRASONIC_TRIGGER_PIN, ULTRASONIC_ECHO_PIN);
    LEDWidget sAlertLED;
    Buzzer sAlertBuzzer;

    bool sAlertActive = false;
} /* namespace */

CHIP_ERROR AppTask::Init()
{
    /* ... Existing code ... */

    /* Initialize LEDs and Buzzer */
    sAlertLED.Init(LED_PIN);
    sAlertBuzzer.Init(BUZZER_PIN);

    /* ... Existing code ... */
}

void AppTask::UltrasonicSensorEventHandler()
{
    const uint16_t distance = ultrasonic.GetDistance();

    if (distance < THRESHOLD_DISTANCE)
    {
        if (!sAlertActive)
        {
            sAlertActive = true;

            // Trigger alert (LED blinking and buzzer)
            sAlertLED.Blink(500, 500); // Blinking pattern
            sAlertBuzzer.Start(1000);  // Start buzzing with a frequency of 1000 Hz
        }
    }
    else
    {
        if (sAlertActive)
        {
            sAlertActive = false;

            // Clear alert (stop LED and buzzer)
            sAlertLED.Set(false);   // Turn off LED
            sAlertBuzzer.Stop();    // Stop buzzing
        }
    }
}

CHIP_ERROR AppTask::StartApp()
{
    ReturnErrorOnFailure(Init());

    AppEvent event = {};

    while (true)
    {
        k_msgq_get(&sAppEventQueue, &event, K_FOREVER);
        DispatchEvent(event);

        // Add Ultrasonic Sensor event handling
        if (event.Type == AppEventType::UltrasonicSensor)
        {
            UltrasonicSensorEventHandler();
        }
    }

    return CHIP_NO_ERROR;
}

void AppTask::ButtonEventHandler(uint32_t buttonState, uint32_t hasChanged)
{
    AppEvent button_event;
    button_event.Type = AppEventType::Button;

    // ... Existing button handling code ...

    // Add handling for a new button (e.g., ULTRASONIC_TRIGGER_BUTTON)
    if (ULTRASONIC_TRIGGER_BUTTON_MASK & buttonState & hasChanged)
    {
        button_event.ButtonEvent.PinNo = ULTRASONIC_TRIGGER_BUTTON;
        button_event.ButtonEvent.Action =
            static_cast<uint8_t>((ULTRASONIC_TRIGGER_BUTTON_MASK & buttonState) ? AppEventType::ButtonPushed :
                                                                                   AppEventType::ButtonReleased);
        button_event.Handler = UltrasonicTriggerButtonHandler;
        PostEvent(button_event);
    }

    // ... Existing button handling code ...
}

void AppTask::UltrasonicTriggerButtonHandler(const AppEvent &event)
{
    if (event.ButtonEvent.PinNo != ULTRASONIC_TRIGGER_BUTTON)
    {
        return;
    }

    if (event.ButtonEvent.Action == static_cast<uint8_t>(AppEventType::ButtonPushed))
    {
        // Trigger Ultrasonic Sensor event
        AppEvent ultrasonic_event;
        ultrasonic_event.Type = AppEventType::UltrasonicSensor;
        PostEvent(ultrasonic_event);
    }
    // Add other button handling logic if needed
}

Credits

Abhinav Krishna
5 projects • 27 followers
Maker | IoT Enthusiast | Electronics hobbyist

Comments