Output from Arduino to Arduino iot

Hello working on a boxing project which involves position. The idea is to create an app that records this data, simple as if the sensors do not detect anything for more than 4 sec a red alarm(screen) will be displayed, if the boxer has good guard the screen will be green. We want to use Arduino Cloud to create this app, using the code attached, how can I make it work on Arduino cloud. I already follow several tutorials but no success. We are using ESP32 microcontroller

#include <Wire.h>
#include <NewPing.h>
#include <I2Cdev.h>
#include <MPU6050.h>

MPU6050 mpu1;
MPU6050 mpu2;

#define TRIGGER_PIN_1 12
#define ECHO_PIN_1 13
#define TRIGGER_PIN_2 14
#define ECHO_PIN_2 27
#define TRIGGER_PIN_3 32
#define ECHO_PIN_3 33

#define GOOD_GUARD_DISTANCE 15

NewPing sonar1(TRIGGER_PIN_1, ECHO_PIN_1);
NewPing sonar2(TRIGGER_PIN_2, ECHO_PIN_2);
NewPing sonar3(TRIGGER_PIN_3, ECHO_PIN_3);

bool punchDetected = false;
int punchCount = 0; // Variable to count punches

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu1.initialize();
  mpu2.initialize();
}

void loop() {
  // Read the accelerometer data for both sensors
  int16_t ax1, ay1, az1;
  int16_t ax2, ay2, az2;
  mpu1.getAcceleration(&ax1, &ay1, &az1);
  mpu2.getAcceleration(&ax2, &ay2, &az2);

  // Calculate acceleration magnitudes
  float acc1 = sqrt(ax1 * ax1 + ay1 * ay1 + az1 * az1);
  float acc2 = sqrt(ax2 * ax2 + ay2 * ay2 + az2 * az2);

  // Check if either sensor detected a punch
  if (acc1 > 20 || acc2 > 20) {
    if (!punchDetected) {
      punchDetected = true;
      punchCount++; // Increment punch count when a new punch is detected
      Serial.print("Punch detected! Total Punches: ");
      Serial.println(punchCount);
    }
  } else {
    punchDetected = false;
  }

  // Ultrasonic sensor code
  int distance1 = sonar1.ping_cm();
  int distance2 = sonar2.ping_cm();
  int distance3 = sonar3.ping_cm();

  // Check if any sensor measures a distance greater than 15 cm.
  if ((distance1 > GOOD_GUARD_DISTANCE || distance2 > GOOD_GUARD_DISTANCE) &&
      (distance1 > GOOD_GUARD_DISTANCE || distance3 > GOOD_GUARD_DISTANCE) &&
      (distance2 > GOOD_GUARD_DISTANCE || distance3 > GOOD_GUARD_DISTANCE)) {
    Serial.println("Bad guard for 4 seconds! HANDS UP!");
    // Add code to trigger an alarm or display a message for bad guard.
  } else {
    Serial.println("Good guard.");
    // Add code for good guard, if needed.
  }
}

Hi!

I would suggest that you get started with this guide.
When you create the Thing following the guide, you will geet an auto-generated sketch where you can include your code.

Test it and if it doesn't work, share your code here.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.