logo elektroda
logo elektroda
X
logo elektroda

Integrating CB2S with OpenBK for a Smart Soil Moisture-Based Watering System

electrikphone 669 7
ADVERTISEMENT
  • #1 20932197
    electrikphone
    Level 3  
    Repurposing a CB2S Module (BK7231N_1.0.1) for a DIY Watering System with OpenBK

    Key Goals:

    Control a water pump based on soil moisture levels, using a CB2S module flashed with OpenBK.
    Monitor moisture levels and manually control the pump through a web interface.
    Challenges and Questions:

    OpenBK Compatibility:
    Does OpenBK support the CB2S module and provide the following features:
    Analog sensor input
    Reliable timing mechanisms
    Web interface customization
    Moisture Sensor Input:
    Does OpenBK directly support analog input on the ADC pin (P8)?
    If not, are PWM-based techniques or external ADCs feasible?
    How to configure the ADC channel in OpenBK's code or settings (if applicable)?
    Relay Control:
    How to configure OpenBK to control the relay on pin 9 or P24, with activation on low signal?
    Web Interface Integration:
    How to implement the following elements in OpenBK's web interface:
    Moisture level display
    Relay control button
    Manual toggle button
    Timing:
    What are reliable timing mechanisms within OpenBK for controlling watering cycles?
    Can the web interface's running counter be used for basic timing?
    Progress and Information:

    Successfully flashed OpenBK on the CB2S module and accessed the web interface.
    Identified potential pin assignments for relay and sensor.
    Discovered a running counter on the web interface.
    Confident in basic coding and eager to learn OpenBK.
    Personal Motivation:

    Passionate about DIY projects and reducing e-waste.
    Request for Assistance:

    Seeking guidance from the community on the specific questions and challenges outlined above.
    Appreciate any insights, code examples, or resources to aid in this project.
    Additional Considerations:

    Simplified web version goals:
    Monitor moisture level, turning the relay on below 40% and off at 70%.
    Continuously display moisture value on the web interface.
    Provide a toggle button for manual relay control.
    I'm excited to collaborate and learn from the community to achieve this project!
  • ADVERTISEMENT
  • #2 20932584
    p.kaczmarek2
    Moderator Smart Home
    That's a lot of questions. Have you looked into our autoexec script examples? This should be the first step at learning OBK scripting:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20933357
    electrikphone
    Level 3  

    I apologize, I am eager to try and make this work. I have already started looking at the drivers section and maybe using 'SHT3X' and IO pin roles like 'CHT8305_DAT'.
    Thank you @p.kaczmarek2 for pointing me towards the autoexec script examples! I've already started taking a look...

    The sensor I have is the 'AZDelivery Soil Moisture Sensor Hygrometer Module V1.2 capacitive compatible with Arduino'

    I already have the idea running from my Arduino, but seeing as I have two broken generic LSPA7 smart plugs that reported current use (BL0942) and also had a relay. The only other chip on the board is KP3210SG chip as I think the power supply. I thought it wouldn't be that hard to make a little circuit that would use the CB2S with I think BN7231N chip on it to do the same thing.
    I have already managed to make my web interface display 'Humidity 0.0% (8)' below the trigger button for relay. I'm not sure what the (8) means yet.

    Will this device run my Arduino sketch by any chance?
  • #4 20933525
    p.kaczmarek2
    Moderator Smart Home
    You can write a custom driver in C for that, but syntax would be a bit different. What kind of device would you like to drive? What kind of protocol is used by 'AZDelivery Soil Moisture Sensor Hygrometer Module V1.2 capacitive compatible with Arduino'?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 20933816
    electrikphone
    Level 3  

    The device is a 'AZDelivery Soil Moisture Sensor Hygrometer Module V1.2.' It's a capacitive sensor that outputs an analog voltage, providing real-time moisture readings.

    Output range: Based on my Arduino code, the sensor output ranges between approximately 398 (wet) and 809 (dry). This corresponds to a voltage range of roughly 0-5V, as typical for analog sensors on the Arduino Uno.
    Arduino compatibility: I've successfully used it with an Arduino Uno, reading its output on an analog pin and obtaining values within the mentioned range. Here's a simplified example of the Arduino code I used:

    
    // Define the sensor pin
    const int sensorAnalog = A0;  // Analog output pin of sensor
    const int dry = 809;  // Value for dry sensor
    const int wet = 398;  // Value for wet sensor
    void setup() {
      Serial.begin(9600);
    }
    void loop() {
      int sensorValue = analogRead(sensorAnalog);  // Read sensor value from the defined pin
      int moisturePercent = map(sensorValue, wet, dry, 0, 100);  // Calculate moisture percentage
      Serial.print("Moisture: ");
      Serial.print(moisturePercent);
      Serial.println("%");
      delay(100);  // Delay between readings
    }
    


    I've found a datasheet for the sensor, see attachment
    I'm excited to integrate this sensor with OpenBK, but I'm not familiar with the specific protocol or driver requirements needed. Any guidance on how to proceed would be greatly appreciated.
    For example how do I upload a hex file of my C++ sketch or what compiler should I use?

    Ps I'm not sure what protocol it uses if that doesn't answer your question :-)
    Below is an explanation of code
    Spoiler:
    Define Constants:

    dry: Stores the value you observed for the sensor when it's completely dry.
    wet: Stores the value you observed for the sensor when it's fully submerged in water.

    Serial.begin(9600): Initializes serial communication for printing readings to the serial monitor.

    const int sensorAnalog = A0;: This line defines a constant variable named sensorAnalog and assigns it the value A0. This means that throughout the code, whenever you use sensorAnalog, it will refer to analog pin A0 on the Arduino.

    analogRead(sensorAnalog): In the loop function, this line now uses sensorAnalog to specify which pin to read the analog value from. By defining the pin as a constant, it's easier to modify if you decide to connect the sensor to a different pin in the future.

    sensorValue = analogRead(A0): Reads the raw analog value from pin A0 (adjust if connected to a different pin).
    moisturePercent = map(sensorValue, wet, dry, 0, 100): Maps the sensor value to a percentage between 0 and 100, using the wet and dry values as the range.
    Serial.print("Moisture: "): Prints "Moisture: " to the serial monitor.
    Serial.print(moisturePercent): Prints the calculated moisture percentage.
    Serial.println("%"): Prints a "%" symbol for clarity.
    delay(100): Pauses for 100 milliseconds before taking the next reading.

  • ADVERTISEMENT
  • #6 20933893
    electrikphone
    Level 3  
    I'm using a sensor connected to pin 8 (ADCI/OADC) of the IC (corresponding to P23).
    Can someone clarify the OpenBK pin naming convention for this module?
    Should I use 'P23' or a different name in the autoexec script?
    Is there a table or function that maps physical pin labels like '8' to OpenBK pin names for my specific module?
    Can someone share an example OpenBK script for reading an analog sensor connected to pin 8 (ADCI/OADC) on my module?
  • #7 20934182
    p.kaczmarek2
    Moderator Smart Home
    This is just a simple ADC read. Set the P23 role to "ADC" in pins:
    Screenshot of a configuration panel showing pin settings, with pin P23 set as ADC.
    and you should get a value read in the related channel... no scripting needed. What do you want to do with that value later?

    You can, for example, script relay to open or close, based on this value.
    Helpful post? Buy me a coffee.
  • #8 20934672
    electrikphone
    Level 3  

    Yes, I would like to have the reading from the sensor start and stop a relay based on a min and max trigger set by me.
    Please forgive my ignorance, you said set P23 as ADC. However, the CB2S has only 11 physical pins. The datasheet says physical pin 8, which corresponds to P23 of the IC. So, is the cfg_pins talking about the pins of the IC?
    In the web app, I set the Channel Type of P23 to humidity.
    However, I noticed a custom type. How do I use that?
    Also, how do I script the relay to open or close based on this value?

Topic summary

The discussion revolves around repurposing a CB2S module (BK7231N_1.0.1) for a DIY soil moisture-based watering system using OpenBK firmware. Key objectives include controlling a water pump based on soil moisture levels, monitoring moisture via a web interface, and addressing compatibility issues with OpenBK. Participants explore the integration of an AZDelivery Soil Moisture Sensor Hygrometer Module V1.2, which outputs an analog voltage for moisture readings. Questions arise regarding OpenBK's support for analog sensor input, relay control configuration, and web interface customization. Solutions include setting the appropriate pin roles in OpenBK and scripting relay operations based on moisture readings.
Summary generated by the language model.
ADVERTISEMENT