1.Install Arduino IDE if you don’t have the software. can be downloaded here 

 https://code.google.com/p/arduino/downloads/detail?name=arduino-1.0.5-windows.execan=2

2.copy the Arduino-IRremote-master file that has been provided and then open the Arduino 

 file on your computer at local disk/programfiles/arduino/libraries Paste the file

 Arduino-IRremote-master.

3.Run the Arduino IDE software, click File open and select the IR_Receiver file that 

 has been provided or simply double-click on the IR_receiver.ino file

4.prepare Arduino uno

5.plug in the T-sop or IR Receiver included in the package. we have given the color on 

 each leg of the T-Sop, red for Vcc, Black for Gnd, and blue or yellow for

 to enter analog pin A0.

6.connect the arduino that has been installed with T-sop and upload the IR_receiver. if successful, 

 open Serial Monitor on Arduino IDE. by clicking on the magnifying glass icon in the right corner

 software, and a new window will appear now press a button from the remote that has been provided, you can use any IR remote such as remote tv, mp3 . 

 if a number or value comes out, it means you have succeeded in the first

 stage.now open the IR_Onggobot.ino file after it appears click the ir_command_codes.h option and 

 a command for the robot action will appear. your task now replaces the value

 XXXXXXX in ir_command_codes.h with the number of each key you selected to perform the command. 

 for example, you select button no.1 to go forward then press the number button 1

 and the serial monitor will display a value for example 12345678 and now open the ir_command_codes.h 

 window where you have entered the number from pressing button one to

 ‘const long IR_COMMAND_FORWARD_CODES[] = { xxxxxxxxx };’you change xxxx with the value 12345678  

 obtained from serial monitor button no.1 so ‘const long IR_COMMAND_FORWARD_CODES[] = { 12345678 };

 and select another button for reverse turn command and others.

7.if everything is filled now, upload ir.kolomonggobot.ino to arduino. when Upload done. 

 means the robot is ready to receive commands from the remote control earlier.

8.Install battery and your robot is ready

9.Code https://github.com/ericdir/Ir_-HEXABOT

Source Code :

//this hexabot using IR remote control

#include «IRremote.h»

#include «ir_command_codes.h»

#include

// // Analog pin rof IR receiver sensor

const int IR_PIN = A0;

// pin for servos

const int LEFT_SERVO_PIN = 2;

const int CENTRAL_SERVO_PIN = 4;

const int RIGHT_SERVO_PIN = 7;

// default angle

const long LEFT_SERVO_ZERO_VALUE = 90;

const long RIGHT_SERVO_ZERO_VALUE = 90;

const long CENTRAL_SERVO_ZERO_VALUE = 90;

const long SIDE_SERVOS_FULL_AMPLITUDE = 30;

const long SIDE_SERVOS_HALF_AMPLITUDE = 15;

const long CENTRAL_SERVO_AMPLITUDE = 20;

const long STEP_PERIOD_VERY_SLOW = 2000;

const long STEP_PERIOD_SLOW = 1500;

const long STEP_PERIOD_FAST = 1000;

const long STEP_PERIOD_VERY_FAST = 500;

long lastMillis;

long globalPhase;

float angleShiftLeftServo;

float angleShiftRightServo;

float angleShiftCentralServo;

long stepPeriod;

long amplitudeLeftServo;

long amplitudeRightServo;

boolean isAttached;

boolean isStopped;

// // EN: IRreceiver code

IRrecv irrecv(IR_PIN);

Servo LeftServo;

Servo RightServo;

Servo CentralServo;

void attachServos() {

 if (!isAttached) {

  LeftServo.attach(LEFT_SERVO_PIN);

  RightServo.attach(RIGHT_SERVO_PIN);

  CentralServo.attach(CENTRAL_SERVO_PIN);

  isAttached = true;

 }

}

void detachServos() {

 if (isAttached) {

  LeftServo.detach();

  RightServo.detach();

  CentralServo.detach();

  isAttached = false;

 }

}

void setup() {

 irrecv.enableIRIn();

 attachServos();

 isStopped = true;

 lastMillis = millis();

 angleShiftLeftServo = 0;

 angleShiftRightServo = 0;

 angleShiftCentralServo = 0;

 stepPeriod = STEP_PERIOD_FAST;

}

int getAngle(long amplitude, long phaseMillis, float shiftAngle) {

 float alpha = 2 * PI * phaseMillis / stepPeriod + shiftAngle;

 float angle = amplitude * sin(alpha);

 return (int)angle;

}

template

boolean hasCode(T (&commandCodes)[N], long code) {

 for (int i = 0; i

  if (commandCodes[i] == code) {

   return true;

  }

 }

 return false;

}

