Toggle Nav

DIY Smart Necklace for Christmas Gift by Arduino & OLED Display

Author

Table of Contents

Overview

It’s Christmas time and if you’re planning to give a decent gift to your family or relatives, It’s better to use your own knowledge or expertise and make them happy with your own hand-made gift. As you know, Arduino provides a variety of options to make different gadgets or cool stuff with simple components like small displays and sensors. Our idea is making a necklace by using Arduino pro mini and OLED display and to display an animation on it.

What You Will Learn

  • how to display animations on OLED displays by Arduino.
  • how to make Arduino boards smaller
  • Will Make a cool gift for Christmas.

Required Materials

Hardware Components

Arduino Pro Mini × 1
0.96" SPI 128X64 OLED Display Module × 1
Mercury Tilt Sensor Switch × 1
Battery 80mAh 3.7 V lipo Polymer × 1

Software Apps

Arduino IDE

Circuit

Code

You must add the OLED display library and then upload the code. Go to Manage Libaray and search for Adafruit SSD1306 and download it. If it is the first time you are using an Arduino board, don’t worry, just follow these steps:

  1. Go to www.arduino.cc/en/Main/Software and download the Arduino software compatible your OS. Install the IDE software as instructed.
  2. Run the Arduino IDE and clear the text editor and copy the following code in the text editor.
  3. Choose the board in tools and boards, select your Arduino Board.
  4. Connect the Arduino to your PC and set the COM port in tools and port.
  5. Press the Upload (Arrow sign) button.
  6.  You are all set!
#include "SPI.h"
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for SSD1306 display connected using software SPI (default case):
#define OLED_MOSI 2
#define OLED_CLK 3
#define OLED_DC 4
#define OLED_CS 5
#define OLED_RESET 6
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

/* Comment out above, uncomment this block to use hardware SPI
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
&SPI, OLED_DC, OLED_RESET, OLED_CS);
*/

#define NUMFLAKES 15 // Number of snowflakes in the animation example

#define LOGO_HEIGHT 4
#define LOGO_WIDTH 4

