● The code starts by defining some constants.
● The HOLDBUTTON constant is the number of buttons on the IR remote
control, and the VOLUP, LEFTPUSH, RIGHTPUSH, and PAUSEPLAY
constants are the corresponding button numbers.
● Next, the receiver_pin variable is defined as an integer value that represents
which pin on the Arduino board will be used to receive IR signals from the
remote control.
● The MotorL and MotorR variables are also defined as integers values.
● These represent which motors on the Arduino board will be used to move
objects in a 3D space.
● The trigPin variable is used to control how many degrees each motor can
rotate (it corresponds to a digital input on an Arduino).
● The echoPin variable is used to generate an echo signal that can be detected
by the receiver_pin .
● The duration variable stores how long for each loop iteration (each time
through this code block) it will take for IR signals from the remote control to
reach the receiver_pin .
● The distance variable keeps track of how far away from the receiver_pin
object(s) in 3D space those signals were received.
● This information can then be used to calculate movement trajectories for
objects in a virtual environment created using OpenGL
● The code initiates an IR remote control session by setting up the necessary
pins and variables.
● The receiver_pin variable will be used to identify the IR receiver in use, while
MotorL and MotorR will be used to control the motors on the robot.
● The duration variable will store the length of time that has passed since the
last command was sent from the controller, while distance will keep track of
how far away from the robot the controller is.
● The previousvalue variable will be used to remember what value was set for
MotorL or MotorR when a new command is received.
● The code starts by initializing the serial port at 9600 bps.
● The receiver module is then enabled, and the motor pins are set to output.
● Next, the trigPin and echoPin pins are configured as input/outputs.
● Finally, the code sets up a loop that will run continuously until stopped.
● The first thing that happens in this code is that the receiver module is
initialized.
● This allows it to receive data from the serial port and interpret it as IR signals.
● Once initialized, the receiver can be used to control various motors using IR
commands.
● Next, two pins are configured as outputs: MotorR and MotorL.
● These pins will be used to control the motors connected to them using an IR
signal.
● Finally, a pin is configured as an input: trigPin.
● This pin will be used to detect when a trigger has been activated (by pressing
a button), and also to send out an IR signal whenever an echo occurs (as
when someone speaks into the microphone).
● The code will initialize the serial port and enable IR reception.
● It then sets up the motor pins as outputs and sets up the echo pin as an
input.
● The code starts by turning the trigPin on and off very quickly (2
microseconds).
● This creates a pulse of electricity that can be detected by the echoPin.
● The code then measures how long it took for the echoPin to respond to the
pulse of electricity.
● This is called the duration.
● Next, the code calculates how far away the object was when the pulse of
electricity was sent out (in meters).
● This is done by multiplying the duration by 0.034/2, which is a measure of
distance in meters per second.
● The code will cause the Arduino to continuously send a low signal to the
trigPin and then a high signal to the trigPin for two seconds.
● After two seconds, the code will cause the Arduino to send a low signal to the
trigPin again and wait 10 milliseconds.
● The code then sends a high signal to the trigPin for ten milliseconds, and
calculates the distance between the Arduino and an object using this time
period as well as how long it took for that distance to be traveled.
● The code starts by initializing some variables.
● The distance variable stores the distance between the robot and the wall.
● The motorL and motorR variables control the speed of the motors.
● The loop() function starts by checking to see if the distance is less than 150.
● If it is, then the code avoids a wall by turning off both motors.
● Next, the code reads in codes from the receiver module.
● If it finds a code that matches one of its conditions (HOLDBUTTON,
PAUSEPLAY, VOLUP, LEFTPUSH, or RIGHTPUSH), then it sets a
corresponding variable to previousvalue and runs through the rest of the code
for that condition.
● For example, if it finds a CODE_HOLDBUTTON condition, it sets
previousvalue to be equal to value .
● If there are no more codes to read from the receiver module, then execution
jumps back into loop().
● This time, however, it checks to see if distance is greater than 150.
● If so, it turns on both motors again and continues running through all of the
code blocks for each condition until either distance decreases below 150 or
execution reaches loop().
● The code will: 1.
● Check to see if the distance between the robot and the wall is less than 150
cm.
● If it is, it will avoid the wall by turning its motors off and on.
● 2.
● Once it has avoided the wall, it will check to see if there is a new value in the
receiver's output buffer.
● If so, it will decode that value and use it as a new setpoint for its motors
(based on previousvalue).
● 3.
● It will then repeat steps 2 and 3 until there is no more data in the receiver's
output buffer or until the robot reaches its destination.
● At this point, it will stop moving and print out the current values of its motors
to serial monitor.
Circuit diagram and code
[Link]
=wnblz3ZvJB3jAojYKFeEV0jPOMTIRlVjPP8x0dDk2S0