Boaz Lawnce
Published © GPL3+

Nano IR Remote for DC Motors

Hacked MP3 player remote as DC motor driver.

IntermediateShowcase (no instructions)4,862
Nano IR Remote for DC Motors

Things used in this project

Story

Read more

Schematics

Circuit Diagram

Code

Program

C/C++
#include "IRremote.h"

int receiver = 11;
int velocity1 = 100;
int velocity2 = 100;

int x;
int Power__ON = 0;

const int M1P1 = 7;
const int M1N1 = 8;

const int M2P2 = 9;
const int M2N2 = 10;

const int M1__Speed = 6;
const int M2__Speed = 5;

IRrecv irrecv(receiver);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(M1P1, OUTPUT);
  pinMode(M1N1, OUTPUT);
  pinMode(M2P2, OUTPUT);
  pinMode(M2N2, OUTPUT);
  pinMode(M1__Speed, OUTPUT);
  pinMode(M2__Speed, OUTPUT);
}
void loop()
{
  if (irrecv.decode(&results))
  {
    x = results.value & 0x0000ff;
    Serial.println(results.value, HEX);
    processIR();
    irrecv.resume();
  }
 
}
void processIR()
{
  if (x == 0x1f) //previous
  {
    Serial.println("Motor 1 rotates forward");
    digitalWrite(M1P1, HIGH);
    digitalWrite(M1N1, LOW);
    analogWrite(M1__Speed, velocity1);
  }
  else if (x == 0x57) //next
  {
    Serial.println("Motor 2 rotates forward");
    digitalWrite(M2P2, LOW);
    digitalWrite(M2N2, HIGH);
    analogWrite(M2__Speed, velocity2);
  }
  else if (x == 0x5d) //turn on
  {
    Power__ON = Power__ON + 1;
    int x = Power__ON % 2;
    Serial.println(x);
    if (x == 0)
    {
      Serial.println("Both Motor goes OFF");
      digitalWrite(M1P1, LOW);
      digitalWrite(M1N1, LOW);
      digitalWrite(M1P1, LOW);
      digitalWrite(M1N1, LOW);
      analogWrite(M1__Speed, 0);
      analogWrite(M2__Speed, 0);

    }
    else
    {
      Serial.println("Both Motor ready to run");
      digitalWrite(M1P1, HIGH);
      digitalWrite(M1N1, LOW);
      digitalWrite(M1P1, HIGH);
      digitalWrite(M1N1, LOW);
    }
  }
  else if (x == 0x67) // vol+
  {
    velocity1 = velocity1 + 10;
    analogWrite(M1__Speed, velocity1);
    Serial.println(velocity1);
  }
  else if (x == 0x97) // vol-
  {
    velocity1 = velocity1 - 10;
    analogWrite(M1__Speed, velocity1);
    Serial.println(velocity1);
  }
  else if (x == 0xdd) //mode
  {
    velocity2 = velocity2 + 10;
    analogWrite(M2__Speed, velocity2);
    Serial.println(velocity2);
  }
  else if (x == 0x3d) //equ
  {
    velocity2 = velocity2 - 10;
    analogWrite(M2__Speed, velocity2);
    Serial.println(velocity2);
  }
  else
  {

  }
  delay(500);
}

Credits

Boaz Lawnce

Boaz Lawnce

11 projects • 38 followers
Electronics Engineer, Founder, Hobbyist....

Comments