Smart FlashLight

by Arnov Sharma in Circuits > LEDs

3393 Views, 25 Favorites, 0 Comments

Smart FlashLight

sddd.jpg
17.gif
16.gif
Smart Flash Light Project! #light #diy #electronics

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.

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.

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.

Supplies

These were the materials used in this build:

  1. XIAO SAMD21 M0
  2. XIAO Expansion Board
  3. Li-ion Cell 3.7V, 2000mAh
  4. 3D-printed parts
  5. LED white 2835 Package
  6. Resistor, 5.6 Ohms, 2512 Package
  7. LED Board
  8. AO3400 N-channel Mosfet SOT23 Package
  9. Resistor 10K 0603
  10. Push Button-Rocker Switch style
  11. Wires
  12. M2 Screws

ELECTRONICS: XIAO SAMD21 With Expansion Board

IMG_20240821_201758.jpg
IMG_20240821_203139.jpg
IMG_20240821_203152.jpg
IMG_20240821_203158.jpg
IMG_20240821_203203.jpg
IMG_20240821_203210.jpg
pinpinpin4 - Copy.jpg

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

01.PNG
02.PNG
03.PNG
04.PNG
05.PNG
06.PNG

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.

TEST SKETCH 01

01.gif

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
}

TEST SKETCH 02

02.gif

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
}

ASSEMBLY PROCESS

03.gif
04.gif
05.gif
06.gif
07.gif
08.gif
  1. 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.
  2. 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.
  3. To permanently fasten the expansion board in its position, we utilize four M2 screws.
  4. The lithium cell was then installed in the main body.
  5. Next, we linked the expansion board to the positive and negative wires of the lithium cell.
  6. 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.

FINAL ASSEMBLY

09.gif
10.gif
11.gif
12.gif
13.gif
14.gif
15.gif
  1. In order to begin the final assembly procedure, we place the LED load on the PCB Holder component and fasten them both together with two M2 screws.
  2. The LED load's negative terminal will then be linked to the mosfet's drain. Next, attach the positive terminal of the LED load to the expansion board's 3V.
  3. Wires are connected to the LED load, and the PCB holder assembly is pushed into the main body. The PCB holder and main body are then fastened together with two M2 screws.
  4. Using a soldering iron, we finally reconnected the rocker switch to D1 and GND. After that, we pushed the rocker switch into place to finish the assembly process.

The flashlight is now ready.

RESULT

17.gif
Smart Flash Light Project! #light #diy #electronics
18.gif

We tested this arrangement outside in the woods to see how well it would perform for lighting up the area. The results are seen in the video.

Compared to conventional focus LED flashlights, the light spread angle of this flashlight, which is a flood light kind, is wider.

I will be using this item on an upcoming camping trip; it was a truly overengineered take on a basic yet essential thing.

Overall, this project was successful, however in order to cut down on wiring and makeshift processes we will soon be working on a Version 2 that will house the Mosfet as a switch configuration and LED array together on single PCB.

Thanks for reaching this far, and special thanks to Seeed Studio Fusion for supporting this project. Check them out for all sorts of PCB manufacturing and assembly services for great quality and less price.

Peace