static const unsigned char PROGMEM logo_tree[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x07, 0x83, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x0f, 0x03, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x1c, 0x03, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x78, 0x03, 0x0c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb7, 0xf0, 0x03, 0x0e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x33, 0xe0, 0x03, 0x0e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x80, 0x03, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3c, 0x33, 0x80, 0x07, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0xf0, 0x31, 0x80, 0x07, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf1, 0xe0, 0x31, 0xc1, 0xc7, 0x03, 0x00, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf3, 0xc0, 0x31, 0xc1, 0xc6, 0x03, 0x00, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0xff, 0x00, 0x30, 0xc0, 0x86, 0x03, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0xde, 0x0c, 0x70, 0xc0, 0x06, 0x03, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x9c, 0x1c, 0x70, 0xe0, 0x06, 0x01, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe1, 0x9c, 0x0c, 0x60, 0xe0, 0x0e, 0x01, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x81, 0x9c, 0x00, 0x60, 0x60, 0x0e, 0x01, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x01, 0x8c, 0x00, 0x60, 0x60, 0x0c, 0x21, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x03, 0x8c, 0x00, 0xe0, 0x60, 0x0c, 0x71, 0xc0, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x08, 0x00, 0x3c, 0x03, 0x0c, 0x00, 0xc0, 0x60, 0x1c, 0x71, 0xff, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x00, 0xf0, 0xc3, 0x0c, 0x00, 0xc0, 0x70, 0x1c, 0x01, 0xff, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x0e, 0x31, 0xe1, 0xc7, 0x0c, 0x01, 0xc0, 0x70, 0x18, 0x01, 0xff, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x0f, 0xe3, 0xc0, 0xc6, 0x0e, 0x01, 0x80, 0x70, 0x18, 0x00, 0xc0, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x1f, 0xe7, 0x00, 0x0e, 0x0e, 0x03, 0x80, 0x70, 0x38, 0x00, 0xc0, 0xc0, 0x00,
0x00, 0x00, 0x00, 0xff, 0xce, 0x00, 0x0c, 0x0e, 0x03, 0x80, 0x70, 0x30, 0x00, 0xc0, 0xc0, 0x00,
0x00, 0x00, 0x00, 0xff, 0xce, 0x00, 0x1c, 0x0e, 0x03, 0x0c, 0x70, 0x30, 0x00, 0xc0, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x1f, 0xe7, 0x00, 0x38, 0x0e, 0x07, 0x0e, 0x70, 0x70, 0x00, 0xff, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x0f, 0xe3, 0xc0, 0x70, 0x0e, 0x06, 0x0c, 0x70, 0x60, 0x00, 0xff, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x0e, 0x71, 0xe0, 0xf0, 0x0e, 0x0e, 0x00, 0x70, 0xe0, 0x01, 0xff, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x00, 0xf1, 0xe0, 0x0c, 0x1c, 0x00, 0x70, 0xe0, 0x01, 0xc0, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x08, 0x00, 0x7b, 0xc3, 0x8c, 0x18, 0x00, 0x61, 0xc0, 0x01, 0xc0, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x03, 0x8c, 0x38, 0x00, 0x61, 0xc2, 0x01, 0xc0, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x03, 0x8c, 0x70, 0x00, 0x61, 0x87, 0x01, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x1c, 0xe0, 0x00, 0x63, 0x87, 0x01, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x19, 0xc0, 0x00, 0xe7, 0x02, 0x01, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0xc0, 0x00, 0xe7, 0x00, 0x01, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1f, 0x81, 0xc0, 0xce, 0x00, 0x03, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3f, 0x01, 0xc0, 0xcc, 0x00, 0x03, 0x80, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x33, 0xc0, 0x81, 0xdc, 0x00, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xb1, 0xe0, 0x01, 0xb8, 0x00, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0xf0, 0x01, 0xf0, 0x00, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x78, 0x03, 0xf0, 0x00, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x03, 0xe0, 0x00, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x03, 0xe0, 0xe0, 0x0e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x87, 0xf0, 0xe0, 0x0e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe6, 0x78, 0x40, 0x0c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x3c, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x0f, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x07, 0x80, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static const unsigned char PROGMEM logo_bmp[] =
{ 0x60,
0xf0,
0xf0,
0x60
};

bool merc;

void setup() {
Serial.begin(9600);

// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}

// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds

merc=digitalRead(7);
testdrawbitmap(); // Draw a small bitmap image
testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps
}

void loop() {
}

void testdrawbitmap(void) {
display.clearDisplay();
if (merc==true){
display.drawBitmap(0,0,logo_tree, 128, 64, 1);
display.display();
delay(1000);}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define XPOS 0 // Indexes into the 'icons' array in function below
#define YPOS 1
#define DELTAY 2

void testanimate(const uint8_t *bitmap, uint8_t w, uint8_t h) {
int8_t f, icons[NUMFLAKES][3];

// Initialize 'snowflake' positions
for(f=0; f< NUMFLAKES; f++) {
icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width());
icons[f][YPOS] = -LOGO_HEIGHT;
icons[f][DELTAY] = random(1, 6);
Serial.print(F("x: "));
Serial.print(icons[f][XPOS], DEC);
Serial.print(F(" y: "));
Serial.print(icons[f][YPOS], DEC);
Serial.print(F(" dy: "));
Serial.println(icons[f][DELTAY], DEC);
}

for(int i=0;i<10;i++) {
display.clearDisplay(); // Clear the display buffer
display.drawBitmap(0,0,logo_tree, 128, 64, 1);
display.display();
// Draw each snowflake:
for(f=0; f< NUMFLAKES; f++) {
display.drawBitmap( icons[f][YPOS],icons[f][XPOS], bitmap, 4, 4, WHITE);
}

display.display(); // Show the display buffer on the screen
delay(50); // Pause for 1/10 second

// Then update coordinates of each flake...
for(f=0; f< NUMFLAKES; f++) { icons[f][YPOS] += icons[f][DELTAY]; // If snowflake is off the bottom of the screen... if (icons[f][XPOS] >= display.height()) {
// Reinitialize to a random position, just off the top
icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width());
icons[f][YPOS] = -LOGO_HEIGHT;
icons[f][DELTAY] = random(1, 6);
}
}
}
}

Assembling

The first step in making the smart necklace is to cut the Arduino board out as much as possible to fit it inside the necklace frame. It’s very important to avoid cutting the main tracks in the board and just cut the unused pins tracks.

Next, Connect the display to Arduino according to the circuit image. Now connect Mercury switch to pin 7 and add an ON/OFF switch between the battery and the Arduino.

Cover the circuit by a Plexi-glass (Acrylic sheet) frame, add a chain to the top of the frame and enjoy! You can build the frame with any other material you wish.

What’s Next?

Here are a few suggestions:

  • Try to make other animation and display them.
  • Try to make the circuit sensitive to other parameters like temperature.

Liked What you see?

Get updates and learn from the best

More To Explore

Comment (1)

  • Abel Reply

    I have a question, how you recharge the battery??

    July 22, 2020 at 10:00 pm

Leave a Reply

Your email address will not be published. Required fields are marked *