How it works
A toy car is programmed to stay in the sunlight and turn any time the light sensor senses shade. Both rear wheels of the car are driven by continuous servo motors. When the program starts both motors are driving the car forward. When the light sensor detects light below a given threshold, the program will stop one of the rear wheels causing the car to turn. When the sensor once again senses the sunlight both wheels push forward. The program alternates which wheel will stop when the light sensed is below the threshold.
The Two Wheel Drive Mini Robot Platform
We found our car chassis on Amazon, but they can also be found on eBay or by searching in your favorite search engine for “2WD Mini Robot Platform Kit.” Make sure you get one that looks the same as the chassis in the video to assure it’s compatible with the BrainPad and programs on this page.
There are many rechargeable battery packs available that are meant to power devices (like phones) that have a micro USB connector. You can check Amazon, eBay, or even local dollar stores or other retail outlets. The battery is not necessary to make this car work, but without it, the car will be tethered by the USB cable to your computer or laptop. In the video above and the picture below you can see our blue battery mounted underneath the BrainPad.
[!Tip] Make sure to push the battery towards the back of the car as far as possible. This will put more weight over the drive wheels and give the car better traction.
Luckily something this cool can be coded with only 3 functions. On start, we are going to start the servo motors and set our dark light threshold. The higher the threshold, the darker it will have to be for the brainpad to realize it is dark.
For this example, when it is in the dark, we want our car to turn around and try to find light, so, we will make an “If statement” block so we can tell the car if it is too dark, turn one of the motors on and the other off producing a turn. In this example, we have it set to turn the opposite way each time it is too dark.
Our last block is the easiest. We want the car to continue going forward when it is happy in the sunlight. We will just copy what we did “On Start”
Click below to go to MakeCode and start with the program we just went through. Try changing the threshold based on your lighting or make a dark seeking car!