Introduction: Arduino-based Gyroscope-controlled Glass Desk Light

Picture of Arduino-based Gyroscope-controlled Glass Desk Light

What?

A glass desk light with LEDs controlled by an Arduino-based microcontroller, and a gyroscope sensor.

Bill of materials:

- an Arduino-based controller. This time I used a genuine Arduino MKR1000 kindly provided by Instructables and Digikey as a runner-up prize for the Arduino Contest 2016 :) I got mine for free, but this is roughly 35$.

- a gyroscope module. I used this one. Roughly 2$.

- LEDs. As many as your base lamp needs. Mine needed 30, and I had a spare meter of ws2813 (60 leds/m) LEDs. You can go with the cheaper ws2812b for a full meter and spend around 6$. Keep the ones you don't use safe, you'll need them at some point :)

- a base lamp. Any would do, I have used an hand made Italian glass lamp with a nice, frosted, diffusing glass. It's meant to be used as a glass lamp, but you can definitely adapt it to be a desk one too. I don't have a link for this, as the shop was a small local one. This costed around 50$ (40 euros) in Italy.

- some spare jumper cables.

- a mini breadboard like this, around 0.5$

- some spare "blue tack" or "white tack" or whatever other adhesive you find around.

- a power source. Thanks to the Arduino MKR1000, this can be either a USB power source (like a battery pack as showed in the video), or a power adaptor using the VIN pin (as showed in the picture), or even a 3.7v batter connected to the JST battery plug of the MKR1000 (I didn't have this option, so no pictures, sorry). Cost depends on solution but ranges from 5$ do 10$.

Note:

The "flashes" you see in the videos are due to loose breadboard connections. While I'm waiting for a new breadboard, you can avoid this by just making the connections without the breadboard. This boils down to finding a way to connect 3 power and 3 ground pins altogether. You could use a spare barrel jack adapter to achieve this, or solder all of them together.

I'll be posting a new video when I solve the problem.






Step 1: Prepare the LEDs and the Lamp

Picture of Prepare the LEDs and the Lamp

Remove all the unnecessary content from the lamp. In my case this was: lamp holder, electric junction, some cables.

These LED strips come with a bi-adhesive tape on the back. Just cut the strip to match the 4 sides of the base of the lamp. Make sure you follow the little black arrows indicating the direction of the data bus. +5v and GND don't have a direction.

Once you have placed the LEDs on the 4 sides, you have to connect them.

First, make yourself a connector from the start of the first side (choose one side with easy access to the breadboard). Then you have to solder each end of a side with the beginning of the next side, except the last piece. Solder +5v with +5v, GND with GND, and DO with DI (Data Out with Data In).

Step 2: Add the Electronics

Picture of Add the Electronics

Take the Arduino or whatever microcontroller you are using and place it on to the base of the lamp. Place the gyroscope on the breaboard.

Make the following connections between the gyro and the Arduino:

Gyro -- Arduino MKR1000

VCC -- 5v (use the breadboard so you can connect also the +5v of the LED strip)

GND -- GND (use the breadboard so you can connect also the GND of the LED strip)

SCL -- SCL

SDA -- SDA

INT -- Pin 2

Refer to the schematics of your microcontroller to modify accordingly. For examples, the Arduino UNO has the SCL on pin 12, if I'm not mistaken.

Make the following connections between the LED strip and the Arduino:

LED -- Arduino MKR1000

+5v -- 5v (use the breaboard)

GND -- GND (use the breadboard)

DI (of the first segment) -- Pin 6

Step 3: Check Your Connections - Add Power

Picture of Check Your Connections - Add Power

Check your connections, you should end up with something similar to the picture.

In my prototype, I used a battery pack to power the project from USB, but you could use a power supply like the one in the picture, with a barrel jack adapter, connecting GND to GND (using the breadboard), and +5v to VIN of the Arduino MKR1000 (5v on the Arduino UNO).

Step 4: Programming the Microcontroller

The gyroscope is a pretty interesting sensor, that can sense 3 axes acceleration and 3 axes angle. Too bad it's easy to get the raw values, it isn't easy to convert them into angles.

Our goal is to implement the following logic:

- x axis: should control the brightness. Angles from -5 to +5 shouldn't do anything, then brightness should increase with angles > +5 and decrease with < -5. Moreover, the angle should affect the speed of the decrease/increase.

- y axis: should control the color. Angles from -5 to +5 shouldn't do anything, then the color should
increase (using Adafruit NeoPixel's "wheel" function in their library example strandtest) with angles > +5 and decrease with < -5. Moreover, the angle should affect the speed of the decrease/increase.

Thankfully, somebody already wrote a base sketch to convert the raw data into angles.

Download the attached zipped libraries and unzip them into your Arduino sketch/libraries folder.

Download the attached .ino sketch and upload it to your microcontroller.

As you can see from the changeColor function, one color has been added to the 256 colors of the Wheel function: 255,127,40. That is, if you increase the color using the y axis to more than 255, you'll get that warm white color (you can see this in the video).

Step 5: Enjoy the Lamp!

That's all folks!

Next steps for me:

1) adding the power supply source with a quick-plug connector

2) adding a battery, so that when the plug is plugged, it takes power from the mains power supply while charging the battery. If it's unplugged, it survives thanks to he 3.7v LiPo battery.

Cheers!

Comments

MESHprj (author)2017-03-16

Great project!

About This Instructable

3,215views

35favorites

Bio: The opinions in my posts are personal and not necessarily shared by the company I work for. Sometimes I don't agree with myself either ... More »
More by berlingozzo:Arduino-based Gyroscope-controlled Glass Desk Light"Paper Heart": a Paper-only Stellated Icosidodecahedron"Heart of Glass": Arduino-based remote bluetooth Heart Rate (HR) display
Add instructable to: