Close
0%
0%

Smart Flashlight with XIAO MCU

Made a smart Flashlight using XIAO Microcontroller paired with OLED Expansion Board.

Similar projects worth following
Greetings everyone and welcome back, and here's something Bright and useful.

Using an XIAO SAMD21 M0 microcontroller and an XIAO expansion board, we have created an OverEngineered SMART Flash light from scratch. This light uses an SSD1306 OLED screen to show the light intensity in percentage.
We are using the XIAO SAMD21 M0 microcontroller as the brain of this project, which is connected to a push-button-rocker switch, user can use this switch to change the state of the LED.

Additionally, we are using an A03400 N channel mosfet as a switch configuration linked to an XIAO microcontroller in order to drive LEDs.

The LED load of this flashlight operates in four different ways: 20% power on the first press, 40% power on the second, 100% power on the third, and OFF on the fourth press.

This device was created since I will soon be departing on a camping trip and needed a few camping essentials. A flashlight with wide coverage is one of these essentials. Regretfully, I was unable to find an adequate flashlight, so I aim to build one myself.

The idea was to use the XIAO expansion board, which has a circuit for charging lithium-ion batteries and is ideal for providing power to drive an LED load—in this case, a specially made copper-clad board that was etched.

We are using the XIAO SAMD21 M0 microcontroller as the brain of this project, which is connected to a push-button-rocker switch, user can use this switch to change the state of the LED.

ELECTRONICS: XIAO SAMD21 with Expansion Board

We're using the XIAO SAMD21 M0 Development Board, which, paired with the XIAO extension board manufactured by Seeed Studio, is the heart of this project.

We are using the OLED display and battery charging IC of the XIAO Expansion board, to which we have connected a 2000mAh 3.7V Li-ion battery.

In order to link everything together, we connected the LED load, the Mosfet switch configuration, and the XIAO expansion board using the wiring schematic that was provided.

With the help of a 10K resistor, the gate of the AO3400 N channel Mosfet in the Mosfet Switch Section is connected to the D2 of the XIAO SAMD21 MCU.

The XIAO Expansion Board's 3V is linked to the LED load's positive terminal, while the mosfet's drain is connected to the LED load's negative terminal.

The source of the mosfet is connected to the GND of the expansion board.

One question: why are we using this particular mosfet switch setup? Why not directly connect the GPIO pins to the LED load? Why would it not operate with these SMD LEDs if it works with 5mm ones?

This is because, while the I/O pins of a microcontroller can drive an individual 20–30 mA LED, the high-power LEDs we are using can draw current of at least 200–500 mA each, and because they are connected in parallel, they can draw up to 2 A of current, which is not possible with regular I/O pins.

Using a Mosfet or even a transistor to connect the load directly through a power line—in this case, 3V—is one way to solve this problem. A Mosfet is similar to a switch in that it connects to the I/O pin of the microcontroller and, when voltage is supplied to the gate, allows current to flow from the drain to the source. Controlling the load is simple when one sends a PWM signal to the mosfet's gate.

We are using a spare Etch LED board that I had lying around for the LED load.

It has eight 2835 LEDs connected in parallel. The current that flows through each pair of LEDs is limited by a 5.6 ohm resistor.

DESIGN

The design of the flashlight was prepared next, which included the model of the XIAO expansion board and battery, which we arranged in such a way that the expansion board was placed on the right face of the model and the battery was placed inside.

The model is composed of two parts: the main body, which houses the expansion board and battery, and the PCB holder, which is mounted to the front of the main body and on which the LED PCB is installed.

The rocker switch was positioned on the uppermost face of the model, which was designed so that the user could hold the body comfortably and press the switch without having to move their thumb too much.

Following the completion of the body, we exported the mesh files and used a 0.4mm nozzle with a 0.2mm layer height to print the main body in purple PLA and the LED holder in transparent PLA.

BPDY.stl

Standard Tesselated Geometry - 1.50 MB - 08/26/2024 at 19:41

