Interfacing SNS-US020 with Pluguino v2

Interfacing SNS-US020 with Pluguino v2

1024 576 Yaniv

SNS-US020 is low cost ultrasonic sensor, perfect for your next robot project. It measures the distance by sending ultrasonic waves and reading back when the reflected wave. SNS-US020 operates with 5V and requires only 3mA in active mode.

SNS-US020 operation is as follows: If trigger input is held high for more than 10 uS the module sends 8 pulses with 40kHz and listen to receive the reflected signal, then calculates the distance assuming speed of sound 340m/s. No temperature compensation is used for the calculation so there is error in the measurement depend on ambient temperature.


  • V and G goes to the Vcc and GND pins of HC-SR04
  • Trig pin connected to Digital Pin 12 of Pluguino
  • Echo pin Connected to Digital Pin 11 of Pluguino Board


// defines pins numbers
const int trigPin = 12;
const int echoPin = 11;
// defines variables
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");


Leave a Reply