r/ArduinoHelp • u/Creative_Commons_Co • Dec 25 '25
I made a simple video explaining how to install Arduino IDE for beginners.
r/ArduinoHelp • u/Creative_Commons_Co • Dec 25 '25
r/ArduinoHelp • u/Another_boykisser • Nov 27 '25
I have a project pending which consists of making a mini weather station that includes an anemometer, humidity measurement, among other sensors, The problem is that I'm new to the world of Arduino, so I don't even know where to start. Any advice on how I could organize it, or where I can learn to program Arduino or related topics?
r/ArduinoHelp • u/CoffeeAffectionate83 • Nov 03 '25
I have a project I am working on where an alarm clock will not go off until the user hits a heart rate of a certain threshold. I am having issues connecting my Whoop Band to the HM-10 module, although I thought they would be compatible. Is there a way to pair it so that the heart rate can be read off of the band for the signal to turn off the alarm? I feel like I have tried everything from MAC address to UUID.
Below is the code I currently have.
// IR Remote Alarm Clock with Buzzer and WHOOP Heart Rate
// Arduino Uno - with HM-10 Bluetooth
#include <IRremote.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
// Pin Definitions
#define IR_RECEIVE_PIN 7
#define BUZZER_PIN 8
#define LCD_RS 12
#define LCD_EN 11
#define LCD_D4 5
#define LCD_D5 4
#define LCD_D6 3
#define LCD_D7 2
#define BT_TX 9 // Connect to HM-10 RX (use voltage divider!)
#define BT_RX 10 // Connect to HM-10 TX
// Your Remote's IR Codes
#define IR_0 0xE916FF00
#define IR_1 0xF30CFF00
#define IR_2 0xE718FF00
#define IR_3 0xA15EFF00
#define IR_4 0xF708FF00
#define IR_5 0xE31CFF00
#define IR_6 0xA55AFF00
#define IR_7 0xBD42FF00
#define IR_8 0xAD52FF00
#define IR_9 0xB54AFF00
#define IR_UP 0xB946FF00
#define IR_DOWN 0xEA15FF00
#define IR_LEFT 0xBB44FF00
#define IR_RIGHT 0xBC43FF00
#define IR_POWER 0xBA45FF00
#define IR_FUNCTION 0xB847FF00
// LCD Setup
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
// Bluetooth Setup
SoftwareSerial BTSerial(BT_RX, BT_TX);
// State Machine
enum State {
STATE_DISPLAY_CLOCK,
STATE_DISPLAY_ALARM,
STATE_DISPLAY_HEARTRATE,
STATE_DISPLAY_BT_STATUS,
STATE_SET_CLOCK_HOUR,
STATE_SET_CLOCK_MIN,
STATE_SET_ALARM_HOUR,
STATE_SET_ALARM_MIN,
STATE_ALARM_ACTIVE
};
State currentState = STATE_DISPLAY_CLOCK;
// Time Variables
unsigned long lastMillis = 0;
int currentHour = 12;
int currentMinute = 0;
int currentSecond = 0;
// Alarm Variables
int alarmHour = 7;
int alarmMinute = 0;
bool alarmEnabled = true;
bool alarmTriggered = false;
unsigned long alarmStartTime = 0;
bool alarmHasTriggeredThisMinute = false;
// Heart Rate Variables
int heartRate = 0;
unsigned long lastHRUpdate = 0;
bool btConnected = false;
String connectedDevice = "";
bool isNOAHWHOOP = false;
// Input Buffer
String inputBuffer = "";
// Track last state to minimize LCD updates
State lastState = STATE_DISPLAY_CLOCK;
int lastSecond = -1;
// Function declarations
void updateDisplayNow();
void readHeartRate();
void setup() {
// Initialize Serial for debugging
Serial.begin(9600);
// Initialize LCD
lcd.begin(16, 2);
lcd.print("Alarm Clock");
lcd.setCursor(0, 1);
lcd.print("Ready!");
delay(2000);
lcd.clear();
// Initialize IR Receiver
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
// Initialize Buzzer Pin
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
// Initialize Bluetooth
BTSerial.begin(9600);
delay(2000);
// Test HM-10 communication
lcd.clear();
lcd.print("Testing BT...");
// Clear any existing data
while(BTSerial.available()) {
BTSerial.read();
}
BTSerial.print("AT");
delay(1000);
if (BTSerial.available()) {
lcd.setCursor(0, 1);
lcd.print("HM-10 Found!");
while(BTSerial.available()) {
Serial.write(BTSerial.read());
}
} else {
lcd.setCursor(0, 1);
lcd.print("HM-10 Not Found");
}
delay(2000);
lcd.clear();
// Configure HM-10 for WHOOP connection
Serial.println("Configuring HM-10...");
BTSerial.print("AT+ROLE1"); // Set as Central
delay(500);
while(BTSerial.available()) Serial.write(BTSerial.read());
BTSerial.print("AT+IMME1"); // Work in command mode
delay(500);
while(BTSerial.available()) Serial.write(BTSerial.read());
Serial.println("HM-10 configured!");
}
void loop() {
// Update time
updateTime();
// Handle IR input
handleIRInput();
// Read heart rate from Bluetooth
readHeartRate();
// Check alarm
checkAlarm();
// Update display
updateDisplay();
delay(100);
}
void updateTime() {
unsigned long currentMillis = millis();
if (currentMillis - lastMillis >= 1000) {
lastMillis = currentMillis;
currentSecond++;
if (currentSecond >= 60) {
currentSecond = 0;
currentMinute++;
if (currentMinute >= 60) {
currentMinute = 0;
currentHour++;
if (currentHour >= 24) {
currentHour = 0;
}
}
}
}
}
void readHeartRate() {
static unsigned long lastConnectAttempt = 0;
static String btBuffer = "";
static unsigned long lastDataTime = 0;
// Try to connect to WHOOP every 10 seconds if not connected
if (!btConnected && (millis() - lastConnectAttempt > 10000)) {
lastConnectAttempt = millis();
Serial.println("Attempting to connect to WHOOP...");
// Connect to WHOOP using its MAC address (without colons)
BTSerial.print("AT+CONE2AB5A5A5E50");
delay(5000); // Wait for connection
}
// Read data from HM-10
while (BTSerial.available()) {
char c = BTSerial.read();
btBuffer += c;
lastDataTime = millis();
// Check for connection success
if (btBuffer.indexOf("OK+CONN") >= 0 && btBuffer.indexOf("OK+CONNF") < 0) {
if (!btConnected) {
btConnected = true;
isNOAHWHOOP = true;
connectedDevice = "NOAHWHOOP";
lastHRUpdate = millis();
Serial.println("*** CONNECTED TO WHOOP! ***");
btBuffer = "";
}
}
// Check for connection failure
if (btBuffer.indexOf("OK+CONNF") >= 0) {
Serial.println("Connection failed");
btBuffer = "";
}
// Check for disconnection
if (btBuffer.indexOf("OK+LOST") >= 0) {
btConnected = false;
isNOAHWHOOP = false;
connectedDevice = "";
heartRate = 0;
Serial.println("*** DISCONNECTED ***");
btBuffer = "";
}
// Keep buffer manageable
if (btBuffer.length() > 200) {
btBuffer = btBuffer.substring(100);
}
}
// Process heart rate data after accumulating
// Only process if we're connected and have received data recently
if (btConnected && btBuffer.length() > 0 && (millis() - lastDataTime > 100)) {
// Look for 0x00 byte followed by a valid heart rate value
for (int i = 0; i < btBuffer.length() - 1; i++) {
if ((uint8_t)btBuffer[i] == 0x00) {
uint8_t hrValue = (uint8_t)btBuffer[i + 1];
// Valid heart rate range
if (hrValue >= 30 && hrValue <= 220) {
heartRate = hrValue;
lastHRUpdate = millis();
Serial.print("Heart Rate: ");
Serial.println(heartRate);
// Clear the processed data
btBuffer = btBuffer.substring(i + 2);
break;
}
}
}
// Clear buffer if no valid data found
if (btBuffer.length() > 50) {
btBuffer = "";
}
}
// Check if heart rate data is stale (no update in 15 seconds)
if (millis() - lastHRUpdate > 15000) {
if (btConnected) {
btConnected = false;
isNOAHWHOOP = false;
connectedDevice = "";
}
}
}
void handleIRInput() {
if (IrReceiver.decode()) {
unsigned long code = IrReceiver.decodedIRData.decodedRawData;
// Handle number inputs (0-9)
int digit = getDigitFromCode(code);
if (digit >= 0) {
inputBuffer += String(digit);
if (inputBuffer.length() > 4) {
inputBuffer = inputBuffer.substring(1);
}
// Force display update when number is entered
updateDisplayNow();
}
// Handle special buttons
switch (code) {
case IR_UP:
// Auto-confirm before changing state
if (inputBuffer.length() > 0) {
handleConfirm();
}
changeState(1);
break;
case IR_DOWN:
// Auto-confirm before changing state
if (inputBuffer.length() > 0) {
handleConfirm();
}
changeState(-1);
break;
case IR_POWER:
// Reset to clock display mode
currentState = STATE_DISPLAY_CLOCK;
inputBuffer = "";
break;
case IR_FUNCTION:
// Manual scan for WHOOP
scanForWHOOP();
break;
}
IrReceiver.resume();
}
}
void scanForWHOOP() {
lcd.clear();
lcd.print("Connecting to");
lcd.setCursor(0, 1);
lcd.print("WHOOP...");
// Connect directly to WHOOP MAC address
BTSerial.print("AT+CONE2AB5A5A5E50");
delay(5000);
lcd.clear();
}
int getDigitFromCode(unsigned long code) {
switch (code) {
case IR_0: return 0;
case IR_1: return 1;
case IR_2: return 2;
case IR_3: return 3;
case IR_4: return 4;
case IR_5: return 5;
case IR_6: return 6;
case IR_7: return 7;
case IR_8: return 8;
case IR_9: return 9;
default: return -1;
}
}
void handleConfirm() {
int value = inputBuffer.toInt();
switch (currentState) {
case STATE_SET_CLOCK_HOUR:
if (value >= 0 && value <= 23) {
currentHour = value;
}
inputBuffer = "";
currentState = STATE_SET_CLOCK_MIN;
break;
case STATE_SET_CLOCK_MIN:
if (value >= 0 && value <= 59) {
currentMinute = value;
currentSecond = 0;
}
inputBuffer = "";
currentState = STATE_DISPLAY_CLOCK;
break;
case STATE_SET_ALARM_HOUR:
if (value >= 0 && value <= 23) {
alarmHour = value;
}
inputBuffer = "";
currentState = STATE_SET_ALARM_MIN;
break;
case STATE_SET_ALARM_MIN:
if (value >= 0 && value <= 59) {
alarmMinute = value;
}
inputBuffer = "";
currentState = STATE_DISPLAY_CLOCK;
break;
default:
inputBuffer = "";
break;
}
}
void changeState(int direction) {
inputBuffer = "";
int newState = (int)currentState + direction;
if (newState < STATE_DISPLAY_CLOCK) {
newState = STATE_SET_ALARM_MIN;
} else if (newState > STATE_SET_ALARM_MIN) {
newState = STATE_DISPLAY_CLOCK;
}
// Skip ALARM_ACTIVE in manual navigation
if (newState == STATE_ALARM_ACTIVE) {
newState = direction > 0 ? STATE_DISPLAY_CLOCK : STATE_SET_ALARM_MIN;
}
currentState = (State)newState;
}
void checkAlarm() {
// Reset the trigger flag when we're in a different minute
if (currentHour != alarmHour || currentMinute != alarmMinute) {
alarmHasTriggeredThisMinute = false;
}
// Check if alarm should trigger
if (alarmEnabled && !alarmTriggered && !alarmHasTriggeredThisMinute) {
if (currentHour == alarmHour && currentMinute == alarmMinute) {
if (currentSecond <= 1) {
triggerAlarm();
alarmHasTriggeredThisMinute = true;
}
}
}
// Check if alarm should stop (after 30 seconds)
if (alarmTriggered) {
if (millis() - alarmStartTime >= 30000) {
stopAlarm();
}
}
}
void triggerAlarm() {
alarmTriggered = true;
alarmStartTime = millis();
currentState = STATE_ALARM_ACTIVE;
// Start buzzer with 1000 Hz tone
tone(BUZZER_PIN, 1000);
}
void stopAlarm() {
alarmTriggered = false;
noTone(BUZZER_PIN);
if (currentState == STATE_ALARM_ACTIVE) {
currentState = STATE_DISPLAY_CLOCK;
}
// Force display refresh
lastState = STATE_ALARM_ACTIVE;
lastSecond = -1;
}
void updateDisplay() {
// Only update if state changed or time changed (for clock display)
bool shouldUpdate = false;
if (currentState != lastState) {
shouldUpdate = true;
lastState = currentState;
}
if (currentState == STATE_DISPLAY_CLOCK && currentSecond != lastSecond) {
shouldUpdate = true;
lastSecond = currentSecond;
}
if (currentState == STATE_DISPLAY_HEARTRATE) {
shouldUpdate = true; // Always update HR display
}
if (currentState == STATE_DISPLAY_BT_STATUS) {
shouldUpdate = true; // Always update BT status display
}
if (!shouldUpdate) {
return;
}
updateDisplayNow();
}
void updateDisplayNow() {
lcd.clear();
switch (currentState) {
case STATE_DISPLAY_CLOCK:
// Display only current time
lcd.setCursor(0, 0);
lcd.print(" Current Time");
lcd.setCursor(4, 1);
printTwoDigits(currentHour);
lcd.print(":");
printTwoDigits(currentMinute);
lcd.print(":");
printTwoDigits(currentSecond);
break;
case STATE_DISPLAY_ALARM:
// Display only alarm time
lcd.setCursor(0, 0);
lcd.print(" Alarm Time");
lcd.setCursor(5, 1);
printTwoDigits(alarmHour);
lcd.print(":");
printTwoDigits(alarmMinute);
break;
case STATE_DISPLAY_HEARTRATE:
// Display heart rate
lcd.setCursor(0, 0);
lcd.print(" Heart Rate");
lcd.setCursor(0, 1);
if (btConnected && heartRate > 0) {
lcd.print(" ");
lcd.print(heartRate);
lcd.print(" BPM");
} else {
lcd.print(" Not Connected");
}
break;
case STATE_DISPLAY_BT_STATUS:
// Display Bluetooth connection status
lcd.setCursor(0, 0);
lcd.print("Bluetooth Status");
lcd.setCursor(0, 1);
if (isNOAHWHOOP && btConnected) {
lcd.print(" NOAHWHOOP - OK");
} else if (btConnected) {
lcd.print(" Connected");
} else {
lcd.print(" Disconnected");
}
break;
case STATE_SET_CLOCK_HOUR:
lcd.setCursor(0, 0);
lcd.print("Set Clock Hour:");
lcd.setCursor(0, 1);
if (inputBuffer.length() > 0) {
lcd.print(inputBuffer);
} else {
printTwoDigits(currentHour);
}
lcd.print(" (0-23)");
break;
case STATE_SET_CLOCK_MIN:
lcd.setCursor(0, 0);
lcd.print("Set Clock Min:");
lcd.setCursor(0, 1);
if (inputBuffer.length() > 0) {
lcd.print(inputBuffer);
} else {
printTwoDigits(currentMinute);
}
lcd.print(" (0-59)");
break;
case STATE_SET_ALARM_HOUR:
lcd.setCursor(0, 0);
lcd.print("Set Alarm Hour:");
lcd.setCursor(0, 1);
if (inputBuffer.length() > 0) {
lcd.print(inputBuffer);
} else {
printTwoDigits(alarmHour);
}
lcd.print(" (0-23)");
break;
case STATE_SET_ALARM_MIN:
lcd.setCursor(0, 0);
lcd.print("Set Alarm Min:");
lcd.setCursor(0, 1);
if (inputBuffer.length() > 0) {
lcd.print(inputBuffer);
} else {
printTwoDigits(alarmMinute);
}
lcd.print(" (0-59)");
break;
case STATE_ALARM_ACTIVE:
lcd.setCursor(0, 0);
lcd.print(" Alarm!");
lcd.setCursor(0, 1);
unsigned long elapsed = (millis() - alarmStartTime) / 1000;
unsigned long remaining = 30 - elapsed;
lcd.print(" Time: ");
if (remaining < 10) lcd.print(" ");
lcd.print(remaining);
lcd.print("s ");
break;
}
}
void printTwoDigits(int number) {
if (number < 10) {
lcd.print("0");
}
lcd.print(number);
}r/ArduinoHelp • u/Routine-Winter-3514 • Nov 02 '25
Hello! I am currently attempting to build a cosmic watch V2 detector. Im basically finished but i cant make it save data to a microSD card.
Building the detector is like following a recipe. All the steps have been laid out in an instruction manual, and all the code used has been pre-written. I followed the steps and the result was that the detector counts, and registers when displaying data onto its OLED screen. But when i try to use the SDcard mode, where it saves its data to an SDcard, it doesnt work. In the serial monitor is see that "SD initialization failed", and then it goes on registering observations. Then i check the SDcard and there as been created a .txt file with nothing written inside it. This is the problem. I've been atemtping this using a SanDisk 32GB microSD card formatted as FAT32 with 32 KB unit allocation size.
I have uploaded other arduino programs to the same setup to troubleshoot, they were able to create files and write things inside of them. So it is possible. My conclusion is that there must be something wrong with the code, but i find that highly unlikely as it has been professionally developed.
Is there anyone who might be able to help me in my situation? Attached to this post is the code uploaded to the arduino to run the SD card logging. More information can be found on this github repository: https://github.com/spenceraxani/CosmicWatch-Desktop-Muon-Detector-v2/blob/master/Instructions.pdf
I would appereciate any help!
/*
CosmicWatch Desktop Muon Detector Arduino Code
This code is used to record data to the built in microSD card reader/writer.
Questions?
Spencer N. Axani
[email protected]
Requirements: Sketch->Include->Manage Libraries:
SPI, EEPROM, SD, and Wire are probably already installed.
1. Adafruit SSD1306 -- by Adafruit Version 1.0.1
2. Adafruit GFX Library -- by Adafruit Version 1.0.2
3. TimerOne -- by Jesse Tane et al. Version 1.1.0
*/
#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>
#define SDPIN 10
SdFile root;
Sd2Card card;
SdVolume volume;
File myFile;
const int SIGNAL_THRESHOLD = 50; // Min threshold to trigger on
const int RESET_THRESHOLD = 25;
const int LED_BRIGHTNESS = 255; // Brightness of the LED [0,255]
//Calibration fit data for 10k,10k,249,10pf; 20nF,100k,100k, 0,0,57.6k, 1 point
const long double cal[] = {-9.085681659276021e-27, 4.6790804314609205e-23, -1.0317125207013292e-19,
1.2741066484319192e-16, -9.684460759517656e-14, 4.6937937442284284e-11, -1.4553498837275352e-08,
2.8216624998078298e-06, -0.000323032620672037, 0.019538631135788468, -0.3774384056850066, 12.324891083404246};
const int cal_max = 1023;
//initialize variables
char detector_name[40];
unsigned long time_stamp = 0L;
unsigned long measurement_deadtime = 0L;
unsigned long time_measurement = 0L; // Time stamp
unsigned long interrupt_timer = 0L; // Time stamp
int start_time = 0L; // Start time reference variable
long int total_deadtime = 0L; // total time between signals
unsigned long measurement_t1;
unsigned long measurement_t2;
float temperatureC;
long int count = 0L; // A tally of the number of muon counts observed
float last_adc_value = 0;
char filename[] = "File_000.txt";
int Mode = 1;
byte SLAVE;
byte MASTER;
byte keep_pulse;
void setup() {
analogReference (EXTERNAL);
ADCSRA &= ~(bit (ADPS0) | bit (ADPS1) | bit (ADPS2)); // clear prescaler bits
//ADCSRA |= bit (ADPS1); // Set prescaler to 4
ADCSRA |= bit (ADPS0) | bit (ADPS1); // Set prescaler to 8
get_detector_name(detector_name);
pinMode(3, OUTPUT);
pinMode(6, INPUT);
Serial.begin(9600);
Serial.setTimeout(3000);
if (digitalRead(6) == HIGH){
filename[4] = 'S';
SLAVE = 1;
MASTER = 0;
}
else{
//delay(10);
filename[4] = 'M';
MASTER = 1;
SLAVE = 0;
pinMode(6, OUTPUT);
digitalWrite(6,HIGH);
//delay(2000);
}
if (!SD.begin(SDPIN)) {
Serial.println(F("SD initialization failed!"));
Serial.println(F("Is there an SD card inserted?"));
return;
}
get_Mode();
if (Mode == 2) read_from_SD();
else if (Mode == 3) remove_all_SD();
else{setup_files();}
if (MASTER == 1){digitalWrite(6,LOW);}
analogRead(A0);
start_time = millis();
}
void loop() {
if(Mode == 1){
Serial.println(F("##########################################################################################"));
Serial.println(F("### CosmicWatch: The Desktop Muon Detector"));
Serial.println(F("### Questions? [email protected]"));
Serial.println(F("### Comp_date Comp_time Event Ardn_time[ms] ADC[0-1023] SiPM[mV] Deadtime[ms] Temp[C] Name"));
Serial.println(F("##########################################################################################"));
Serial.println("Device ID: " + (String)detector_name);
myFile.println(F("##########################################################################################"));
myFile.println(F("### CosmicWatch: The Desktop Muon Detector"));
myFile.println(F("### Questions? [email protected]"));
myFile.println(F("### Comp_date Comp_time Event Ardn_time[ms] ADC[0-1023] SiPM[mV] Deadtime[ms] Temp[C] Name"));
myFile.println(F("##########################################################################################"));
myFile.println("Device ID: " + (String)detector_name);
write_to_SD();
}
}
void setup_files(){
for (uint8_t i = 1; i < 201; i++) {
int hundreds = (i-i/1000*1000)/100;
int tens = (i-i/100*100)/10;
int ones = i%10;
filename[5] = hundreds + '0';
filename[6] = tens + '0';
filename[7] = ones + '0';
if (! SD.exists(filename)) {
Serial.println("Creating file: " + (String)filename);
if (SLAVE ==1){
digitalWrite(3,HIGH);
delay(1000);
digitalWrite(3,LOW);
}
delay(500);
myFile = SD.open(filename, FILE_WRITE);
break;
}
}
}
void write_to_SD(){
while (1){
if (analogRead(A0) > SIGNAL_THRESHOLD){
int adc = analogRead(A0);
if (MASTER == 1) {digitalWrite(6, HIGH);
count++;
keep_pulse = 1;}
analogRead(A3);
if (SLAVE == 1){
if (digitalRead(6) == HIGH){
keep_pulse = 1;
count++;}}
analogRead(A3);
if (MASTER == 1){
digitalWrite(6, LOW);}
measurement_deadtime = total_deadtime;
time_stamp = millis() - start_time;
measurement_t1 = micros();
temperatureC = (((analogRead(A3)+analogRead(A3)+analogRead(A3))/3. * (3300./1024)) - 500)/10. ;
if (MASTER == 1) {
digitalWrite(6, LOW);
analogWrite(3, LED_BRIGHTNESS);
Serial.println((String)count + " " + time_stamp+ " " + adc+ " " + get_sipm_voltage(adc)+ " " + measurement_deadtime+ " " + temperatureC);
myFile.println((String)count + " " + time_stamp+ " " + adc+ " " + get_sipm_voltage(adc)+ " " + measurement_deadtime+ " " + temperatureC);
myFile.flush();
last_adc_value = adc;}
if (SLAVE == 1) {
if (keep_pulse == 1){
analogWrite(3, LED_BRIGHTNESS);
Serial.println((String)count + " " + time_stamp+ " " + adc+ " " + get_sipm_voltage(adc)+ " " + measurement_deadtime+ " " + temperatureC);
myFile.println((String)count + " " + time_stamp+ " " + adc+ " " + get_sipm_voltage(adc)+ " " + measurement_deadtime+ " " + temperatureC);
myFile.flush();
last_adc_value = adc;}}
keep_pulse = 0;
digitalWrite(3, LOW);
while(analogRead(A0) > RESET_THRESHOLD){continue;}
total_deadtime += (micros() - measurement_t1) / 1000.;}
}
}
void read_from_SD(){
while(true){
if(SD.exists("File_210.txt")){
SD.remove("File_209.txt");
SD.remove("File_208.txt");
SD.remove("File_207.txt");
SD.remove("File_206.txt");
SD.remove("File_205.txt");
SD.remove("File_204.txt");
SD.remove("File_203.txt");
SD.remove("File_202.txt");
SD.remove("File_201.txt");
SD.remove("File_200.txt");
}
for (uint8_t i = 1; i < 211; i++) {
int hundreds = (i-i/1000*1000)/100;
int tens = (i-i/100*100)/10;
int ones = i%10;
filename[5] = hundreds + '0';
filename[6] = tens + '0';
filename[7] = ones + '0';
filename[4] = 'M';
if (SD.exists(filename)) {
delay(10);
File dataFile = SD.open(filename);
Serial.println("opening: " + (String)filename);
while (dataFile.available()) {
Serial.write(dataFile.read());
}
dataFile.close();
Serial.println("EOF");
}
filename[4] = 'S';
if (SD.exists(filename)) {
delay(10);
File dataFile = SD.open(filename);
Serial.println("opening: " + (String)filename);
while (dataFile.available()) {
Serial.write(dataFile.read());
}
dataFile.close();
Serial.println("EOF");
}
}
Serial.println("Done...");
break;
}
}
void remove_all_SD() {
while(true){
for (uint8_t i = 1; i < 211; i++) {
int hundreds = (i-i/1000*1000)/100;
int tens = (i-i/100*100)/10;
int ones = i%10;
filename[5] = hundreds + '0';
filename[6] = tens + '0';
filename[7] = ones + '0';
filename[4] = 'M';
if (SD.exists(filename)) {
delay(10);
Serial.println("Deleting file: " + (String)filename);
SD.remove(filename);
}
filename[4] = 'S';
if (SD.exists(filename)) {
delay(10);
Serial.println("Deleting file: " + (String)filename);
SD.remove(filename);
}
}
Serial.println("Done...");
break;
}
write_to_SD();
}
void get_Mode(){ //fuction for automatic port finding on PC
Serial.println("CosmicWatchDetector");
Serial.println(detector_name);
String message = "";
message = Serial.readString();
if(message == "write"){
delay(1000);
Mode = 1;
}
else if(message == "read"){
delay(1000);
Mode = 2;
}
else if(message == "remove"){
delay(1000);
Mode = 3;
}
}
float get_sipm_voltage(float adc_value){
float voltage = 0;
for (int i = 0; i < (sizeof(cal)/sizeof(float)); i++) {
voltage += cal[i] * pow(adc_value,(sizeof(cal)/sizeof(float)-i-1));
}
return voltage;
}
boolean get_detector_name(char* det_name)
{
byte ch; // byte read from eeprom
int bytesRead = 0; // number of bytes read so far
ch = EEPROM.read(bytesRead); // read next byte from eeprom
det_name[bytesRead] = ch; // store it into the user buffer
bytesRead++; // increment byte counter
while ( (ch != 0x00) && (bytesRead < 40) && ((bytesRead) <= 511) )
{
ch = EEPROM.read(bytesRead);
det_name[bytesRead] = ch; // store it into the user buffer
bytesRead++; // increment byte counter
}
if ((ch != 0x00) && (bytesRead >= 1)) {det_name[bytesRead - 1] = 0;}
return true;
}r/ArduinoHelp • u/Whatever_org • Oct 25 '25
Hey there, in my project I need to switch a 3.3 V Current with a mosfet and I'm not completely sure if the Arduino Nano can handle that or if I need to amplify the IOpin with a transistor or if I just need a certain Mosfet
Thank you for the help
r/ArduinoHelp • u/NeVaDa_ToRrEs • Oct 22 '25
I have a 7 year old Arduino Uno that has never seen much use, and has just been gathering dust. How do I get it working again? I want to get back into programming so I thought working on this might be a good place to start.
r/ArduinoHelp • u/TreehouseAndy • Oct 20 '25
Hi all. I'm trying to make an Arduino MIDI device. I've done this before, but I lost the code. I want it to transmit the midi over USB, but not serial, I want it to appear as a normal midi device. I'm on an esp32-s3, which I know works as it is the same as my last project. I'm on platformio. I've been trying all day an I'm going round on circles with dependencies and errors. Help would be appreciated.
r/ArduinoHelp • u/strangessssss • Oct 14 '25
I’m not to Arduino (To be honest, I’ve tried it out only with Arduino uno kit) but I’m pretty good developer and free using may technologies. Furthermore, I’ve got the algorithm of this project in js that I created last night. The problem is that I do not know what modules I gotta use for this project. So, for the project I need 48 stepper motors and 6 esp32 that will be connected 8 motors. But I can’t understand how to connect them so that I will be able to control them from one main controller(raspberry or something else)
r/ArduinoHelp • u/ShironekozCosplay • Oct 12 '25
Hi! I'm starting an arduino project to make the mask of Queen from To Be Hero X, but y barely have 0 idea of arduino, and her mask is a chaos Her mask opens and closes thanks that every golden piece makes a 180° turn and become closer when all of them are in the same position. I know that servomotors can make that movement, but they are to big to use one for every piece, and I'm asking if someone knows a way to simplify it
I've already searched several tutorials for iron man mask, but the movement is different and because is a helmet and not a small mask, all the pieces can be hidden under it, but not in this case 😭
Thanks for reading!
r/ArduinoHelp • u/TurkeyDrips • Sep 24 '25
Hello: I hope someone can tell me my problem. The serial monitor on Transmitter is printing the correct data. The Receiver prints everything, but not the data. I've tested my DHT. I think my problem is with the struct and float, part, I can't figure it out. Code below.:
____________________________________________________________________________________
//transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <DHT.h>
#define DHTPIN 2 // DHT22 data pin
#define DHTTYPE DHT22 // DHT type
DHT dht(DHTPIN, DHTTYPE);
RF24 radio(9, 8); // CE, CSN pins
struct SensorData {
float temperature;
float humidity;
};
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
dht.begin();
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_LOW);
radio.stopListening();
}
void loop() {
SensorData data;
data.temperature = dht.readTemperature();
data.humidity = dht.readHumidity();
if (!isnan(data.temperature) && !isnan(data.humidity)) {
radio.write(&data, sizeof(SensorData));
Serial.print("Sent Temp: ");
Serial.print(data.temperature);
Serial.print("C, Hum: ");
Serial.print(data.humidity);
Serial.println("%");
}
delay(2000);
}
____________________________________________________________________________________________
//Receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <LiquidCrystal_I2C.h>
RF24 radio(9, 8); // CE, CSN pins
const byte address[6] = "00001"; // Must match transmitter address
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD I2C address (check yours), columns, rows
struct SensorData {
float temperature;
float humidity;
};
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.print("Receiving Data...");
radio.begin();
radio.openReadingPipe(0, address); // Open reading pipe on address
radio.setPALevel(RF24_PA_MAX);
radio.startListening(); // Receiver starts listening
}
void loop() {
if (radio.available()) {
SensorData data;
radio.read(&data, sizeof(data));
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(data.temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Hum: ");
lcd.print(data.humidity);
lcd.print(" %");
Serial.print("Received - Temp: ");
Serial.print(data.temperature);
Serial.print("C, Humidity: ");
Serial.print(data.humidity);
Serial.println("%");
}
}
r/ArduinoHelp • u/Party_Conversation14 • Sep 21 '25
I have the problem that I connect the water pump to the relay module but it does not turn on, I connected the positive to the no to turn on when it is turned on and the negative to the com but the pump does not turn on, why could that be?
r/ArduinoHelp • u/Julian8383 • Sep 08 '25
Hey guys
I am doing only my second ever arduino project, but im struggling to find a power supply solution to it. Long story short I have x4 SG90 servo motors which I am trying to power from a battery pack that contains x4 AA batteries (just the regular off the self ones, from any local store).
But they are struggling as the servos are not behaving right. All other elements in my circuit are fine (as ive tested them) so ive narrowed it down to a power supply issue.
Can anyone recommend me a method to power these servo motors effectively? The solution has to be mobile and so a power supply from a computer or wall outlet will not work. Its not shown in the schematic, but the battery pack connects to the power rails of the bread board.
Thanks in advance!!
r/ArduinoHelp • u/Connor-Ford • Sep 04 '25
I am trying to get a CNC shield to turn a stepper. As soon as it gets plugged in it makes a buzzing noise, and then when activated via code, it jitters even more and tries to move but nothing actually moves as expected
I’ve referenced many different tutorials trying to figure out how to wire it correctly but am completely stumped
r/ArduinoHelp • u/Infinite_Math7517 • Sep 01 '25
The circuit is two ultrasound sensors, a LCD and a Arduino Uno. I don't know why its not working and don't have anyone to ask so here I am. any help is appreciated. Code is below
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
long Start = 0 ;
int Start1 = 0;
long Start3 = 0;
long End = 0;
int End1 = 0;
long End3 = 0;
long Time = 0;
void setup() {
lcd.init();
lcd.backlight();
pinMode(2, INPUT);
pinMode(4, OUTPUT);
pinMode(10, INPUT);
pinMode(12, OUTPUT);
}
void loop() {
if (Start1 = 0) {
digitalWrite(4, HIGH);
delay (10);
digitalWrite(4, LOW);
Start = pulseIn(2, HIGH);
Start1 = Start * 0.034 / 2;
delay(500);
}
if (Start1 < 0); {
Start3 = millis();
}
if (End1 = 0, Start1 < 0); {
digitalWrite(12, HIGH);
delay (10);
digitalWrite(12, LOW);
End = pulseIn(10, HIGH);
End1 = End * 0.034 / 2;
delay(500);
}
if (End1 < 0) {
End3 = millis();
}
if (End3 < 0) {
Time = End3 - Start3;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(Time);
lcd.setCursor(0, 1);
lcd.print("milliseconds");
delay(2000);
}
}r/ArduinoHelp • u/BrackenSmacken • Aug 16 '25
I have tried 7 different DHTs (11 and 22). Checked the wiring and checked the code several times. The serial monitor always says:
Temperature nan
Humidity nan
I learned nan means "not a number"
Here's the code:
//Transmitter Code
#include <DHT.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RF24 radio(7, 8);
struct MyData {
byte h;
byte t;
};
MyData data;
void setup() {
Serial.begin(9600);
dht.begin();
radio.begin();
radio.openWritingPipe(0xF0F0F0F0E1LL);
radio.setPALevel(RF24_PA_HIGH);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
radio.write(&data, sizeof(data));
if (isnan(h)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
delay(2000);
}r/ArduinoHelp • u/Background-Bench-395 • Aug 09 '25
I’m building a custom LED lighting system for a go-kart using an Arduino. The setup includes multiple COB LED strips (white, red, and yellow) for functions like parking lights, low beam, high beam, turn signals, hazard lights, all controlled by separate buttons on the steering wheel. The challenge is to program smooth fade-in/fade-out effects for certain lights, handle timed blinking sequences for the turn signals, and manage multiple lighting modes without interference or delays between them. Every idea and help is Appreciated
r/ArduinoHelp • u/SamuraiDestroy • Aug 01 '25
r/ArduinoHelp • u/stramarcio • Jul 29 '25
Hi folks, newbie here I'm trying to use a transistor as a switch to turn on a DC motor but is not working. Basically I followed this tutorial https://www.tutorialspoint.com/arduino/arduino_dc_motor.htm but not even this work so basically how I can make a DC motor run without a driver using only a transistor as a switch.
r/ArduinoHelp • u/metroidvictim • Jul 27 '25
r/ArduinoHelp • u/Equivalent_Quit_2586 • Jul 25 '25
when compiling the code in arduino IDE, it says unable to execute file at sketch location
it's an emergency, someone please help fix
r/ArduinoHelp • u/Quiet-Analyst-6889 • Jul 18 '25
I am trying to test my DFPlayer with an Arduino Nano. All the hardware pins are connected properly. I have downloaded all the necessary libraries but everytime the code is uploaded, it always shows:
"An error occurred while uploading the sketch":
Arduino: 1.8.19 (Mac OS X), Board: "Arduino Nano, ATmega328P (Old Bootloader)" Sketch uses 4816 bytes (15%) of program storage space. Maximum is 30720 bytes. Global variables use 353 bytes (17%) of dynamic memory, leaving 1695 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe0
An error occurred while uploading the sketch
Here is the code inputted:
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial mySerial(10, 11); // TX, RX
DFRobotDFPlayerMini myDFPlayer;
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
Serial.println(2);
Serial.println(F("DFPlayer Mini Test"));
if (!myDFPlayer.begin(mySerial)) {
Serial.println(F("DFPlayer not responding! Check wiring and SD card."));
while (true); // freeze here if not connected
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(20); // Set volume (0 to 30)
myDFPlayer.play(1); // Play the first MP3: 0001.mp3
}
void loop() {
// Nothing needed here
}
What is the problem?
r/ArduinoHelp • u/[deleted] • Jun 07 '25
Motor doesnt turn. motor beeps when powered. Im just trying to get it to spin at all and nothings happening. it will be apart of a drone and will have others connected similarly but not even this one works. Both esc and motor were purchased on amazon and do not provide datasheets. The ESC's brand is aneegfpv, it is a 40a max ESC with 2-6s input which is in range of our lipo. The motor is CENPEK A2212 1000KV Brushless Motor 13T. multiple variations of code has been tried.
Codes:
/*ESC calibration sketch; author: ELECTRONOOBS */
#include <Servo.h>
#define MAX_SIGNAL 2000
#define MIN_SIGNAL 1000
#define MOTOR_PIN 9
int DELAY = 1000;
Servo motor;
void setup() {
Serial.begin(9600);
delay(1500);
Serial.println("Program begin...");
delay(1000);
motor.attach(MOTOR_PIN);
motor.writeMicroseconds(MAX_SIGNAL); // Wait for input
motor.writeMicroseconds(MIN_SIGNAL);
}
void loop() {
if (Serial.available() > 0) {
int DELAY = Serial.parseInt();
if (DELAY > 999) {
motor.writeMicroseconds(DELAY);
float SPEED = (DELAY-1000)/10;
Serial.print("\n");
Serial.println("Motor speed:");
Serial.print(" ");
Serial.print(SPEED);
Serial.print("%"); } } }
/*ESC calibration sketch; author: ELECTRONOOBS */
#include <Servo.h>
#define MAX_SIGNAL 2000
#define MIN_SIGNAL 1000
#define MOTOR_PIN 9
int DELAY = 1000;
Servo motor;
void setup() {
Serial.begin(9600);
delay(1500);
Serial.println("Program begin...");
delay(1000);
motor.attach(MOTOR_PIN);
motor.writeMicroseconds(MAX_SIGNAL); // Wait for input
motor.writeMicroseconds(MIN_SIGNAL);
}
void loop() {
if (Serial.available() > 0) {
int DELAY = Serial.parseInt();
if (DELAY > 999) {
motor.writeMicroseconds(DELAY);
float SPEED = (DELAY-1000)/10;
Serial.print("\n");
Serial.println("Motor speed:");
Serial.print(" ");
Serial.print(SPEED);
Serial.print("%"); } } }
#include <Servo.h>
Servo esc;
void setup() {
// put your setup code here, to run once:
esc.attach(10);
esc.write(180);
delay(2000);
esc.write(0);
delay(2000);
esc.write(20);
delay(2000);
esc.write(0);
delay(2000);
}
void loop() {
// put your main code here, to run repeatedly:
esc.write(1000);
delay(5000);
esc.write(0);
}
#include <Servo.h>
Servo esc;
void setup() {
// put your setup code here, to run once:
esc.attach(10);
esc.write(180);
delay(2000);
esc.write(0);
delay(2000);
esc.write(20);
delay(2000);
esc.write(0);
delay(2000);
}
void loop() {
// put your main code here, to run repeatedly:
esc.write(1000);
delay(5000);
esc.write(0);
}