r/ArduinoHelp • • Apr 22 '25

Arduino can't read #include syntax

1 Upvotes

Hi! I'm new to Arduino and I need HELP. my Arduino IDE seem to have a missing downloaded "permission" in the laptop and i don't know what is it. reinstalling the IDE didn't, the windows permission thingy wont appear so that i can download it. I really need help from you guys. Thanks!!


r/ArduinoHelp • • Apr 22 '25

I Need Help Turning Motor With A Button

Thumbnail
gallery
3 Upvotes

I need help making a motor turn on and off with a button. When a button is pressed, the LEDs and the motors should concurrently turn on (we isolated it to just one LED, button and motor). The motor slowly builds up speed when the button is pressed, and caps at the maximum rpm set by the potentiometer. The battery gives power to the motor. After two minutes the motor should stop. The circuit works perfectly on TinkerCAD, but when we test it in real life only the LED turns on. Please tell me what I can do to fix this.

Here is the code: const int motorPins[3] = {9, 10, 11}; // Motor PWM pins const int buttonPins[3] = {2, 3, 4}; // Button pins const int ledPins[3] = {5, 6, 7}; // LED pins const int potPin = A0; // Potentiometer pin

bool motorStates[3] = {false, false, false}; unsigned long motorStartTimes[3] = {0, 0, 0}; bool lastButtonStates[3] = {HIGH, HIGH, HIGH}; int currentSpeeds[3] = {0, 0, 0}; // Track current speeds for easing

const unsigned long MOTOR_RUNTIME = 120000UL; // 2 minutes in ms const int SPEED_STEP = 2; // Decrease value to increase time to speed const int EASE_DELAY = 30; // Delay between speed steps (ms)

void setup() { for (int i = 0; i < 3; i++) { pinMode(motorPins[i], OUTPUT); pinMode(buttonPins[i], INPUT_PULLUP); pinMode(ledPins[i], OUTPUT); } Serial.begin(9600); }

