0

I am fairly new to the arduino topic and try to get a few things to work together.

First i tried setting up a DC motor that can be controlled via PWM, which works perfectly when used standalone. I can start/stop the motor and change speed depending on the value i send to the PWM pin.

Second i tried to use an RF-5V wireless receiver to work with a remote control from remote switched power outlets. For this one i followed the instructions on how to build a 433mhz sniffer. This all by itself works as well. I can receive diffent codes depending on which keys on the remote i am pressing.

Now the fun part started: I wanted to integrate both of the projects into one, so i could use the remote to start/stop the motor. So i came up with the following circuit:

Circuit of pwm driven motor with wireless receiver

(Thanks for some of you pointing out that the circuit does not match the sketch. I made an error when drawing, but even with the cables attached to the right pins, it works as described)

and the following code (which is partly from the instructions mentioned above):

#include <RCSwitch.h>

// init 433MHz lib
RCSwitch mySwitch = RCSwitch();
unsigned long lOldValue=0;  // to check for consecutive reads on 433MHz
int motorPin = 5; // PWM-Pin to use for motor

void setup()
{
  pinMode(motorPin, OUTPUT);

  Serial.begin(9600);

  // set-up rf receiver
  mySwitch.enableReceive(0);  // 433MHz Receiver on interrupt 0 => that is pin #2
}

void loop()
{
  if (mySwitch.available())
  {
    int value = mySwitch.getReceivedValue();

    // only react, if at least two times same value received
    if (value == lOldValue)
    {
      if (value == 0)
      {
        Serial.print("Unknown encoding");
      }
      else
      {
        Serial.print("Received ");
        Serial.print( mySwitch.getReceivedValue() );
        Serial.print(" / ");
        Serial.print( mySwitch.getReceivedBitlength() );
        Serial.print("bit ");
        Serial.print("Protocol: ");
        Serial.println( mySwitch.getReceivedProtocol() );

    // One of the keys on the remote
    if (value == 274393) {
      Serial.println("got start code, starting motor");
          analogWrite(motorPin, 100); // start the motor
    }

    // another key on the remote
    if (value == 270384) {
      Serial.println("got stop code, stopping motor");
          analogWrite(motorPin, 0); // stop the motor
    }
      }
    }
    lOldValue = value;
    mySwitch.resetAvailable();
  }
}

when i run the code and click on the remote, i get different values shown depending on the key i press. So the wireless receiver works as expected.

When i receive the right value for starting the motor, the motor really begins to turn, so this works as well.

And here the fun part starts: As soon as i use the analogWrite function to send data to the PWM port the motor is connected to, the wireless receiver stops working (or at least I do not get any more values when pressing a key on the remote).

I found a few similar posts/problem descriptions on the net which said to try the following:

  • Use another pin for PWM (due to possible interrupt conflicts). I tried that as well, same behaviour
  • Use external power supply instead of USB-Cable, which helped somebody resolve this issue. Not here. Does not work either

So the question is: Does anybody know how to combine those two things together so a can use the wireless receiver to get commands and switch on/off the motor with it?

Olli
  • 1,708
  • 10
  • 21
  • If you disconnect the motor, leaving the same program, and maybe putting an LED with the resistor, does this solve the problem? If it is solved, the problem is either the insufficient power or the noise. You can solve the first by powering the circuits externally (try with a bench power supply, then you cna try to use a single battery, but just confirm this before starting to design it). If it is some noise, put a capacitor next to the motor power supply (the bigger the better, at least a couple of hundred of microfarads). – frarugi87 Jan 09 '17 at 15:50
  • @frarugi87 Funnily the problem still exists, when i do not connect the motor to the circuit. Even calling the analogWrite without hardware attached results in the same behaviour. – Olli Jan 09 '17 at 16:00
  • Wait, you wrote `int motorPin = 5;`, but in the schematic you attached the motor to pin 3, and on pin 5 you have the 433 transceiver... Did you correct it correctly? – frarugi87 Jan 09 '17 at 16:06
  • @frarugi87 Oh stupid me... i really made the circuit graphics wrong.. sorry about that.. this happened after i changed the PWM pin a few times and got confused... :( but having the cables like the code uses it, it still didn't work. – Olli Jan 09 '17 at 19:54
  • does it work when you don't connect the motor _and_ don't connect the diode? – dandavis Jan 09 '17 at 22:37
  • @dandavis thanks for the hint.. i will try that tonight! haven't tried this combination! – Olli Jan 10 '17 at 07:37
  • well if it's backwards, then activating the npn would pull down the 5v rail... – dandavis Jan 10 '17 at 10:56

1 Answers1

0

I have the same problem in the past. The problem is the ability of arduino to supply them both. I recommend to use external power supply for the receiver or for the motor (it's best to do that for the motor but according to your circuit it's impossible) like the 545043YwRobot and supply the other from the arduino (I hope this is not what you try already, if so i'm sorry).

Hope it's help.

Yoav

  • thanks for that information. I will try to check if this would solve the issue. But due to limited space in my design i wouldnt be able to add two power supplies in my case. I hoped to be able to use only one 9v block to power the whole circuit. Any ideas on this? – Olli Jan 09 '17 at 14:53
  • try to go to the arduino, and to regulator directly from the battery. – YoavShtainer Jan 09 '17 at 14:58