From d51ff806cc203f341ca8c6b5bca4417053c41603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Abonnel?= Date: Sun, 15 May 2022 21:48:32 +0000 Subject: [PATCH] Update sketchDistanceSerial-Ultrasonic.ino --- arduino/sketchDistanceSerial-Ultrasonic.ino | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/arduino/sketchDistanceSerial-Ultrasonic.ino b/arduino/sketchDistanceSerial-Ultrasonic.ino index df14921..9256f1c 100644 --- a/arduino/sketchDistanceSerial-Ultrasonic.ino +++ b/arduino/sketchDistanceSerial-Ultrasonic.ino @@ -1,13 +1,20 @@ + #include "Ultrasonic.h" -Ultrasonic sensor(8,9); // Trig et Echo + +#define echoPin 9 // attach pin D2 Arduino to pin Echo of HC-SR04 +#define trigPin 8 //attach pin D3 Arduino to pin Trig of HC-SR04 + +Ultrasonic sensor(trigPin,echoPin); // Trig et Echo // defines variables int distance; // variable for the distance measurement void setup() { - Serial.begin(9600); - pinMode (11, OUTPUT); - pinMode (12, OUTPUT); + Serial.begin(9600);trigPin as an OUTPUT + pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT + Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed + Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor + Serial.println("with Arduino UNO R3 and Ultrasonic.h"); } void loop () {