Skip to content

Commit

Permalink
Create bbn_m5atomS3_lite_JSN-SR04T.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch authored Nov 23, 2024
1 parent d010c25 commit 4b5105f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bbn_m5atomS3_lite_JSN-SR04T/bbn_m5atomS3_lite_JSN-SR04T.ino
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");
}

0 comments on commit 4b5105f

Please sign in to comment.