The latest Circuit Playground board, the Adafruit Circuit Playground Express comes equipped with an onboard IR transmitter and receiver! This can be used to communicate with TVs and other household devices. You can also use infrared remote controls to control your Circuit Playground Express. You can use another Circuit Playground Express as a remote to control your CPX, and you can even send simple messages between Circuit Playgrounds. By measuring the raw reflected IR light bouncing off of nearby objects you can make a simple proximity sensor!
For this project, we will be utilizing the infrared transmitter and receiver to control two different light animations on our Circuit Playground Express. We will put the same program on two Circuit Playgrounds, so one can act as both a remote and a receiver. The transmit and receive on the Circuit Playground Express works reliably up to three meters. If you are only receiving signals with the Circuit Playground and controlling using a TV remote, you should have longer range.
There are two parts for infrared. The transmitter is the clear LED to the left of center on the board marked with TX, its connected to pin #29. The receiver is the darker LED to the right of center marked with RX. The receiver also has a decoder chip that receives the 28KHz signals and demodulates them. Demodulated output from the receiver is available on pin #39.
If you want to use the infrared transmitter and receiver as a proximity sensor, then you need to use the raw analog value from the receiver. The direct analog value is available on pin A10.
For our program, we will create a command to transmit a number when button A or button B is pressed, and a loop to wait for a received number. This is the first program we have made in MakeCode that uses a Variable. The standard variables in MakeCode are “item” and “num”. We will use the “num” variable for our received number, whatever the infrared receiver reads will be stored as that variable.
The “on infrared received” loop waits for an infrared signal then runs everything within its brackets. For this program, we will use if-else logic. If the variable “num” is equal to 0, then the rainbow animation is played for two seconds. If anything else is received then it plays a sparkle animation. When the animation is finished the lights are turned off.
There are a lot of fun possibilities with the infrared transmitter and receiver. A great project could be making a laser tag game with two Circuit playgrounds or a tree ornament that changes animations remotely. You could use the infrared to send messages to another Circuit Playground Express, or make a robot controlled by infrared. There are a lot of possibilities, so get tinkering! Be sure to share your projects on our forum! There are many other tutorials for the Adafruit Circuit Playground Express if you are looking for direction or inspiration.