element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Connected Cloud Challenge
  • Challenges & Projects
  • Design Challenges
  • Connected Cloud Challenge
  • More
  • Cancel
Connected Cloud Challenge
Blog #12 Water Dispenser with auto stop function
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: wanfp97
  • Date Created: 25 May 2020 2:48 PM Date Created
  • Views 2341 views
  • Likes 2 likes
  • Comments 0 comments
  • psoc 6
  • cypress semiconductor
Related
Recommended

#12 Water Dispenser with auto stop function

wanfp97
wanfp97
25 May 2020

I have made some modification on the coding that I have used in my previous blogpost #11 Water sensor calibration so that the water dispenser will stop automaticly when the water level reaches the calibrated level.

 

BOM: PSoC6 WiFi-BT Prototyping Kit, a water pump, two 18650 battery, 18650 battery socket, 2 N-channel MOSFET, a push button, a buzzer, a red led, a green LED, 6x 10k ohm potentiometers, some jumper wires, a bread board, a water pump and hose, a 1.5L water bottle, a 500ml water bottle, bendable steel wire, a plastic tray, hot glue gun and glue sticks.

 

GitHub: https://github.com/wanfp97/PSoC6-Auto-Cutt-off-Water-Dispenser

 

Coding:

#include "cy_pdl.h" // include Peripheral Driver Library
#include "cyhal.h" // include Hardware Abstraction Layer library
#include "cycfg.h" // include device configurator library
/*******************************************************************************
* Function Prototypes
********************************************************************************/
static void button_intr_handler(void *handler_arg, cyhal_gpio_event_t event);
static void wtr_sense_intr_handler(void *handler_arg, cyhal_gpio_event_t event);
/*******************************************************************************
* Global Variables
********************************************************************************/
volatile bool button_intr_flag = false; // Boolean type variable to store the interrupt flag
volatile bool wtr_sense_intr_flag = false; // Boolean type variable to store the interrupt flag
int main(void)
{
    init_cycfg_all(); // configure pins as done in Device Configurator
    __enable_irq(); // enable interrupt
    cyhal_gpio_register_callback(button_HAL_PORT_PIN,
                                 button_intr_handler, NULL); // assigning isr handler for button
    cyhal_gpio_enable_event(button_HAL_PORT_PIN, CYHAL_GPIO_IRQ_RISE,
                                 1u, true); // interrupt on rising edge (button pressed)
    cyhal_gpio_register_callback(wtr_sense_HAL_PORT_PIN,
                                 wtr_sense_intr_handler, NULL); // assigning isr handler for water sensor
    cyhal_gpio_enable_event(wtr_sense_HAL_PORT_PIN, CYHAL_GPIO_IRQ_FALL,
                                 1u, true); // interrupt on falling edge (water level high)
    for (;;)
    {
     if (true == button_intr_flag) // if interrupt happens (button pressed)
     {
         button_intr_flag = false; // clear interrupt flag for further interrupt
         if(Cy_GPIO_ReadOut(water_pump_PORT, water_pump_NUM)==0UL)
         {
          Cy_GPIO_Write(green_PORT, green_NUM, 1UL); // green LED on
          Cy_GPIO_Write(water_pump_PORT, water_pump_NUM, 1UL); // on water pump
         }
         else
         {
          Cy_GPIO_Write(green_PORT, green_NUM, 0UL); // green LED off
          Cy_GPIO_Write(water_pump_PORT, water_pump_NUM, 0UL); // off water pump
         }
     }
     else;
     if(0UL == Cy_GPIO_Read(wtr_sense_PORT, wtr_sense_NUM))
  {
         Cy_GPIO_Write(red_PORT, red_NUM, 1UL); // red LED on
         Cy_GPIO_Write(green_PORT, green_NUM, 0UL); // green LED off
         Cy_GPIO_Write(water_pump_PORT, water_pump_NUM, 0UL); // off water pump
  }
     else
     {
         Cy_GPIO_Write(red_PORT, red_NUM, 0UL); // red LED off
     }
     if( true == wtr_sense_intr_flag) // buzzer on for 0.5s
     {
         Cy_GPIO_Write(buzzer_PORT, buzzer_NUM, 1UL); // buzzer on
         cyhal_system_delay_ms(100); // delay 100 ms
         Cy_GPIO_Write(buzzer_PORT, buzzer_NUM, 0UL); // buzzer off
         wtr_sense_intr_flag = false;
     }
    }
}
/*******************************************************************************
* Function Name: button_intr_handler
********************************************************************************
* Summary:
*   button GPIO interrupt handler.
*
* Parameters:
*  void *handler_arg (unused)
*  cyhal_gpio_irq_event_t (unused)
*
*******************************************************************************/
static void button_intr_handler(void *handler_arg, cyhal_gpio_irq_event_t event)
{
    button_intr_flag = true;
}
/*******************************************************************************
* Function Name: wtr_sense_intr_handler
********************************************************************************
* Summary:
*   water sensor GPIO interrupt handler.
*
* Parameters:
*  void *handler_arg (unused)
*  cyhal_gpio_irq_event_t (unused)
*
*******************************************************************************/
static void wtr_sense_intr_handler(void *handler_arg, cyhal_gpio_irq_event_t event)
{
    wtr_sense_intr_flag = true;
}

 

Water Dispenser operation video:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube