Infrared (IR) Controlled Lights with MakeCode: Adafruit Circuit Playground Express

Updated 22 April 2018

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.

Adafruit Circuit Playground Express IR

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.


The Code

MakeCode screenshot IR controlled lights adafruit circuit playground express

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.

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.