In this lesson we show how to use the IR remote in the Elegoo Smart Car to send signals to the robot. The IR remote sends IR signals to the IR detector on the Electronic Shield sitting on top of the Smart Car. In this lesson we show how to install the IR library, and how to write code to send and detect IR signals. The code we develop in today’s lesson is included below for your convenience.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <IRremote.h> int IRpin=12; IRrecv IR(IRpin); decode_results cmd; void setup() { // put your setup code here, to run once: Serial.begin(9600); IR.enableIRIn(); IR.blink13(true); } void loop() { // put your main code here, to run repeatedly: while (IR.decode(&cmd)==0) { } Serial.println(cmd.value,HEX); delay(500); IR.resume(); } |