V
V
vaselekk2020-12-31 11:50:55
Arduino
vaselekk, 2020-12-31 11:50:55

Why won't the motor start?

I wanted to make that when you press the "forward" button on the remote control, the motor rotates for 1 second. The motor itself works with Arduino, but for some reason it does not work with signal processing. Please tell me what is wrong?

The code:

#include "IRremote.h"
#include <AFMotor.h>     // подключаем библиотеку для шилда
AF_DCMotor motor1(1); // подключаем мотор к клеммникам M1


IRrecv irrecv(2); // указываем вывод, к которому подключен приемник

decode_results results;

void setup() {
  Serial.begin(9600); // выставляем скорость COM порта
  irrecv.enableIRIn(); // запускаем прием
  motor1.setSpeed(255); // задаем максимальную скорость мотора
  motor1.run(RELEASE);   // останавливаем мотор
}

void loop() {
  if ( irrecv.decode( &results )) { // если данные пришли

String stringOne =  String(results.value, HEX);   
Serial.println(stringOne);  
if(stringOne == "3d9ae3f7") {

motor1.run(FORWARD);  // задаем движение вперед
}

irrecv.resume(); // принимаем следующую команду
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
milssky, 2020-12-31
@milssky

if(stringOne == "3d9ae3f7") {

motor1.run(FORWARD);  // задаем движение вперед
}

I understand that this condition is not met or something else? If you remove it, does the motor start spinning?

K
kalapanga, 2020-12-31
@kalapanga

The IRremote and AFMotor libraries are in conflict. They use the same hardware timer by default. It is necessary to reconfigure one of them for another. The details are googling.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question