Download

SMART FLASH LIGHT v3.f3d

fusion - 1019.46 kB - 08/26/2024 at 19:41

Download

Inner PCB Support.stl

Standard Tesselated Geometry - 103.01 kB - 08/26/2024 at 19:41

Download

  • 1
    TEST SKETCH 01

    We added a basic blink sketch to the XIAO SAMD21 MCU in order to test this configuration. By passing the sketch via the microcontroller, LED Load turns ON and OFF, indicating that we are ready to continue on to the next stage, which is to add the main sketch to the board.

    void setup() {
    // initialize digital pin LED_BUILTIN as an output.
    pinMode(2, OUTPUT);
    }
    // the loop function runs over and over again forever
    void loop() {
    digitalWrite(2, HIGH);  // turn the LED on (HIGH is the voltage level)
    delay(1000);                      // wait for a second
    digitalWrite(2, LOW);   // turn the LED off by making the voltage LOW
    delay(1000);                      // wait for a second
    }
  • 2
    TEST SKETCH 02

    The main sketch was then uploaded into the XIAO SAMD21 configuration.

    By pushing the switch, this code enables the user to toggle between various light brightness levels. An OLED screen, rotated to be viewed in portrait orientation, shows the brightness level currently in use.

    #include <Wire.h>
    #include <Adafruit_SSD1306.h>
    #include <Adafruit_GFX.h>
    #define OLED_WIDTH 128
    #define OLED_HEIGHT 64
    #define OLED_ADDR   0x3C
    const int switchPin = 1;
    const int lightPin = 2;
    int lightMode = 1;
    Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
    void setup()
    {
    pinMode(lightPin, OUTPUT);
    pinMode(switchPin, INPUT_PULLUP);
    digitalWrite(lightPin, LOW);
    display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
    display.clearDisplay();
    }
    void loop()
    {
    if (digitalRead(switchPin) ==LOW)
    {
    lightMode = lightMode + 1;
    if (lightMode == 6)
    {
    lightMode = 1;
    }
    }
    if (lightMode == 1)
    {
    digitalWrite(lightPin, LOW);
    display.clearDisplay();
    display.setRotation(3);
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(5, 55);
    display.println("OFF");
    display.display();
    delay(500);
    }
    else if (lightMode == 2)
    {
    analogWrite(lightPin, 50);
    display.clearDisplay();
    display.setRotation(3);
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(5, 55);
    display.println("20%");
    display.display();
    delay(500);
    }
    else if (lightMode == 3)
    {
    analogWrite(lightPin, 100);
    display.clearDisplay();
    display.setRotation(3);
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(5, 55);
    display.println("40%");
    display.display();
    delay(500);
    }
    else if (lightMode == 4)
    {
    analogWrite(lightPin, 255);
    display.clearDisplay();
    display.setRotation(3);
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(5, 55);
    display.println("100%");
    display.display();
    delay(500);
    }
    else if (lightMode == 5)
    {
    analogWrite(lightPin, LOW);
    display.clearDisplay();
    display.setRotation(3);
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(5, 55);
    display.println("OFF");
    display.display();
    delay(500);
    }
    //delay(200); // see text
    }

    After making sure that the main sketch was working, we started the assembly process.

  • 3
    ASSEMBLY PROCESS
    • Using a soldering iron, remove all of the parts from the XIAO expansion board, including the battery, switch, and LED load, to start the assembly process.
    • Next, using a window provided on the expansion board mounting location, we select and position the expansion board on the main body before running all the cables inside.
    • To permanently fasten the expansion board in its position, we utilize four M2 screws.
    • The lithium cell was then installed in the main body.
    • Next, we linked the expansion board to the positive and negative wires of the lithium cell.
    • We turn the ON/OFF switch on the expansion board to confirm that the battery is connected to the board. When we do this, the XIAO SAMD21's status LED illuminates, indicating that the board is receiving power.

View all 5 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates