Arduino Code Please Help

Joined
Oct 29, 2024
Messages
2
Reaction score
0
What I am trying to do is control the step motor 28BYJ-48 5VDC with the given ir remote in the arduino uno r3 kit. The functions I need is to rotate clockwise when a button is pressed, rotate counterclockwise when the other button is pressed, and for it to stop when a third button is pressed. This is my code so far:

//3108437760 vol+ B946FF00
//3091726080 func/stop B847FF00
//3141861120 |<< BB44FF00
//3208707840 play pause BF40FF00
//3158572800 >>| BC43FF00
//4161273600 down F807FF00
//3927310080 vol- EA15FF00
//4127850240 up F609FF00
//3910598400 0 E916FF00
//3860463360 EQ E619FF00
//4061003520 st/rept F20DFF00
//4077715200 1 F30CFF00
//3877175040 2 E718FF00
//2707357440 3 A15EFF00
//4144561920 4 F708FF00
//3810328320 5 E31CFF00
//2774204160 6 A55AFF00
//3175284480 7 BD42FF00
//2907897600 8 AD52FF00
//3041591040 9 B54AFF00

#include <IRremote.h>
#include <Stepper.h>

// Stepper motor configuration
const int stepsPerRevolution = 2048; // 28BYJ-48 has 2048 steps per revolution

// Pin Definitions
const int motorPin1 = 8; // IN1
const int motorPin2 = 9; // IN2
const int motorPin3 = 10; // IN3
const int motorPin4 = 11; // IN4
const int receiverPin = 2; // Pin for the IR receiver

// Create objects
IRrecv irrecv(receiverPin);
decode_results results;
Stepper stepper(stepsPerRevolution, motorPin1, motorPin2, motorPin3, motorPin4);

// Define your IR remote button codes (change these according to your remote)
const int forwardCode = 0xF30CFF00; // Replace with your specific forward button code
const int backwardCode = 0xE718FF00; // Replace with your specific backward button code
const int stopCode = 0xA15EFF00; // Replace with your specific stop button code

void setup() {
Serial.begin(9600); // Start serial communication for debugging
irrecv.enableIRIn(); // Start the IR receiver

// Set the initial speed
stepper.setSpeed(15); // Set speed in RPM (adjust as necessary)
}

void loop() {
if (irrecv.decode(&results)) { // Check if a new IR code has been received
Serial.println(results.value); // Print the received value for debugging

switch (results.value) {
case forwardCode:
stepper.step(stepsPerRevolution / 10); // Move forward (adjust step count)
break;
case backwardCode:
stepper.step(-stepsPerRevolution / 10); // Move backward (adjust step count)
break;
case stopCode:
// Do nothing (stop moving)
break;
default:
break;
}
irrecv.resume(); // Receive the next value
}
}



The error messages are:

error: duplicate case value
case backwardCode:
case forwardCode:
case stopCode:


Here is the thing, I dont know if I need to input as hex decimal for the inputs of the ir remote or not, however, the correct calibration for both decimal and hex are at the beginning of the code. I also need some help with the wiring and the power source of the step motor driver I am using: Can I use a 9V battery on a separate breadboard for this or do I use the arduino 5V connection for the driver? I would like some pictures as to how I should connect this with a breadboard and wires with the arduino uno r3 kit and all of the devices previously mentioned (ir remote and the step motor).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,949
Messages
2,570,111
Members
46,683
Latest member
Elane75F41

Latest Threads

Top