-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create bbn_m5atomS3_lite_JSN-SR04T.ino
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
bbn_m5atomS3_lite_JSN-SR04T/bbn_m5atomS3_lite_JSN-SR04T.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <M5AtomS3.h> | ||
#include <NewPing.h> | ||
|
||
#define TRIGGER_PIN G7 // Pin tied to trigger pin on the ultrasonic sensor. | ||
#define ECHO_PIN G8 // Pin tied to echo pin on the ultrasonic sensor. | ||
#define MAX_DISTANCE 75 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. | ||
|
||
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. | ||
|
||
float temp = 28.0; // Temperature in Celsius (this value would probably come from a temperature sensor). | ||
float factor = sqrt(1 + temp / 273.15) / 60.368; // Speed of sound calculation based on temperature. | ||
|
||
void setup() { | ||
auto cfg = M5.config(); | ||
AtomS3.begin(cfg); | ||
Serial.begin(4800); | ||
} | ||
|
||
void loop() { | ||
delay(1000); // Wait 1 second between distance readings. | ||
Serial.print("Ping: "); | ||
Serial.print((float)sonar.ping_median(5) * factor); // Send 5 pings, get median distance, convert to cm and print result | ||
Serial.println("cm"); | ||
} |