How to build a glowing dog collar with Adafruit Flora  

How to build a glowing dog collar with Adafruit Flora

You can build a glowing collar for your best friend with the help of Adafruit Flora and colour-changing neopixels. Whether you’re looking for extra cool points at the park or you’d like the added safety in the dark, here’s how to get started:

The project

Suitable for: beginners

Time required: 2 hours

Budget: £80-100

The tech you need:

  • Adafruit Flora
  • Adafruit Flora RGB neopixel LEDs
  • 150 mAh LiPoly battery or 3xAAA block battery
  • conductive thread
  • Adafruit Flora accelerometer

You will also need:

  • dog collar
  • needle
  • thread

How to connect Adafruit Flora to an accelerometer and neopixel

Before construction starts it’s important to understand how the components will connect to the Adafruit Flora. In this project, we’ll connect our components using conductive threads. This way we ensure that the transmission of the signals or the current transmission work. Alternatively, it is possible to use stranded wires, which connect the components via solder points. Here’s a guide to help you (the letters stand for the connection points of the individual components and the mainboard):

Accelerometer:
GND → GND
SCL → SCL
SDA → SDA
3.3V → 3.3V

Series connection of NeoPixels:
Vcc (Power) → FLORA VBATT
IN (Data Input) → FLORA D6
Gnd (Ground) → GND

Placement of neopixels and Adafruit Flora

Caution: Always make sure you are working on a non-conductive surface. It’s important to check your work for short circuits before connecting the Adafruit Flora to the battery or computer.

First, choose where you’d like to place the neopixels, Adafruit Flora and accelerometer on the collar. When you are happy with the neopixels’ placement, sew on the mainboard and accelerometer making sure they are close together. Use the opposite connections GND and 3.3V for the Adafruit Flora. Then connect the Flora and the accelerometer with a conductive thread.

Connect neopixels to Adafruit Flora

The next step is to connect the neopixels to the mainboard. Start from the D6 connector of the mainboard wheel. Lead the conductive thread to the connector with the inward arrow of the first neopixel. From the opposite connector with the arrow pointing outwards, guide the conductive thread to the next neopixel. Repeat until you have reached all neopixels.

Now take two more conductive threads and sew the ground line and the power connection between the mainboard and the neopixels.

Make the neopixels glow

Now the mainboard is connected to the computer with a USB cable. Open the Adafruit Arduino IDE, which contains the NeoPixel library and follow these steps:

  1. To test the neopixels, upload the sketch here: File→Examples→Adafruit_NeoPixel→strandtest. When all the pixels light up and the colours change, you’re good to go.
  2. To test the accelerometer, download the Adafruit Sensor Library and the Unified LSM303DLHC Library. Then upload the sketch here: File→Examples→Adafruit_LSM303→Test. Open the Serial Monitor and look for changing motion values.
  3. Now copy the code below (from the official Adafruit homepage) and paste it into the Adafruit Arduino DIE and upload. (You can adjust the colours in the myFavoriteColors array and the movement sensitivity under MOVE_THRESHOLD)

#include <Wire.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_LSM303_U.h>

#include <Adafruit_NeoPixel.h>

 

// Parameter 1 = number of pixels in strip

// Parameter 2 = pin number (most are valid)

// Parameter 3 = pixel type flags, add together as needed:

//   NEO_RGB     Pixels are wired for RGB bitstream

//   NEO_GRB     Pixels are wired for GRB bitstream

//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)

//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, 6, NEO_GRB + NEO_KHZ800);

Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);

 

// Input your favorite colors here, these will appear on the collar!

// just add new {nnn, nnn, nnn}, lines. They will be picked out randomly

//                                  R G B

uint8_t myFavoriteColors[][3] = {{200,   0, 200}, // purple

                                {200, 0, 0}, // red

                                {200, 200, 200}, // white

                              };

// don’t edit the line below

