IR Remote Control for Servo Motor with Arduino

Code Explanation

This code controls a servo motor using an IR remote and an Arduino. It includes functions to decode IR signals, validate remote codes, and perform actions based on the received key presses.

IR Remote Codes

The code defines arrays to store IR codes for both white and black remotes, along with their corresponding key names. These codes are specific to the Robojax IR remote but can be modified for other remotes.

White Remote Codes (Non-PCB Version)

unsigned int whiteRemote[] = { ... };

White Remote Codes (PCB Version)

unsigned int whiteRemotePCB[] = { ... };

Black Remote Codes (Non-PCB Version)

unsigned int blackRemote[] = { ... };

Black Remote Codes (PCB Version)

unsigned int blackRemotePCB[] = { ... };

Key Names

The code also defines arrays to store the key names associated with each IR code.

String whiteRemoteKey[] = { ... };

String blackRemoteKey[] = { ... };

Setup Function

The setup() function initializes the serial communication, starts the IR receiver, and attaches the servo to the specified pin.

Loop Function

The loop() function continuously checks for received IR signals. If a signal is detected, it decodes the value and calls the robojaxValidateCode() function to determine the corresponding key press.

robojaxValidateCode Function

The robojaxValidateCode() function validates the received IR code against the defined remote codes and prints the corresponding key name. It also calls the servoAction() function to perform the appropriate action based on the key press.

servoAction Function

The servoAction() function controls the servo motor based on the received key press. It can rotate the servo to the right, left, or center position.

Additional Notes

  • The code assumes you have the IRremote library installed.
  • You need to modify the code to match the pin connections of your servo motor and IR receiver.
  • You can customize the servoAction() function to perform different actions based on the key presses.