Photon not running DC Motor when IR code received

So thanks to @Moors7, I was able to receive decoded IR signals on my Particle Photon using this [library][1]. My main objective is to make a robot with 2 mini pager motors that have a really small electrical footprint and be controlled by an IR remote. I’m able to receive IR codes in 1 code and run a motor in the other, but can’t do both in the same code.

Here’s the only-motor code:

int mPin = D1;

void setup() {
    pinMode(mPin, OUTPUT);
}

void loop() {
    for(int x = 0; x < 256; x++){
        analogWrite(mPin, x);
        delay(10);
    }
}

Here’s the IR code (by GitHub user: [babean][1]):

#if defined (PARTICLE)
#include "application.h"
#endif

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

Here’s my attempt at joining the two:

#if defined (PARTICLE)
#include "application.h"
#endif

#include <IRremote.h>

int RECV_PIN = 11;
int mPin = 14;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  pinMode(mPin, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver

}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value);
    if(results.value == 2011254812){
        Serial.println("Running Motor");
        analogWrite(mPin, 200);
        delay(1000);
    }
    irrecv.resume(); // Receive the next value
  }
}

I’d appreciate any help, thanks!
[1]: https://github.com/babean/IRRemote

First, please don’t use these anonymous pin numbers, but use A1 & A4 as your pins.

And in order to help you you’d need to state what doesn’t work and what your Serial.print() statements say.

BTW: When you use D1 for one test but then use A4 in your joint code, would it not be more logical to have the motor test code also use the same A4 to get comparable results?

I also see no cide that would ever switch the motor off after turning it on once :confused:

If you just connected the motors straight up to the pins then that might be why, even if they’re mini pager motors. You might want to consider making a circuit to control them or a motor driver. Or like @ScruffR mentioned, it could be part of your code.

Sorry about that @ScruffR , it’s just that the IR library I’m using is still relatively beta and needs pin numbers as such: https://docs.particle.io/assets/images/photon-jtag.png

So pin 11 is used to map out the IR Receiving Pin, and pin 14 (D1) is used to map out the DC Motor.

The first Serial.println tells me the IR code that was received. The second Serial.println tells me that the conditional:

if(results.value == 2011254812)

has passed and is going to attempt to run the motor. This conditional just checks if the received IR code is the code we’re looking for.

So when running, I receive both Serial outputs but the motor itself doesn’t run. Then I’ll try resending the IR code by pressing the button on the remote again, but instead I receive super weird IR codes from the Photon and the motor still doesn’t spin.

@JackD12, I’m using a setup like this to run my motors: https://cdn-learn.adafruit.com/assets/assets/000/002/346/medium800/learn_arduino_breadboard.jpg?1396782072

Nope, the pin numbers on that schema are only physical and don't have anything to do with the software side of things.
D1 = 1 while 14 would map to A4 (as said above) on the software side of things - and 11 = A1.
And if you just tried my suggestion with D1 instead of the wrong 14, you might have seen it work without further ado.

BTW: It doesn't matter if that lib is beta or not. Just replace 11 with A1 in your IR test code and you should see it working still.
You have to use the labels on the device and not any arbitrary pin numbers as those on that schema.

1 Like