#define FAVCOLORS sizeof(myFavoriteColors) / 3

 

// mess with this number to adjust TWINklitude 🙂

// lower number = more sensitive

#define MOVE_THRESHOLD 45

 

void setup()

{

 Serial.begin(9600);

 

 // Try to initialise and warn if we couldn’t detect the chip

 if (!accel.begin())

 {

   Serial.println(“Oops … unable to initialize the LSM303. Check your wiring!”);

   while (1);

 }

 strip.begin();

 strip.show(); // Initialize all pixels to ‘off’

}

 

void loop()

{

 /* Get a new sensor event */

 sensors_event_t event;

 accel.getEvent(&event);

 Serial.print(“Accel X: “); Serial.print(event.acceleration.x); Serial.print(” “);

 Serial.print(“Y: “); Serial.print(event.acceleration.y);       Serial.print(” “);

 Serial.print(“Z: “); Serial.print(event.acceleration.z);     Serial.print(” “);

 

 // Get the magnitude (length) of the 3 axis vector

 // http://en.wikipedia.org/wiki/Euclidean_vector#Length

 double storedVector = event.acceleration.x*event.acceleration.x;

 storedVector += event.acceleration.y*event.acceleration.y;

 storedVector += event.acceleration.z*event.acceleration.z;

 storedVector = sqrt(storedVector);

 Serial.print(“Len: “); Serial.println(storedVector);

 

 // wait a bit

 delay(100);

 

 // get new data!

 accel.getEvent(&event);

 double newVector = event.acceleration.x*event.acceleration.x;

 newVector += event.acceleration.y*event.acceleration.y;

 newVector += event.acceleration.z*event.acceleration.z;

 newVector = sqrt(newVector);

 Serial.print(“New Len: “); Serial.println(newVector);

 

 // are we moving

 if (abs(newVector – storedVector) > MOVE_THRESHOLD) {

   Serial.println(“Twinkle!”);

   flashRandom(5, 1);  // first number is ‘wait’ delay, shorter num == shorter twinkle

   flashRandom(5, 3);  // second number is how many neopixels to simultaneously light up

   flashRandom(5, 2);

 }

}

 

void flashRandom(int wait, uint8_t howmany) {

 

 for(uint16_t i=0; i<howmany; i++) {

   // pick a random favorite color!

   int c = random(FAVCOLORS);

   int red = myFavoriteColors[c][0];

   int green = myFavoriteColors[c][1];

   int blue = myFavoriteColors[c][2];

 

   // get a random pixel from the list

   int j = random(strip.numPixels());

   //Serial.print(“Lighting up “); Serial.println(j);

   

   // now we will ‘fade’ it in 5 steps

   for (int x=0; x < 5; x++) {

     int r = red * (x+1); r /= 5;

     int g = green * (x+1); g /= 5;

     int b = blue * (x+1); b /= 5;

     

     strip.setPixelColor(j, strip.Color(r, g, b));

     strip.show();

     delay(wait);

   }

   // & fade out in 5 steps

   for (int x=5; x >= 0; x–) {

     int r = red * x; r /= 5;

     int g = green * x; g /= 5;

     int b = blue * x; b /= 5;

     

     strip.setPixelColor(j, strip.Color(r, g, b));

     strip.show();

     delay(wait);

   }

 }

 // LEDs will be off when done (they are faded to 0)

}


You can tweak this code again and again until you find the perfect setup for you and your pup!

Now for the battery

After configuration, you need to install the battery. Securely fasten a small battery or cloth bag to your dog collar. Make sure that the battery is close to the Adafruit Flora motherboard so that the connection is short and stable. When the battery case is fixed, you can connect the battery and the mainboard.

Glow in the bark!

When you are happy with the light frequency and colour design then there’s just one thing left to do… get outside and show everyone who has the coolest dog gadget!



 

Your opinion counts. What do you think about this topic?

Previous voting results loading.
 

Leave a Reply

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