Welcome Guest! To enable all features please Login or Register.
Go to last post Go to first unread
#1 Posted : Friday, June 23, 2017 2:34:08 AM(UTC)

Rank: Newbie

Groups: Registered
Joined: 6/23/2017(UTC)
Posts: 3

3 Pin Ultrasonic Sensor

This code reads a value from an ultrasonic sensor with 3 pins: ground, voltage, and signal. The signal pin plugs into a digital pin on the Arduino, and the code changes the pin mode as needed to both send and received data to the sensor via one wire.

Supported Products

Parallax PING))) Ultrasonic Sensor

Decleration Code

const int pingPin = 7; // Update this to the pin your sensor is plugged into!


// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
digitalWrite(pingPin, HIGH);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH, 100); // Max 100 microsecond read

// Convert the duration value from 0 to 100 to the Embrio range of 0.0 to 1.0
Output_Activation = transform(duration, 0, 100, 0.0, 1.0);
Check for essay writing service
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.