4 Pin Ultrasonic Sensor

This preset can be used with ultrasonic distance sensors that use 4 pins.

Supported Products

  • Ultrasonic Module HC-SR04 Distance Measure Transducer Sensor

Decleration Code

int echoPin = 7;
int trigPin = 8;
int maxPulse = 100;         // Maximum micros to wait for a pulse
long duration;

Setup Code

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

EveryUpdate

digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH, maxPulse);

Output_Activation = transform(duration, 0, maxPulse, 0.0, 1.0);

No required source files.

To use this node in your Embrio project, either add it from the Library toolbar or copy the XML in the below box and paste it into a node screen.

View Comments (0)