

ABX00087 UNO R4 WiFi සංවර්ධන මණ්ඩලය
Cricket Shot Recognition using Arduino UNO R4 WiFi + ADXL345 + Edge
ආවේගය
This document provides a complete workflow for building a cricket shot recognition system using Arduino UNO R4 WiFi with an ADXL345 accelerometer and Edge Impulse Studio. The project involves collecting accelerometer data, training a machine learning model, and deploying the trained model back to the Arduino for real-time shot classification.
Cricket shots considered in this project:
– Cover Drive
– Straight Drive
– Pull Shot
පියවර 1: දෘඪාංග අවශ්යතා
– Arduino UNO R4 WiFi
– ADXL345 Accelerometer (I2C)
– Jumper wires
– Breadboard (optional)
- USB Type-C කේබලය
පියවර 2: මෘදුකාංග අවශ්යතා
– Arduino IDE (latest)
– Edge Impulse Studio account (free)
– Edge Impulse CLI tools (Node.js required)
– Adafruit ADXL345 library
Step 3: Wiring the ADXL345
Connect the ADXL345 sensor to the Arduino UNO R4 WiFi as follows:
වීසීසී → 3.3V
GND → GND
SDA → SDA (A4)
SCL → SCL (A5)
CS → 3.3V (optional, for I2C mode)
SDO → floating or GND
Step 4: Make IDE Sensor Ready
Arduino IDE හි සංවේදක පුස්තකාල ස්ථාපනය කරන්නේ කෙසේද?
Arduino IDE විවෘත කරන්න.
Open Tools → Manage Libraries… and install: Adafruit ADXL345 Unified Adafruit Unified Sensor
(If you have LSM6DSO or MPU6050 instead: install SparkFun LSM6DSO , Adafruit LSM6DS or MPU6050 accordingly.)
Step 5: Arduino Sketch for Data Collection
Upload this sketch to your Arduino UNO R4 WiFi. It streams accelerometer data in CSV format (x,y,z) at ~18 Hz for Edge Impulse.
#ඇතුළත්
#include <Adafruit_ADXL345_U.h>
Adafruit_ADXL345_Unified accel =
Adafruit_ADXL345_Unified(12345);
හිස් සැකසුම () {
Serial.begin(115200);
(!accel.begin()) නම් {
Serial.println(“No ADXL345 detected”);
අතරතුර (1);
}
accel.setපරාසය(ADXL345_පරාසය_4_G);
}
void loop() {
සංවේදක_සිදුවීම්_ටී ඊ;
accel.සිදුවීම ලබා ගන්න(&e);
Serial.print (e.acceleration.x);
Serial.print(“,”);
Serial.print(e.acceleration.y);
Serial.print(“,”);
Serial.println(e.acceleration.z);delay(55); // ~18 Hz
}
Set Up Edge Impulse

Step 6: Connecting to Edge Impulse
- Close Arduino Serial Monitor.
- Run the command: edge-impulse-data-forwarder –frequency 18
- Enter axis names: accX, accY, accZ
- Name your device: Arduino-Cricket-Board
- Confirm connection in Edge Impulse Studio under ‘Devices’.


පියවර 7: දත්ත රැස් කිරීම
In Edge Impulse Studio → Data acquisition:
– Device: Arduino-Cricket-Board
– Sensor: Accelerometer (3 axes)
- එස්ample length: 2000 ms (2 seconds)
– සංඛ්යාතය: 18 Hz
Record at least 40 samples per class:
– Cover Drive
– Straight Drive
– Pull Shot
Collect Data Examples
ආවරණ ධාවකය
Device: Arduino-Cricket-Board
Label: Cover Drive
Sensor: Sensor with 3 axes (accX, accY, accZ)
Sample length: 10000ms
සංඛ්යාතය: 18 Hz
Example Raw Data:
accX -0.32
accY 9.61
accZ -0.12
Straight Drive
Device: Arduino-Cricket-Board
Label: Straight Drive
Sensor: Sensor with 3 axes (accX, accY, accZ)
Sample length: 10000ms
සංඛ්යාතය: 18 Hz
Example Raw Data:
accX 1.24
accY 8.93
accZ -0.42
Pull Shot
Device: Arduino-Cricket-Board
Label: Pull Shot
Sensor: Sensor with 3 axes (accX, accY, accZ)
Sample length:10000 ms
සංඛ්යාතය: 18 Hz
Example Raw Data:
accX 2.01
accY 7.84
accZ -0.63 
Step 8: Impulse Design
Open Create impulse:
ආදාන කොටස: කාල ශ්රේණි දත්ත (අක්ෂ 3).
Window size: 1000 ms Window increase (stride): 200 ms Enable: Axes, Magnitude (optional), frequency 18.
Processing block: Spectral analysis (a.k.a. Spectral Features for motion). Window size: 1000 ms Window increase (stride): 200 ms Enable: Axes, Magnitude (optional), keep all defaults first.
ඉගෙනුම් කොටස: වර්ගීකරණය (කේරස්).
ආවේගය සුරකින්න ක්ලික් කරන්න. 
Generate features:
වර්ණාවලි විශ්ලේෂණය වෙත ගොස්, පරාමිතීන් සුරකින්න ක්ලික් කරන්න, ඉන්පසු පුහුණු කට්ටලය සඳහා විශේෂාංග ජනනය කරන්න.

