Shinji
Published © GPL3+

The HANIWA: Timeless yet Cutting-edge Irrigatable Scarecrow

A Pico W hub turning Cloud-AI forecast and Edge-AI security into soil alerts via an ancient statue's eye.

IntermediateProtip24 hours36
The HANIWA: Timeless yet Cutting-edge Irrigatable Scarecrow

Things used in this project

Hardware components

Raspberry Pi Pico 2
Raspberry Pi Pico 2
I used Raspberry Pi Pico 2 WH.
×1
Grove - Capacitive Soil Moisture Sensor
Seeed Studio Grove - Capacitive Soil Moisture Sensor
I used B07MC9ZGXL from "DIY Studio."
×1
Resistor 220 ohm
Resistor 220 ohm
×4
LED (generic)
LED (generic)
×3

Software apps and online services

VS Code
Microsoft VS Code

Story

Read more

Schematics

Connect LEDs and Moisture Sensor

Photo of the breadboard connecting LEDs and a moisture sensor to Raspberry Pi Pico 2 W.

Code

Test: CMakeLists for USB Serial Communication

C/C++
CMakeLists.txt for Testing USB Serial Communication
cmake_minimum_required(VERSION 3.13)

# Import SDK
include(pico_sdk_import.cmake)

# Using not Pico but Pico 2 (RP2350)
set(PICO_BOARD pico2)

project(haniwa_monitor C CXX ASM)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

pico_sdk_init()

# Define file names
add_executable(haniwa_monitor
    haniwa_monitor.cpp 
)

# Library link to use blinking LED
target_link_libraries(haniwa_monitor
    pico_stdlib
    hardware_adc
)

# Enable USB output, disable UART output
pico_enable_stdio_usb(haniwa_monitor 1)
pico_enable_stdio_uart(haniwa_monitor 0)

# Activate generating .uf2 file
pico_add_extra_outputs(haniwa_monitor)

Test: LEDs and Moisture Sensor

C/C++
The code for testing my handmade circuit with LEDs and a soil moisture sensor
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "hardware/adc.h"

// Define constants
const uint LED_RED   = 13;
const uint LED_GREEN = 14;
const uint LED_BLUE  = 15;
const uint SENSOR_VCC = 22;

void blink_led(uint gpio, int duration_sec) {
    // 1 cycle = 1 second (0.5s ON + 0.5s OFF)
    // Simply loop 'duration_sec' times to blink for that many seconds.
    for (int i = 0; i < duration_sec; i++) {
        gpio_put(gpio, 1); // ON
        sleep_ms(500);
        gpio_put(gpio, 0); // OFF
        sleep_ms(500);
    }
}

int main() {
    // Initialize all of the SDK
    stdio_init_all();

    // Initialize LED pins
    const uint leds[] = {LED_RED, LED_GREEN, LED_BLUE};
    for (uint led : leds) {
        gpio_init(led);
        gpio_set_dir(led, GPIO_OUT);
    }

    // Initialize Soil Moisture Sensor pins
    gpio_init(SENSOR_VCC);
    gpio_set_dir(SENSOR_VCC, GPIO_OUT);

    // Initialize Analog-to-Digital Converter
    adc_init();
    adc_gpio_init(26);
    adc_select_input(0);

    while(true){
        // VCC ON
        gpio_put(SENSOR_VCC, 1);
        sleep_ms(50);

        // Print data to the PC terminal
        uint16_t reading = adc_read();
        printf("Soil Moisture: %d\n", reading);

        // VCC OFF
        gpio_put(SENSOR_VCC, 0);

        // Blinking LEDs of RGB
        blink_led(LED_RED, 3);
        blink_led(LED_GREEN, 3);
        blink_led(LED_BLUE, 3);
    }

}

SharedMemory

Python
Explain using shared memory for a real-time backend processing
from multiprocessing import shared_memory

# The unique identifier for our inter-process communication
SHM_NAME = "memories_of_haniwa_garden"
SHM_SIZE = 8 # Enough space for our status flags

# Logic to initialize the shared memory segment
try:
  # 'DrWadachi' (Main Service) creates the memory block
  shm = shared_memory.SharedMemory(name=SHM_NAME, create=True, size=SHM_SIZE)
  print("Shared Memory created.")
  except FileExistsError:
  # If the block exists from a previous run, we simply attach to it
  shm = shared_memory.SharedMemory(name=SHM_NAME)
  print("Attached to existing Shared Memory.")

# Now, any process can access the data via shm.buf
# e.g., shm.buf[0] = 1 (Person detected!)

haniwa-hybrid

Timeless yet Cutting-edge Terracotta Irrigation and Smart Scarecrow Hybrid System

Credits

Shinji
3 projects • 0 followers
Ph. D. in Engineering, Optics, 3D Holograms. Designer for High Power Laser Manufacturing Systems. Project Leader regarding Metal AM Monitor.

Comments