Good day, I am new to programming and I am trying to send data to my dashboard but I have difficulties as I am a newbie. I have managed to create the dashboard on Thinger.io and get my device online. I can transmit temperature data and the basic IMU accelerometer reading. The hardware I am using is Arduino Uno, Arduino Ethernet Shield, Adafruit IMU.
I am finding it difficult to write this code below in the correct format to get it to uploaded. I am aiming to send the results of my print statements to my dashboard. I would appreciate any help or guidance. thank you
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
// Define the BNO055 sensor object
Adafruit_BNO055 bno = Adafruit_BNO055();
// Define variables for wave detection
float peak_threshold = 3.0; // Minimum height of peak
float trough_threshold = -3.0; // Maximum depth of trough
int num_peaks = 0; // Number of peaks detected
int num_troughs = 0; // Number of troughs detected
float peak_sum = 0.0; // Sum of heights of peaks
float trough_sum = 0.0; // Sum of depths of troughs
float wave_period = 0.0; // Period of the wave
float wave_frequency = 0.0; // Frequency of the wave
bool wave_detected = false; // Whether a wave has been detected
float max_wave_height = 0;
void setup() {
// Initialize serial communication
Serial.begin(115200);
while (!Serial) {
delay(10);
}
// Initialize the BNO055 sensor
if (!bno.begin()) {
Serial.println("Failed to initialize BNO055!");
while (1);
}
// Set BNO055 to NDOF mode
bno.setExtCrystalUse(true);
}
void loop() {
// Read acceleration data from BNO055
sensors_event_t event;
bno.getEvent(&event);
float acceleration_z = event.acceleration.z;
// Detect peaks and troughs
if (acceleration_z >= peak_threshold) {
num_peaks++;
peak_sum += acceleration_z;
}
else if (acceleration_z <= trough_threshold) {
num_troughs++;
trough_sum += acceleration_z;
}
// Check if wave has been detected
if (num_peaks > 1 && num_troughs > 1) {
// Calculate wave period and frequency
wave_period = (num_peaks + num_troughs - 2) * (1.0 / 1000.0);
wave_frequency = 1.0 / wave_period;
max_wave_height = (acceleration_z);
// Check if the combination of peaks and troughs simulate a sinusoidal pattern
if ((num_peaks + num_troughs) % 2 == 0 && peak_sum + trough_sum >= 0) {
wave_detected = true;
}
// Reset peak and trough variables for next detection
num_peaks = 0;
num_troughs = 0;
peak_sum = 0.0;
trough_sum = 0.0;
}
// Print wave parameters and plot wave if detected
if (wave_detected) {
Serial.print("Wave detected! ");
Serial.print("Wave period: ");
Serial.print(wave_period);
Serial.print(" seconds, Wave frequency: ");
Serial.print(wave_frequency);
Serial.print("Hz, max wave height: ");
Serial.print(max_wave_height);
Serial.println("cm");
wave_detected = false;
}
}