Electro BOY
Published © GPL3+

Waterproof Ultrasonic sensor grove module

I made a shield to use this waterproof sensor with GROVE shield. You can participate in the contest, any new idea may win 2 FREE PCBA.

BeginnerFull instructions provided1 hour496
Waterproof Ultrasonic sensor grove module

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)

Story

Read more

Custom parts and enclosures

Gerber files

Schematics

With arduino

With GROVE SHIELD

Code

Waterproof sensor code

Arduino
// Include the Software Serial library
#include <SoftwareSerial.h>
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD

LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); 

// Define connections to sensor
int pinRX = 10;
int pinTX = 11;

// Array to store incoming serial data
unsigned char data_buffer[4] = {0};

// Integer to store distance
int distance = 0;

// Variable to hold checksum
unsigned char CS;

// Object to represent software serial port
SoftwareSerial mySerial(pinRX, pinTX);

void setup() {
  // Set up serial monitor
  Serial.begin(115200);
  // Set up software serial port
  mySerial.begin(9600);
  Wire.begin();
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("A02YYUW Test");
  lcd.setCursor(0,1);
  lcd.print("Please wait...");
  delay(1000);
  lcd.clear();
}

void loop() {

  // Run if data available
  if (mySerial.available() > 0) {

    delay(4);

    // Check for packet header character 0xff
    if (mySerial.read() == 0xff) {
      // Insert header into array
      data_buffer[0] = 0xff;
      // Read remaining 3 characters of data and insert into array
      for (int i = 1; i < 4; i++) {
        data_buffer[i] = mySerial.read();
      }

      //Compute checksum
      CS = data_buffer[0] + data_buffer[1] + data_buffer[2];
      // If checksum is valid compose distance from data
      if (data_buffer[3] == CS) {
        distance = (data_buffer[1] << 8) + data_buffer[2];
        // Print to serial monitor
        Serial.print("distance: ");
        Serial.print(distance);
        Serial.println(" mm");
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Distance:");
        lcd.setCursor(10, 0);
        lcd.print(distance);
        
      }
    }
  }
}

Credits

Electro BOY

Electro BOY

57 projects • 52 followers
Electronics is my passion. I am not professional, Always learning something new. I am good at soldering, designing pcb, Arduino programing.

Comments