LED Hammer Using ATttiny85

by wale4d in Circuits > Electronics

506 Views, 6 Favorites, 0 Comments

LED Hammer Using ATttiny85

WhatsApp Image 2023-10-03 at 6.09.22 PM.jpeg

Welcome to this exciting Instructables project, where I'll guide you through the creation of a unique and eye-catching diy 3D printed LED hammer. This project combines the precision of 3D printing technology with the versatility of electronics, featuring components like the ATtiny85 micro-controller, batteries, Neo-Pixels, a push button, and a slider switch to bring your creation to life. Whether you're a seasoned maker or a curious beginner, this project offers a fantastic opportunity to dive into the world of 3D printing, electronics, and creative design. Get ready to build a functional and visually stunning LED hammer that not only looks great but also showcases your skills in crafting and coding. Let's get started!

Supplies

WhatsApp Image 2023-10-03 at 6.08.37 PM.jpeg
WhatsApp Image 2023-10-03 at 6.08.38 PM.jpeg
WhatsApp Image 2023-10-03 at 6.08.42 PM(1).jpeg
WhatsApp Image 2023-10-03 at 6.08.42 PM.jpeg
WhatsApp Image 2023-10-03 at 6.08.43 PM.jpeg
WhatsApp Image 2023-10-03 at 6.08.44 PM.jpeg
WhatsApp Image 2023-10-03 at 6.09.06 PM.jpeg
  • Neopixel LED's x4
  • Attiny85
  • Rechargeable batteries
  • Push button
  • Slider switch (SPDT)
  • Battery connector
  • USB micro female connector
  • Soldering iron
  • Hot glue Gun
  • 3D printer
  • Wires

Programming Attiny85

Amazing Leelo.png

To program an attiny85 I used Arduino UNO and make the following connections.

