As a daily motorcycle rider, I often face one of the biggest challenges: staying awake during late-night rides after a long day of work. The drowsiness creeps in, and let’s face it—riding while sleepy is downright dangerous. That’s when I realized I needed a solution, and the idea for the Night Glow Smart Helmet was born.
This isn’t your regular helmet. I integrated an IMU sensor hooked up with cutting-edge Edge AI to detect signs of drowsiness. The second it senses I’m about to doze off, it sends a vibration alert to keep me awake and aware. But I didn’t stop there—why not make safety look good too? I added vibrant lights to the helmet, making it not only functional but also undeniably cool for nighttime rides.
Curious about how I built it? Stick around—this story is packed with tech, creativity, and the drive to make the road a safer place for riders like me.
1. PreparationThis idea has been living rent-free in my head for ages, but I finally decided it was time to turn it into something real. The first step? Diving into my stash of components. I dusted off my storage boxes, hunting for parts that could bring this project to life. It felt like a treasure hunt, sifting through wires, sensors, and forgotten gadgets, piecing together the essentials for this smart helmet. Turns out, a lot of what I needed was already there, just waiting to be used.
As I dug through my old stash, I struck gold: an XIAO ESP32C6, two vibration motors, an IMU sensor (MPU6050), and some LEDs that, to my surprise, still lit up perfectly. That was all I needed to kickstart this project. With these components in hand, I realized I only needed a few extras to bring my vision to life—things like a battery, PCB board, and some cables to tie it all together. Using parts I already had felt not only resourceful but also gave me a sense of satisfaction. It was like these components were waiting for their moment to shine in something big.
I also grabbed a few components I didn’t have to complete what I needed for my project. I got a D313 transistor to replace the relays since using six of them would’ve been way too bulky. Plus, I picked up a step-down converter because I’ll need it to power the microcontroller I’m planning to use later on.
So here's the idea, we're going to use the XIAO ESP32C6 as the main processor. It'll handle controlling the lights for specific patterns and also read data from the MPU6050 sensor. The accelerometer data from the MPU6050 will then be used to detect or predict if someone is feeling drowsy. This will be covered in detail in the third section, which focuses on Edge AI Integration. If drowsiness is detected, the vibrator motor will activate to alert the motorbike rider to stop immediately.
To make it more compact, I'm using the D313 transistor. The D313 is an NPN bipolar transistor often used in simple applications as a replacement for relays. Its main function is as an electronic switch that controls the flow of current in a circuit. The advantages of using the D313 transistor over a relay include its smaller size, lack of moving mechanical parts (making it more durable), and faster response time. To use it, a small signal is applied to the transistor's base, allowing current to flow from the collector to the emitter, effectively replacing the mechanical switch function of a relay. This transistor is suitable for controlling small loads like LEDs or small motors, but it’s important to stay within its maximum current and voltage limits to prevent damage.
Since it works similarly to a relay, we can create specific patterns for the six lights to shine alternately in harmony. With proper setup, we can make our helmet light up beautifully at night.
The LED lights require 12 volts, so we can connect them directly to a 12V battery. Meanwhile, we need 5V power to run the XIAO ESP32C3 and the MPU6050 sensor. To achieve this, we'll use an XL4005 step-down converter to reduce the battery's voltage from 12V to 5V.
Since I’m using a dot PCB this time, the first step is to arrange it to find the optimal position. The arrangement needs to ensure the PCB stays compact, as it will eventually be mounted on a helmet.
Now it’s time to solder. We’ll solder the components onto the dot PCB according to the layout we prepared earlier. The soldering process must be done carefully to ensure each connection is secure and there are no accidental bridges between traces. Use an appropriate soldering iron and make sure the temperature is hot enough to melt the solder smoothly, but not so hot that it damages the components.
Additionally, double-check each connection after soldering to ensure there are no errors that could affect the circuit’s performance. This step is crucial to guarantee the circuit works perfectly when mounted on the helmet later.
Here’s the final result of the PCB, now soldered with all the necessary components. The design is quite simple, but I believe it will be very effective and compact. With its small size and neatly arranged components, this board is ready to be mounted and integrated into the helmet.
Next, we’ll create a machine learning model to detect when someone is drowsy. When a person gets sleepy while riding a motorcycle, they tend to slightly lower their head, then realize it and lift it back up. This pattern can be detected using an IMU MP6050 sensor. The data collected includes gyroscope readings for the x, y, z axes and accelerometer readings for the x, y, z axes. You can download the project code from the attachment and check out the results in the image below.
So, how can we make use of this data? We can leverage artificial intelligence or machine learning to create a model that captures the movement patterns of a drowsy person. This model will allow us to detect if someone is getting drowsy based on the collected data.
The platform we’re using is Edge Impulse. Edge Impulse is a software platform designed to simplify the development and deployment of machine learning (ML) on edge devices like sensors, microprocessors, and microcontrollers. It enables developers, engineers, and innovators to build efficient AI-based applications without needing deep expertise in machine learning.
The data collected from the sensors will be sent to the Edge Impulse platform using a data forwarder. This allows the data to be utilized for training and building the desired model. For further guidance, you can check out the full tutorials at these links: [1][2].
After successfully connecting our device to Edge Impulse, the next step is to access the link provided in the command prompt. Clicking on this link will take you to the Edge Impulse dashboard, where you can begin the data collection process. To start sampling, simply click the Start Sampling button on the screen. Before doing this, however, it’s important to configure parameters such as frequency and sample length.
The frequency is determined based on the delay set in the void loop program in Arduino IDE to ensure the data is collected at consistent intervals. For this project, I used a sample length of 3000 ms (3 seconds), which is sufficient to capture motion patterns in each sampling session.
I created two data classes for this project: Normal and Sleepy. To ensure the model is well-trained, I collected 30 datasets for training and 8 datasets for testing. This adheres to the general standard in machine learning, which involves splitting the dataset into 80% for training and 20% for testing. This ratio ensures the model has enough data to learn effectively while still being able to generalize well when tested with unseen data.
Once the dataset is ready, the next step is to build the machine learning model. For this project, I chose spectral analysis, which is excellent for analyzing repetitive motion, such as data from accelerometers. Spectral analysis extracts the frequency and power characteristics of a signal over time, enabling the identification of relevant patterns. For the model type, I opted for classification. This choice aligns with the primary goal of the project: categorizing data into two classes, Normal and Sleepy. A classification model allows us to learn patterns from the collected data and predict a person’s condition based on those patterns. This approach is expected to deliver accurate results in detecting drowsiness when deployed on edge devices, such as helmets.
The next step is to configure the parameters for the neural network we’ll use. One of the advantages of Edge Impulse is how user-friendly it is for setting up and adjusting model parameters. For this part, I set the training to 20 epochs with a learning rate of 0.0005. Choosing 20 epochs allows the model enough time to learn patterns from the data without overfitting. The learning rate of 0.0005 was selected to ensure the training process is stable, allowing the model to converge without overshooting the optimal point. These parameters can be adjusted based on the complexity of the data and the project’s requirements, but this combination strikes a good balance between training speed and the model’s accuracy in distinguishing between Normal and Sleepy classes.
Last but not least, we can download the model we’ve created in the Arduino Library format. This format makes it easy to integrate the model into Arduino programs for use on edge devices, such as the helmet. The download process in Edge Impulse is straightforward. Once the model is trained and tested, simply go to the Deploy section on the dashboard and select the Arduino Library format. The downloaded file will include all the necessary components, such as header files and resources, to run the model directly on a microcontroller.
Let’s start building the main program. The first step is to test whether the machine learning model we’ve created runs optimally. This test is crucial to ensure the model accurately detects the Normal and Sleepy conditions. Once the model works as expected, we’ll add a reminder feature using a vibration motor. This motor will activate when the model detects a Sleepy condition, providing a physical alert to the user. Next, we’ll add a feature to ensure the helmet lights remain on. This feature is essential to enhance user safety on the road, especially in low-light conditions.
The library we downloaded needs to be imported into Arduino IDE. Next, we’ll use the provided example to test it before making further modifications. Here, we’ll copy data from the dataset to check whether the program we’ve created works as expected. Simply select the part of the data you want to copy, then click Copy. For this test, we’ll use data from one of the 'Sleepy' datasets.
After copying the data, the next step is to paste it into our Arduino program. Then, we can directly upload it to the board using Arduino IDE. Once the upload process is complete, we can check the results on the serial monitor. In this test, the output shows that the Sleepy condition was detected with an accuracy of 99.609%. This demonstrates that the model we created is functioning well in recognizing movement patterns associated with the Sleepy condition.
We’ve tested the program with data copied from the dataset we created. But what if we want to use real data from the sensor? In this case, we need to slightly modify the program to make it compatible with the sensor we’re using. One key step is to modify the void loop function as follows:
void loop() {
// Read gyrometer and accelerometer data
Vector rawGyro = mpu.readRawGyro();
Vector rawAccel = mpu.readRawAccel();
// Fill the buffer
imu_data_buffer[buffer_index++] = rawGyro.XAxis;
imu_data_buffer[buffer_index++] = rawGyro.YAxis;
imu_data_buffer[buffer_index++] = rawGyro.ZAxis;
imu_data_buffer[buffer_index++] = rawAccel.XAxis;
imu_data_buffer[buffer_index++] = rawAccel.YAxis;
imu_data_buffer[buffer_index++] = rawAccel.ZAxis;
// Wrap around buffer index if it exceeds BUFFER_SIZE
if (buffer_index >= BUFFER_SIZE) {
buffer_index = 0;
// Process the data using the Edge Impulse classifier
run_inference();
}
delay(100); // Adjust sampling rate as needed
}
The final step is ensuring that if the classification result indicates a drowsy condition, we can directly activate the mini vibration motor connected to GPIO 19. This mini vibration motor will be mounted inside the helmet and hidden at the back for a discreet and comfortable design. When the helmet detects that the user is drowsy, the mini vibration motor will turn on to provide an alert via vibration. The vibration is designed to be strong enough to wake the user without causing discomfort. This feature is intended to help motorcyclists become aware of their condition and pull over to rest when necessary.
Next, we’ll program the lights. To turn on the lamp, you simply connect 12 volts from the battery to the positive terminal of the lamp, while the negative terminal of the lamp will be connected to the collector, the emitter will be connected to gnd, and connect the base to a pin on the XIAO ESP32C6. If you think about it, this is quite similar to how we use a relay—simple, isn’t it? With this configuration, we can easily control the lights using a digital pin on the microcontroller.
Before we start soldering according to the schematic we’ve designed, the first step is to attach the lights to the helmet. For this project, I’m using 6 colorful lights, arranged with 3 on the right side and 3 on the left side of the helmet. This arrangement is designed to ensure both an attractive appearance and functionality, such as providing clear visibility at night. To secure the lights, I used strong adhesive to make sure they stay in place even when the helmet is subjected to various conditions. Once the lights are properly attached, we can proceed with soldering to connect them according to the planned circuit.
Next, you can create a simple blink program to test whether the circuit you’ve built works properly. In this program, I turned on GPIO00, GPIO1, GPIO2, GPIO21, GPIO16, and GPIO17. Remember, the pin numbers are based on their GPIO numbers, not their digital pin numbers. If everything is done correctly, voila, the lights will blink as programmed. Once that’s working, the next task is to create more interesting blinking patterns by controlling the on and off sequence of each light. Check out the video below to see the results.
Finally, I will combine the entire program into a single, cohesive codebase. To achieve this, I’ve made several adjustments to ensure smooth and parallel execution of LED blinking and running the classifier.
Here’s how I achieved parallel execution:
- Using millis() for non-blocking delays instead of the delay() function. This allows the program to continue executing other tasks while waiting.
- Separating the LED blinking logic and classifier logic into independent loops. Each logic operates independently without interfering with one another.
- Ensuring both loops are called within the main loop() function, enabling them to run simultaneously without blocking.
This approach ensures that the LEDs can keep blinking while the classifier remains active to detect Normal or Sleepy conditions. You can check the final code in the attached program I’ve provided. The code includes all the core functionalities, such as LED control, classifier integration, and vibration motor activation to alert the user when a drowsy condition is detected.
5. Final TouchesEverything has been completed, and everything is working perfectly. However, there’s still one final task. The cables are still messy—just look at the tangled wires on the helmet. While it functions well, the aesthetics are still not quite there.
I only needed a few adhesive clips to reorganize the cable routing. With these clips, the once-messy cables can now be neatly arranged and secured. These clips not only improve the helmet’s aesthetics but also ensure that the cables remain safe and unobtrusive during use. Take a look at the comparison in the image below—the result is much cleaner. With the cables neatly organized, the helmet is not only functional but also more comfortable and visually appealing.
Everything is done! Now it’s time to test it out and see how everything works. Let's try it!
ClosingIt’s incredibly satisfying to turn an old idea that’s been in my head into reality. This helmet is designed to detect when the rider is drowsy and alert them with vibrations. The goal is to encourage riders to pull over and rest, reducing the risk of accidents that could happen if they keep going.
Beyond its primary function, the helmet is also equipped with blinking lights, making it both functional and stylish, especially at night. The integration of functionality, artificial intelligence, and aesthetics makes this helmet not just a safety tool but also a fascinating piece of innovation.
Of course, it’s not perfect—it has its flaws, and it might look a bit rough around the edges. But isn’t that the nature of every prototype? This is just the starting point. Now it’s your turn to take this idea, add your own creativity, and build a better version with even more features.
So, are you ready to create your own smart helmet? 😀😁🪖⛑️🛵🏍️
Comments
Please log in or sign up to comment.