We have completed the primary part of our workshop! Now, let’s improve our race track with more advanced features!
In this lesson, we will trigger a race to start without using Arduino’s start button!
How will we do it?
On our board, near our Arduino, we have a small infrared sensor.
Unlike the sensors at the finish line, this sensor will not check if an object is next to it. Instead, this sensor can receive messages using infrared light.
You can find these sensors in many remote-controlled electronic devices. For example, your television and air conditioner may be using these sensors.
Let’s get to work!
How does a remote control work?
We discussed this a little bit in lesson 9, but let’s have a deeper look at the remote control!
Remote controls have an infrared LED to generate infrared light. (or multiple LEDs to make the light shine brighter).
Each time a button is clicked, the remote flashes the LED at a very high frequency (many thousands of blinks per second).
How does the TV know which button was clicked?
On the device you control (example: TV), a sensor sees and recognizes the flashes of infrared light from the remote.
The remote control and the TV have a unique language. The rate and length of the flashes translate into different messages.
Each button will produce a slightly different flash, and the TV can identify each type of flash to know which button is being clicked.
Because we cannot see infrared light, we cannot notice the messages sent by the remote control. But luckily, we have a sensor for this!
To create code that will read and print our sensor’s values, we need to consider the following:
Follow the video and change your code:
After uploading the code, click different buttons on the remote control and pay attention to the 7-segment display.
You should see the digit “1” when the sensor does not see the remote control flashing. Then, you should see “0” when the sensor sees the remote control’s infrared light.
Our race currently starts by clicking on the start button. To create a remote-controlled start, we need to make two small changes to our code:
1) Instead of only reading pin 14 (start button), we will also read pin 10 (infrared sensor).
2) Add the new sensor’s value meaning to our code, which is different than the start button:
Make the changes to your code according to the video below:
We need to allow some time for the infra-red sensor to “rest” between reading the flashes from your remote control. Otherwise, the sensor will not provide reliable values to Arduino. All we need is a small delay of 0.05 seconds (in the video below we use 0.01, but later we found out that 0.05 works better).
Make the changes to the code as shown in the video, and upload it to Arduino:
Once the code is uploaded, try to start the race using the remote control!
Sometimes the infrared sensor can trigger an unwanted start. For example, if someone changes the channel on TV, our sensor will recognize the infrared light and start the race.
If you want to go back to using only the start button, follow the video below:
That’s it! Time to move on to the next lesson and display a rounds counter on the screen!