(*You can use any Arduino boards for uploading the code to attiny85. It uses SPI(Serial Peripheral Interface) communication protocol to bootload and upload the code

  • Arduino UNO pin 10 ------------ Attiny pin 1
  • Arduino UNO pin 11 ------------ Attiny pin 5
  • Arduino UNO pin 12 ------------ Attiny pin 6
  • Arduino UNO pin 13 ------------ Attiny pin 7
  • Arduino UNO 5V ---------------- Attiny pin 4
  • Arduino UNO GND ------------- Attiny pin 8

(*Note: You have to burn bootloader to the attiny85 first in order to upload the code. You can find more information on Youtube on how to bootload and upload code to attiny85)

Building & Testing the Circuit

Capture.JPG
Amazing Leelo.png

The first step is to upload the code to the attiny85 with the help of Arduino IDE and with the help of the provided schematic, patch the circuit on the bread board to verify the circuit and the code.

Power the circuit with the 3 to 5 volts battery and turn the slider switch. The neopixels will blink for 0.5 seconds and will turn OFF. Press the push button continuously to change the color of the neopixels. If the neopixels change their colors your circuit and code is working just fine.

(I'm using 40mAh Li-po rechargeable batteries which can be charged with a stable 4.2 volts power source)

3D Printing the LED Hammer

WhatsApp Image 2023-10-03 at 6.08.41 PM.jpeg

You can choose any kind of filament material for 3D printing these hammers. The filament that I choose is

  • PLA (white)
  • Transparent PETG

(*For printing with Transparent PETG make sure to change the settings for transparency of the model. Also print in vertical direction when printing with PETG for best results)

Assembling

WhatsApp Image 2023-10-03 at 6.09.11 PM.jpeg
WhatsApp Image 2023-10-03 at 6.08.46 PM.jpeg
Micro usb.png
WhatsApp Image 2023-09-15 at 9.22.39 AM.jpeg

Follow these steps for soldering the components inside the hammer

  1. Connect the wires with the Micro USB female connector, slider switch, push button,neopixels, batteries and the pin number 4, 6, 7 and 8 of the attiny85.
  2. Place the micro USB female connector into the hammer and add some hot glue to avoid any movement of the connector.
  3. Add some hot glue to the slider switch and place it inside the hammer and apply some pressure so that it wont move.
  4. Do the same 3rd step with the push button.
  5. Remove the back protective sheet of the LED strip and apply some hot glue and place it onto the inner surface of the hammer.
  6. Make the connections of the positive and ground first. Pin 4 of the attiny85 is the ground and the pin 8 is the voltage pin.
  7. Connect the data pin (DIN) of the neopixels with the pin 6 of the attiny85 and the pin 7 of the attiny85 with the pin of the push button
  8. Use small piece of wire for making connections and use heat shrink tubes or add some glue gun to avoid short circuits and for making strong connections.
  9. Use the connectors shown in the image for connecting the battery to the circuit.
  10. When everything is connected use the screw of head diameter 2.5mm to join the two parts together.

Final Product

WhatsApp Image 2023-10-03 at 6.08.39 PM.jpeg
WhatsApp Image 2023-10-03 at 6.08.44 PM(1).jpeg
F15W4DHLNABY0NE.jpg

Code

#include <Adafruit_NeoPixel.h>

#define PIN          1 //pin for push button
#define NUMPIXELS    4 //no of LED's

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

const int buttonPin = 2; //pin for button
int buttonState = 0;    
int lastButtonState = 0;
int pressCount = 0;      
bool rainbowMode = false;

void setup()
{
 strip.begin();
 strip.show();

 pinMode(buttonPin, INPUT_PULLUP); // Use internal pull-up resistor
}

void loop()
{
 buttonState = digitalRead(buttonPin);

 // Check if the button has been pressed and released
 if (buttonState != lastButtonState)
 {
   if (buttonState == LOW) {
     // Button has been pressed, increment pressCount
     pressCount++;

     // Handle different cases
     switch (pressCount)
     {
       case 1:
         setLEDsRed();
         break;
       case 2:
         setLEDsGreen();
         break;
       case 3:
         setLEDsBlue();
         break;
       case 4:
         setLEDsPink();
         break;
       case 5:
         setLEDsYellow();
         break;
       case 6:
         setLEDsCyan();
         break;
       case 7:
         if (rainbowMode)
         {
           stopRainbowEffect();
           pressCount = 0;
         }
         else
         {
           startRainbowEffect();
         }
         break;
       default:
         pressCount = 1;
         setLEDsRed();
         break;
     }
   }
   delay(50); // Debounce delay to prevent multiple toggles with one press
 }

 lastButtonState = buttonState;

 // If rainbowMode is enabled, update the rainbow effect
 if (rainbowMode) {
   rainbowCycle(20);
 }
}

/*----------------------------------------------------------------*/
void setLEDsRed()
{
 for (int i = 0; i < NUMPIXELS; i++)
 {
   strip.setPixelColor(i, strip.Color(255, 0, 0)); // Red color
 }
 strip.show();
}
/*----------------------------------------------------------------*/
void setLEDsGreen()
{
 for (int i = 0; i < NUMPIXELS; i++)
 {
   strip.setPixelColor(i, strip.Color(0, 255, 0)); // Green color
 }
 strip.show();
}
/*----------------------------------------------------------------*/
void setLEDsBlue()
{
 for (int i = 0; i < NUMPIXELS; i++)
 {
   strip.setPixelColor(i, strip.Color(0, 0, 255)); // Blue color
 }
 strip.show();
}
/*----------------------------------------------------------------*/
void setLEDsYellow()
{
 for (int i = 0; i < NUMPIXELS; i++)
 {
   strip.setPixelColor(i, strip.Color(255, 255, 0)); // Blue color
 }
 strip.show();
}
/*----------------------------------------------------------------*/
void setLEDsPink()
{
 for (int i = 0; i < NUMPIXELS; i++)
 {
   strip.setPixelColor(i, strip.Color(255, 0, 127)); // Blue color
 }
 strip.show();
}
/*----------------------------------------------------------------*/
void setLEDsCyan()
{
 for (int i = 0; i < NUMPIXELS; i++)
 {
   strip.setPixelColor(i, strip.Color(0, 255, 255)); // Blue color
 }
 strip.show();
}
/*----------------------------------------------------------------*/
void startRainbowEffect()
{
 // Start the rainbow effect by enabling the flag
 rainbowMode = true;
}

void stopRainbowEffect()
{
 // Stop the rainbow effect by disabling the flag and turning off all LEDs
 rainbowMode = false;
 for (int i = 0; i < NUMPIXELS; i++)
 {
   strip.setPixelColor(i, strip.Color(0, 0, 0)); // Turn off all LEDs
 }
 strip.show();
}

void rainbowCycle(uint8_t wait)
{
 // Rainbow cycling algorithm
 uint16_t i, j;
 for (j = 0; j < 256; j++)
 {
   for (i = 0; i < strip.numPixels(); i++)
   {
     strip.setPixelColor(i, Wheel((i + j) & 255));
   }
   strip.show();
   delay(wait);
 }
}

uint32_t Wheel(byte WheelPos)
{
 // Generate rainbow colors across 0-255 positions
 if (WheelPos < 85)
 {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
 }
 else if (WheelPos < 170)
 {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
 }
 else
 {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
 }
}