Floppy Lab
Published © CERN-OHL2

DIY 10W portable spotlight

I built a cheap and easy to make spotlight. It is made from 3D printed parts, nuts, bolts and some cheap electronic components.

BeginnerFull instructions provided632
DIY 10W portable spotlight

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Custom parts and enclosures

camera_holder

portable_spotlight

Schematics

main circuit

control board schematic

Code

Spotlight firmware

Arduino
#include <OneButton.h>

#define POTENZIOMETRO PA4
#define PWM_LED PA6
#define PULSANTE PB7
#define LED_ONBOARD PC15

OneButton pulsante(PULSANTE, true);

int adcprev = 0;
int adc = 0;


void setup() {
  pinMode(POTENZIOMETRO, INPUT);
  pinMode(PWM_LED, OUTPUT);
  pinMode(LED_ONBOARD, OUTPUT);
  //Serial.begin(9600);
  pulsante.attachClick(cambiaStato);

  analogReadResolution(8);          //I set the ADC resolution to 8 bit
  adc = analogRead(POTENZIOMETRO);  //I read the value of the potentiometer
  adc = map(adc, 0, 240, 5, 255);   //I correct the maximum value read by the ADC [change the second number]
  adcprev = adc;
}

bool on = false;


void loop() {
  pulsante.tick();  //check if the button has been pressed

  adc = analogRead(POTENZIOMETRO);  //I read the value of the potentiometer
  adc = map(adc, 0, 240, 5, 255);   //I correct the maximum value read by the ADC [change the second number]
  adc = (0.1 * adc) + (0.9 * adcprev);
  adcprev = adc;

  if (on) {
    analogWrite(PWM_LED, adc);  //I set the duty cycle of the PWM signal of the LEDs
    digitalWrite(LED_ONBOARD, HIGH);
  } else {
    analogWrite(PWM_LED, 0);
    digitalWrite(LED_ONBOARD, LOW);
  }
  //Serial.println(adc);
}

void cambiaStato() {
  digitalWrite(LED_ONBOARD, LOW);
  delay(200);
  digitalWrite(LED_ONBOARD, HIGH);
  delay(200);
  digitalWrite(LED_ONBOARD, LOW);
  delay(200);
  on = !on;  //on -> off, off -> on
}

Credits

Floppy Lab

Floppy Lab

6 projects • 12 followers
Hi I'm Filippo, and I’m an electronic engineering student passion for DIY. I enjoy building small IoT systems and some robotics projects.

Comments