void loop() {

 long millisNow = millis();

 long millisPassed = millisNow — lastMillis;

 if (isStopped) {

  if (millisPassed >= 500) {

   lastMillis = 0;

   detachServos();

  }

  globalPhase = 0;

 } else {

  lastMillis = millisNow;

  globalPhase += millisPassed;

  globalPhase = globalPhase % stepPeriod;

 }

decode_results results;

 if (irrecv.decode(&results)) {

  if (hasCode(IR_COMMAND_FORWARD_CODES, results.value) ||

    hasCode(IR_COMMAND_FORWARD_LEFT_CODES, results.value) ||

    hasCode(IR_COMMAND_FORWARD_RIGHT_CODES, results.value)) {

   attachServos();

   isStopped = false;

   angleShiftLeftServo = 0;

   angleShiftRightServo = 0;

   angleShiftCentralServo = PI/2;

   amplitudeLeftServo = SIDE_SERVOS_FULL_AMPLITUDE;

   amplitudeRightServo = SIDE_SERVOS_FULL_AMPLITUDE;

   if (hasCode(IR_COMMAND_FORWARD_LEFT_CODES, results.value)) {

    amplitudeLeftServo = SIDE_SERVOS_HALF_AMPLITUDE;

   } else if (hasCode(IR_COMMAND_FORWARD_RIGHT_CODES, results.value)) {

    amplitudeRightServo = SIDE_SERVOS_HALF_AMPLITUDE;

   }

  } else if(hasCode(IR_COMMAND_BACKWARD_CODES, results.value) ||

       hasCode(IR_COMMAND_BACKWARD_LEFT_CODES, results.value) ||

       hasCode(IR_COMMAND_BACKWARD_RIGHT_CODES, results.value)) {

   attachServos();

   isStopped = false;

   angleShiftLeftServo = 0;

   angleShiftRightServo = 0;

   angleShiftCentralServo = -PI/2;

   amplitudeLeftServo = SIDE_SERVOS_FULL_AMPLITUDE;

   amplitudeRightServo = SIDE_SERVOS_FULL_AMPLITUDE;

   if (hasCode(IR_COMMAND_BACKWARD_LEFT_CODES, results.value)) {

    amplitudeRightServo = SIDE_SERVOS_HALF_AMPLITUDE;

   } else if (hasCode(IR_COMMAND_BACKWARD_RIGHT_CODES, results.value)) {

    amplitudeLeftServo = SIDE_SERVOS_HALF_AMPLITUDE;

   }

  } else if (hasCode(IR_COMMAND_TURN_LEFT_CODES, results.value)) {

   attachServos();

   isStopped = false;

   angleShiftLeftServo = 0;

   angleShiftRightServo = PI;

   angleShiftCentralServo = -PI/2;

   amplitudeLeftServo = SIDE_SERVOS_FULL_AMPLITUDE;

   amplitudeRightServo = SIDE_SERVOS_FULL_AMPLITUDE;

  } else if (hasCode(IR_COMMAND_TURN_RIGHT_CODES, results.value)) {

   attachServos();

   isStopped = false;

   angleShiftLeftServo = 0;

   angleShiftRightServo = PI;

   angleShiftCentralServo = PI/2;

   amplitudeLeftServo = SIDE_SERVOS_FULL_AMPLITUDE;

   amplitudeRightServo = SIDE_SERVOS_FULL_AMPLITUDE;

  } else if (hasCode(IR_COMMAND_STOP_CODES, results.value)) {

   attachServos();

   isStopped = true;

   angleShiftLeftServo = 0;

   angleShiftRightServo = 0;

   angleShiftCentralServo = 0;

   amplitudeLeftServo = SIDE_SERVOS_FULL_AMPLITUDE;

   amplitudeRightServo = SIDE_SERVOS_FULL_AMPLITUDE;

  } else if (hasCode(IR_COMMAND_VERY_SLOW_CODES, results.value)) {

   // globalPhase koreksi untuk menyimpan posisi servo ketika mengubah periode.

   globalPhase = globalPhase * STEP_PERIOD_VERY_SLOW / stepPeriod;

   stepPeriod = STEP_PERIOD_VERY_SLOW;

  } else if (hasCode(IR_COMMAND_SLOW_CODES, results.value)) {

   globalPhase = globalPhase * STEP_PERIOD_SLOW / stepPeriod;

   stepPeriod = STEP_PERIOD_SLOW;

  } else if (hasCode(IR_COMMAND_FAST_CODES, results.value)) {

   globalPhase = globalPhase * STEP_PERIOD_FAST / stepPeriod;

   stepPeriod = STEP_PERIOD_FAST;

  } else if (hasCode(IR_COMMAND_VERY_FAST_CODES, results.value)) {

   globalPhase = globalPhase * STEP_PERIOD_VERY_FAST / stepPeriod;

   stepPeriod = STEP_PERIOD_VERY_FAST;

  }

  irrecv.resume();

 }

 if (isAttached) {

  LeftServo.write(LEFT_SERVO_ZERO_VALUE + getAngle(amplitudeLeftServo, globalPhase, angleShiftLeftServo));

  RightServo.write(RIGHT_SERVO_ZERO_VALUE + getAngle(amplitudeRightServo, globalPhase, angleShiftRightServo));

  CentralServo.write(CENTRAL_SERVO_ZERO_VALUE + getAngle(CENTRAL_SERVO_AMPLITUDE, globalPhase, angleShiftCentralServo));

 }

}

ir_command_codes.h

// Command code received from remote IR. One command can be assigned to many codes

// You can type the code of several IR remotes

// You can type the code of several IR remotes^^// Replace xxxxxxxxx with the value that comes out of the serialmonitor when we press the button, select the button to go back and forth and etc.

const long IR_COMMAND_FORWARD_CODES[] = { 16619623 };

const long IR_COMMAND_BACKWARD_CODES[] = { 16615543 };

const long IR_COMMAND_TURN_LEFT_CODES[] = { 16607383 };

const long IR_COMMAND_TURN_RIGHT_CODES[] = { 16591063 };

const long IR_COMMAND_FORWARD_LEFT_CODES[] = { 16593130 };

const long IR_COMMAND_FORWARD_RIGHT_CODES[] = { 16609423 };

const long IR_COMMAND_BACKWARD_LEFT_CODES[] = { 16584943 };

const long IR_COMMAND_BACKWARD_RIGHT_CODES[] = { 16601263 };

const long IR_COMMAND_STOP_CODES[] = { 16623703 };

const long IR_COMMAND_VERY_SLOW_CODES[] = { 16580863 };

const long IR_COMMAND_SLOW_CODES[] = { 16613503 };

const long IR_COMMAND_FAST_CODES[] = { 16597183 };

const long IR_COMMAND_VERY_FAST_CODES[] = { 16621663 };

Leave a Reply