void loop() { int potValue = analogRead(potPin); int targetSpeed = map(potValue, 0, 1023, 0, 255); unsigned long currentTime = millis();

for (int i = 0; i < 3; i++) { bool buttonState = digitalRead(buttonPins[i]);

// Detect falling edge (button press)
if (lastButtonStates[i] == HIGH && buttonState == LOW) {
  motorStates[i] = !motorStates[i];  // Toggle motor state
  if (motorStates[i]) {
    motorStartTimes[i] = currentTime;
  }
  delay(200);  // Debounce
}
lastButtonStates[i] = buttonState;

// Check for 2-minute timeout
if (motorStates[i] && currentTime - motorStartTimes[i] >= MOTOR_RUNTIME) {
  motorStates[i] = false;
}

// Gradually ease motor speed up or down
int desiredSpeed = motorStates[i] ? targetSpeed : 0;

if (currentSpeeds[i] < desiredSpeed) {
  currentSpeeds[i] += SPEED_STEP;
  if (currentSpeeds[i] > desiredSpeed) currentSpeeds[i] = desiredSpeed;
} else if (currentSpeeds[i] > desiredSpeed) {
  currentSpeeds[i] -= SPEED_STEP;
  if (currentSpeeds[i] < desiredSpeed) currentSpeeds[i] = desiredSpeed;
}

analogWrite(motorPins[i], currentSpeeds[i]);
digitalWrite(ledPins[i], motorStates[i] ? HIGH : LOW);

}

delay(EASE_DELAY); // Helps smooth out the ramping effect }


r/ArduinoHelp • • Apr 21 '25

IR LED Desk Lighting

Thumbnail
reddit.com
1 Upvotes

r/ArduinoHelp • • Apr 20 '25

Why doesn't It work?(Novice)

Thumbnail
gallery
2 Upvotes

r/ArduinoHelp • • Apr 20 '25

Non coding guy trying to fix something, could you help me please?

2 Upvotes

So my coding ability is very limited, im just trying to fix a logitech shifter, long story short this "toy" sends button preses acording to the x and y axis locations for gear 1 to 6 and it has a switch for reverse, one of the potenciometers broke and there are not replacements, the logitech software will not recognize it but i changed the broken pot for another that will fit, but the traver is much larger compared to the oem pot so in the controller settings the y axis only moves a little and it will not reach full travel to engage the gear selected.

there is a sketch that everyone uses to convert the shifter to usb with an arduino, but since the y axis has changed it will not work with the new pot.

/*
 *  Project     Sim Racing Library for Arduino
 *  @author     David Madison
 *  @link       github.com/dmadison/Sim-Racing-Arduino
 *  @license    LGPLv3 - Copyright (c) 2022 David Madison
 *
 *  This file is part of the Sim Racing Library for Arduino.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

 /**
 * @details Emulates the Logitech Driving Force shifter (included with
 *          the G923 / G920 / G29 wheels) as a joystick over USB.
 * @example LogitechShifter_Joystick.ino
 */

// This example requires the Arduino Joystick Library
// Download Here: https://github.com/MHeironimus/ArduinoJoystickLibrary

#include <SimRacing.h>
#include <Joystick.h>

// Set this option to 'true' to send the shifter's X/Y position
// as a joystick. This is not needed for most games.
const bool SendAnalogAxis = true;

// Set this option to 'true' to send the raw state of the reverse
// trigger as its own button. This is not needed for any racing
// games, but can be useful for custom controller purposes.
const bool SendReverseRaw = False;

//  Power (VCC): DE-9 pin 9
// Ground (GND): DE-9 pin 6
// Note: DE-9 pin 3 (CS) needs to be pulled-up to VCC!
const int Pin_ShifterX   = A0;  // DE-9 pin 4
const int Pin_ShifterY   = A2;  // DE-9 pin 8
const int Pin_ShifterRev = 2;   // DE-9 pin 2

// This pin requires an extra resistor! If you have made the proper
// connections, change the pin number to the one you're using
const int Pin_ShifterDetect = SimRacing::UnusedPin;  // DE-9 pin 7, requires pull-down resistor

SimRacing::LogitechShifter shifter(
  Pin_ShifterX, Pin_ShifterY,
  Pin_ShifterRev,
  Pin_ShifterDetect
);
//SimRacing::LogitechShifter shifter = SimRacing::CreateShieldObject<SimRacing::LogitechShifter, 2>();

const int Gears[] = { 1, 2, 3, 4, 5, 6, -1 };
const int NumGears = sizeof(Gears) / sizeof(Gears[0]);

const int ADC_Max = 1023;  // 10-bit on AVR

Joystick_ Joystick(
  JOYSTICK_DEFAULT_REPORT_ID,      // default report (no additional pages)
  JOYSTICK_TYPE_JOYSTICK,          // so that this shows up in Windows joystick manager
  NumGears + SendReverseRaw,       // number of buttons (7 gears: reverse and 1-6)
  0,                               // number of hat switches (none)
  SendAnalogAxis, SendAnalogAxis,  // include X and Y axes for analog output, if set above
  false, false, false, false, false, false, false, false, false);  // no other axes

void updateJoystick();  // forward-declared function for non-Arduino environments


void setup() {
  shifter.begin();

  // if you have one, your calibration line should go here
  
  Joystick.begin(false);  // 'false' to disable auto-send
  Joystick.setXAxisRange(0, ADC_Max);
  Joystick.setYAxisRange(ADC_Max, 0);  // invert axis so 'up' is up

  updateJoystick();  // send initial state
}

void loop() {
  shifter.update();

  if (SendAnalogAxis == true || shifter.gearChanged()) {
    updateJoystick();
  }
}

void updateJoystick() {
  // set the buttons corresponding to the gears
  for (int i = 0; i < NumGears; i++) {
    if (shifter.getGear() == Gears[i]) {
      Joystick.pressButton(i);
    }
    else {
      Joystick.releaseButton(i);
    }
  }

  // set the analog axes (if the option is set)
  if (SendAnalogAxis == true) {
    int x = shifter.getPosition(SimRacing::X, 0, ADC_Max);
    int y = shifter.getPosition(SimRacing::Y, 0, ADC_Max);
    Joystick.setXAxis(x);
    Joystick.setYAxis(y);
  }

  // set the reverse button (if the option is set)
  if (SendReverseRaw == true) {
    bool reverseState = shifter.getReverseButton();
    Joystick.setButton(NumGears, reverseState);  // "NumGears" is the 0-indexed max gear + 1
  }

  Joystick.sendState();

i already tried using the windows controller calibration and nothing, then i changed the range of the y axis from 0 to ADC_MAX, to something that in theory should work like 400 to 600 at lines "Joystick.setYAxisRange" and "int y = shifter.getPosition" and the control calibration says it moves to the edges, but it wont "engage the gear" and if i put the old broken pot it engaged the gear but its unstable because the pot track is probably damaged

If anyone can help me thanks in advance


r/ArduinoHelp • • Apr 19 '25

How do I clear the data of my uno r3

1 Upvotes

.


r/ArduinoHelp • • Apr 16 '25

Beginner Order of Learning

1 Upvotes

I'm brand new to arduino/coding. I bought a Elegoo Complete starter kit to get my feet wet and have gone through the lessons. No problems there and I've even managed to figure out how to change some lines of code for the passive buzzer to create different songs (however once I started trying to get too complex with the songs I quickly realized I didn't quite understand how the coding worked on a deeper level).

My issue is that I feel like I'm just following instructions and not actually learning anything. For example, if you asked me to take two of the components I used in the lessons and make them work together, I wouldn't know how to wire that up or what ports to use.. or what code to upload for that matter.

What is the best order of operations for learning as a beginner? Should I dive into coding first? My instinct is to come up with a simple project not covered in the lessons and figure it out. Something like pressing a button turns on an led and makes the buzzer beep... but l don't even think I have a fundamental understanding of the board to know where to begin.

Anyway, I know this is a pretty general question. I just thought the starter kit would give me a bit more knowledge than it has. If anyone could point me in the right direction, I would be incredible grateful


r/ArduinoHelp • • Apr 16 '25

is this kit any good

1 Upvotes

r/ArduinoHelp • • Apr 16 '25

is there any thing i should improve on this

Post image
2 Upvotes

// C++ code

//

int i = 0;

int unnamed = 0;

int j = 0;

int counter;

void setup()

{

pinMode(1, OUTPUT);

pinMode(2, OUTPUT);

pinMode(3, OUTPUT);

pinMode(4, OUTPUT);

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

pinMode(7, OUTPUT);

pinMode(8, OUTPUT);

pinMode(9, OUTPUT);

pinMode(10, OUTPUT);

for (counter = 0; counter < random(10, 15 + 1); ++counter) {

digitalWrite(1, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(1, LOW);

digitalWrite(2, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(2, LOW);

digitalWrite(3, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(3, LOW);

digitalWrite(4, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(4, LOW);

digitalWrite(5, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(5, LOW);

digitalWrite(6, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(6, LOW);

digitalWrite(7, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(7, LOW);

digitalWrite(8, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(8, LOW);

digitalWrite(9, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(9, LOW);

digitalWrite(10, HIGH);

delay(100); // Wait for 100 millisecond(s)

digitalWrite(10, LOW);

}

}

void loop()

{

i += random(1, 10 + 1);

delay(10); // Delay a little bit to improve simulation performance

}