Surilli
Published © GPL3+

Ultrasonic Sensor with Surilli Basic M0 and 16x2 LCD

Integrate your Surilli Basic M0 with ultrasonic sensor and visualize the changing values of distance on 16x2 LCD.

BeginnerFull instructions provided15 minutes687
Ultrasonic Sensor with Surilli Basic M0 and 16x2 LCD

Things used in this project

Hardware components

Surilli Basic
Surilli Basic
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Surilli Basic M0 with HC-SR04 Ultrasonic Sensor Module and 16x2 LCD

Code

SurilliBasicM0_Ultrasonic_16x2LCD

C/C++
#include <LiquidCrystal.h> // Include the LiquidCrystal Library.

LiquidCrystal lcd(6, 11, 5, 12, 20, 21); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7).

const int trigPin = 9;
const int echoPin = 10;

long duration;

int distanceCm, distanceInch;

void setup() 

{
    
    lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display.
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    
}

void loop() 

{
    
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distanceCm= duration*0.034/2;
    distanceInch = duration*0.0133/2;
    lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed.
    lcd.print("Distance: "); // Prints string "Distance" on the LCD.
    lcd.print(distanceCm); // Prints the distance value from the Ultrasonic Sensor (HC-SR04).
    lcd.print(" cm");
    delay(10);
    lcd.setCursor(0,1);
    lcd.print("Distance: ");
    lcd.print(distanceInch);
    lcd.print(" inch");
    delay(10);
    
}

Credits

Surilli

Surilli

196 projects • 62 followers
Surilli is a premiere Internet of Things centric Technology Company aimed at providing cutting edge innovative solutions.

Comments