Ater reading this tutorial you’ll be able add headlights to your car very easily.
You can also add brake/reverse lights or cop sirens or other lights.
Components I used:
- RC Car Wltoys K989 ……………………………….… Amazon/ Banggood / Shopee
- ESP32 C6 Super Mini ……………………….…….… Amazon / Banggood / Shopee
- 5mm LED Diode Lights – Super Bright …….… Amazon/ Banggood / Shopee
- 5mm Red & Blue Blinking LED Diodes …….… Amazon/ Banggood / Shopee
- Resistor Kit …………………………………………….… Amazon/ Banggood / Shopee
Disclosure: These are affiliate links. I earn a little comission if you use my links to buy the parts.
Please use them to help me continue building cool projects.
3D Print the parts
If you got the same car as i do, you can just download and print the parts to attatch it to your car for free.
I just glued the LEDs to the holes after soldering them and testing the wire sizes.
I also had to cut the car body to be able to see the Head Light LEDs.
I used a hot soldering iron to open a hole and finish the details with a wire cutter.
Wiring the Headlight LEDs
It’s just 2 LEDs that will turn on when i press a button on the controller and turn off when i press it again.
And to use only a single pin on the ESP32-S3 i connected 2 LEDs with a single resistor.
Head Lights:
- Red wire toPin 5
- Black wire to GND
Modify the code to Add Headlight LEDs
Add this to the begining of your car.ino code.
1. Declare the variables and pins.
const int ledHeadlightPin = 5; bool lightActive = false; // LED state bool previousButtonState = HIGH; // Previous button state
2. Edit the setup() and add the Headlight LEDs pins.
// void setup() { pinMode(ledHeadlightPin, OUTPUT); digitalWrite(ledHeadlightPin, LOW);
3. Create a function to enable/disable the LEDs each time a button is pushed.
Must be outside of the loop() and setup().
void toggleLED() { Serial.print("toggleLED triggered "); // Read the current button state bool currentButtonState = digitalRead(ledHeadlightPin); // Check if the button is pressed and released if (previousButtonState == HIGH && currentButtonState == LOW) { // Toggle the LED state lightActive = !lightActive; // Set the LED to the new state digitalWrite(ledHeadlightPin, lightActive ? HIGH : LOW); } // Update the previous button state for the next loop previousButtonState = currentButtonState; }
4. Call the function you just created when a button is pressed on the controller. Button “Z” in this case.
if (dataEspNowIN.Z == 0) { toggleLED(); }
Now when you press Z on the Steering Wheel, turns the LED on and when you press again turns it off.