Train a small model
Go to Classifier (Keras) and use a compact config like:
Neural network: 1–2 dense layers (e.g., 60 → 30), ReLU
Epochs: 40–60
ඉගෙනීමේ අනුපාතය: 0.001–0.005
කණ්ඩායම් ප්රමාණය: 32
Data split: 80/20 (train/test)
Save and train the data
Evaluate and Check Model testing with the holdout set.
Inspect the confusion matrix; if circle and up overlap, collect more diverse data or tweak
Spectral parameters (window size / noise floor).
Step 9: Deployment to Arduino
Go to Deployment:
Choose Arduino library (C++ library also works).
මාදිලියේ ප්රමාණය හැකිලීමට EON සම්පාදකය (තිබේ නම්) සක්රීය කරන්න.
Download the .zip, then in Arduino IDE: Sketch → Include Library → Add .ZIP Library… This adds exampස්ථිතික බෆරය සහ අඛණ්ඩ යටතේ වැනි File → උදාamples →
Your Project Name – Edge Impulse. Inference sketch for Arduino UNO EK R4 WiFi + ADXL345.
Step 10: Arduino Inference Sketch
#ඇතුළත්
#ඇතුළත්
#include <your_project_inference.h> // Replace with Edge Impulse header
Adafruit_ADXL345_Unified accel =
Adafruit_ADXL345_Unified(12345);
ස්ථිතික බූල් debug_nn = අසත්ය;
හිස් සැකසුම () {
Serial.begin(115200);
(! අනුක්රමික) {}
(!accel.begin()) නම් {
Serial.println(“දෝෂය: ADXL345 අනාවරණය වී නොමැත”);
අතරතුර (1);
}
accel.setපරාසය(ADXL345_පරාසය_4_G);
}
void loop() {
පාවෙන බෆරය[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE] = {0};
for (size_t ix = 0; ix < EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE; ix +=
3) {
uint64_t next_tick = micros() + (EI_CLASSIFIER_INTERVAL_MS *
1000);
සංවේදක_සිදුවීම්_ටී ඊ;
accel.සිදුවීම ලබා ගන්න(&e);
බෆරය[ix + 0] = e.ත්වරණය.x;
බෆරය[ix + 1] = e.ත්වරණය.y;
බෆරය[ix + 2] = e.ත්වරණය.z;
int32_t රැඳී සිටින්න = (int32_t)(ඊළඟ_ටික් - මයික්රෝස්());
(ඉන්න > 0) ප්රමාද වුවහොත් මයික්රෝ තත්පර(ඉන්න);
}
සංඥා_ටී සංඥාව;
int err = numpy::signal_from_buffer(buffer,
EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &signal);
(err != 0) ආපසු ලබා දෙන්නේ නම්;
ei_impulse_result_t ප්රතිඵලය = {0};
EI_IMPULSE_ERROR res = run_classifier(&signal, &result,
debug_nn);
(res != EI_IMPULSE_OK) ආපසු ලබා දෙන්නේ නම්;
(size_t ix = 0; ix <EI_CLASSIFIER_LABEL_COUNT; ix++) සඳහා {
ei_printf(“%s: %.3f “, result.classification[ix].label,
result.classification[ix].value);
}
#EI_CLASSIFIER_ඇනමලි == 1 නම්
ei_printf(“විෂමතාව: %.3f”, ප්රතිඵලය.විෂමතාව);
#endif
ei_printf(“\n”);
}
ප්රතිදානය exampලෙ:
ඉඟි:
ඔබගේ දත්ත යොමු කිරීමේ සංඛ්යාතය (උදා: 100 Hz → 10 ms) සමඟ EI_CLASSIFIER_INTERVAL_MS සමමුහුර්තව තබා ගන්න. Edge Impulse පුස්තකාලය මෙම නියතය ඔබගේ ආවේගයෙන් ස්වයංක්රීයව සකසයි.
ඔබට අඛණ්ඩ අනාවරණය (ස්ලයිඩින් කවුළුව) අවශ්ය නම්, අඛණ්ඩ ex වලින් ආරම්භ කරන්න.ample EI පුස්තකාලය සමඟ ඇතුළත් කර ඇති අතර ADXL345 කියවීම් වල හුවමාරු කර ඇත.
We will be adding video tutorials soon; till then, stay tuned – https://www.youtube.com/@RobuInlabs
And If you still have some doubts, you can check out this video by Edged Impulse: https://www.youtube.com/watch?v=FseGCn-oBA0&t=468s

ලේඛන / සම්පත්
![]() |
Arduino ABX00087 UNO R4 WiFi Development Board [pdf] පරිශීලක මාර්ගෝපදේශය R4 WiFi, ADXL345, ABX00087 UNO R4 WiFi Development Board, ABX00087, UNO R4 WiFi Development Board, WiFi Development Board, Development Board, Board |
