IR not working when motor connected

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I am using a Leonardo board with IR remote and an LED. I have used remote library and everything seems to be fine. LED is connected to PIN9 and IR receiver is connected to PIN11.

Now the issue is when I connect a motor, it seems to not work at all. I have connected an LED to check if remote is working. When I press the power button on remote, LED turns on and the motor starts running. Serial monitor shows the received hex code. Once the motor starts working, it fails to detect any further codes from the remote and serial monitor shows junk values as received values even though I do not press any button on the remote controller. I am using the same power source for both the motor and Leonardo board. I even tried to isolate motor and IR circuit (physically and different power supply), but no hope. Any idea what might be causing this issue?

 

Attached a rough schematic and code below.


/* 
 This sketch uses Ken Shirriff's IR library
*/

#include "IRstepI.h"

// Hex values of each button on remote control

#define POWER 0xF61E2A57//power//0x1FE48B7
#define MODE 0x1AD1ED61//menu//0x1FE58A7
#define MUTE 0x1FE7887
#define PLAY 0x1FE807F
#define REWIND 0x81930A09//down//0x1FE40BF
#define FORWARD 0xC20370A1//up//0x1FEC03F
#define EQUIL 0x1FE20DF
#define VOLUMEM 0x983AB4C1//left//0x1FEA05F
#define VOLUMEP 0x21035431//right//0x1FE609F
#define ZER0 0x1FEE01F
#define REPT 0x1FE10EF
#define USD 0x1FE906F
#define ONE 0x1FE50AF
#define TWO 0x1FED827
#define THREE 0x1FEF807
#define FOUR 0x1FE30CF
#define FIVE 0x1FEB04F
#define SIX 0x1FE708F
#define SEVEN 0x1FE00FF
#define EIGHT 0x1FEF00F
#define NINE 0x1FE9867

int receiver = 11;
int powerLed = 13;
int powerStatus = 0;
int motorPin = 9;
int ledOn = 500;
int ledOff = 500;
int remoteValue = 50;

IRrecv irrecv(receiver);
decode_results results;

void setup()
{
  pinMode(powerLed, OUTPUT);
  pinMode(motorPin, OUTPUT);
// Set up serial communication
  Serial.begin(9600);
//  while (!Serial) {
//    ; // wait for serial port to connect
//  }
  irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
  if (irrecv.decode(&results))
  {
    Serial.print("Hex Value = ");
    Serial.print(results.value, HEX);  // print raw values
    translateIR(); 
    irrecv.resume(); // wait for the next value
  }
 controlComponents();
}

void translateIR()
{
//  Serial.print(" : Button = ");
  switch(results.value)
  {
 case POWER:
//    Serial.print(" POWER ");
 powerBoard(); // turn on circuit
    break;
 case MODE:
 //   Serial.print(" MODE "); 
 break;
 case MUTE:
//    Serial.print(" MUTE ");
    break;
 case PLAY:
//    Serial.print(" PLAY ");
    break;
 case REWIND:
//    Serial.print(" REWIND ");
 remoteValue = remoteValue - 10;
    break;
 case FORWARD:
//    Serial.print(" FORWARD ");
 remoteValue = remoteValue + 10;
    break;
 case EQUIL:
//    Serial.print(" EQUILISER ");
    break;
  case VOLUMEM:  
//    Serial.print(" VOLUME MINUS "); 
    break;
  case VOLUMEP:  
//    Serial.print(" VOLUME PLUS "); 
    break;
  case ZER0:  
//    Serial.print(" ZERO "); 
    break;
  case REPT:  
//    Serial.print(" REPEAT "); 
    break;
  case USD:  
//    Serial.print(" US/D "); 
    break;
  case ONE:  
//    Serial.print(" ONE "); 
    break;
  case TWO:  
//    Serial.print(" TWO "); 
    break;
  case THREE:  
//    Serial.print(" THREE "); 
    break;
  case FOUR:  
//    Serial.print(" FOUR "); 
    break;
  case FIVE:  
//    Serial.print(" FIVE "); 
    break;
  case SIX:  
//    Serial.print(" SIX "); 
    break;
  case SEVEN:  
//    Serial.print(" SEVEN "); 
    break;
  case EIGHT:  
//    Serial.print(" EIGHT "); 
    break;
  case NINE:  
//    Serial.print(" NINE "); 
    break;
//  default: 
//    Serial.print(" #NOT MAPPED ");
  }
  Serial.println();
  delay(250); // avoid multiple presses
}

// This turns on power to the circuit
void powerBoard(){
 if (powerStatus==0) {
  digitalWrite(powerLed, HIGH);   // Turn on the LED
  powerStatus = 1;
 }
 else {
  digitalWrite(powerLed, LOW);    // Turn off the LED     
  powerStatus = 0;
 }
}

// This is the main logic function. Any additional components
// can be attached here and extended.
void controlComponents(){
 if(powerStatus == 1) // checks if power button is on
 {
 controlMotor();
 }
 else{
 digitalWrite(motorPin, LOW);    // sets motor off
 }
}

void controlMotor() {
if(powerStatus == 1)
  if (remoteValue > 255)
  remoteValue = 255;
  if (remoteValue < 0)
  remoteValue = 0;
  analogWrite(motorPin, remoteValue);  // analogRead values go from 0 
  
}

 

Attachment(s): 

Robot building is all about sharing & learning
-----------------------------------
www.robotplatform.com

Last Edited: Mon. Feb 2, 2015 - 10:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It may help to convert the pulsing pwm output from the Arduino to a dc value by adding a 10uf cap from base of Q1 to gnd, this "filter" will help smooth out the pwm pulses and provide a smoother drive for your motor.  Your dc motor will also produce some hash, so add a 100nF cap across your motor as well to help filter out it's noise. 

Report back what you find after doing the above.  

 

Jim

 

 

FF = PI > S.E.T