Lock Using Sonars and LED Strips on Arduino

608

12

3

Published

Introduction: Lock Using Sonars and LED Strips on Arduino

For this project I made a box that opens by using sonars, LED strips and 1 servo motor. The main idea behind this is that you use two sonars that both have a "sweet spot". If you hit both these sweet spots the servo moves and opens the lock. The LED's are used to visualize the sweet spots.

For this project you will need:

  • 1 Neopixel strip that's 1 meter long with 30 LED's in total
  • 2 HC - SR04 Sonars
  • 1 Neopixel LEDring with 12 neopixels
  • 3 220 OHM resistors
  • 1 arduino UNO
  • A breadboard
  • Wires
  • 1 box

Step 1: Connecting Everything

For the LED strips, I cut the one strip in two separate LED strips that are 12 LED's big. Since I couldn't find LED strips in the schematics I used 2 single LED's. Just pretend they're strips. Between the LED's (strips and ring) add a resistor of 220 ohm.

Make sure you get the pins right:

  • trig1 13
  • echo1 12
  • trig2 10
  • echo2 9
  • neopixel strip1 11
  • neopixel strip2 8
  • neopixel ring 7
  • Servo 6

Step 2: The Code

Add this code and upload it to your arduino:

#include
#include

int servoPin = 6;

#define trigPin 13 #define echoPin 12 #define trigPin2 10 #define echoPin2 9 #define neoPin 11 #define neoPin2 8 #define neoPin3 7 #define BRIGHTNESS 50 #define BRIGHTNESS2 30

Servo Servo1; // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, neoPin, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(12, neoPin2, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(12, neoPin3, NEO_GRB + NEO_KHZ800);

void setup() {

Servo1.attach(servoPin);

// set up sonar 01 -------------------------------------------------------------------------------------- Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); strip.setBrightness(BRIGHTNESS); strip.begin(); strip.show();

// set up sonar 02 --------------------------------------------------------------------------------------

Serial.begin (9600); pinMode(trigPin2, OUTPUT); pinMode(echoPin2, INPUT); strip2.setBrightness(BRIGHTNESS); strip2.begin(); strip2.show();

// set up strip 03 --------------------------------------------------------------------------------------

strip3.setBrightness(BRIGHTNESS2); strip3.begin(); strip3.show(); }

void loop() {

Servo1.write(150); // reset servo position

// sonar 01 --------------------------------------------------------------------------------------------- long duration, distance; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1;

// sonar 02 ----------------------------------------------------------------------------------------------

long duration2, distance2; digitalWrite(trigPin2, LOW); delayMicroseconds(2); digitalWrite(trigPin2, HIGH); delayMicroseconds(10); digitalWrite(trigPin2, LOW); duration2 = pulseIn(echoPin2, HIGH); distance2 = (duration2/2) / 29.1;

// LED for strip 01 -------------------------------------------------------------------------------------- if (distance < 5) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 0, 0); } strip.show(); } else if (distance < 7) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 255, 255); if(i>=1) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 9) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 200, 255); if(i>=2) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 11) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 150, 255); if(i>=3) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 13) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 100, 255); if(i>=4) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 15) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 50, 255); if(i>=5) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 17) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 0, 255); if(i>=6) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 19) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 50, 0, 255); if(i>=7) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 21) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 100, 0, 255); if(i>=8) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 23) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 150, 0, 255); if(i>=9) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 25) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 200, 0, 255); if(i>=10) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 27) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 255, 0, 255); if(i>=11) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 29) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 255, 100, 255); } strip.show(); } else if (distance < 31) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 255, 0, 255); if(i>=11) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 33) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 200, 0, 255); if(i>=10) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 35) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 150, 0, 255); if(i>=9) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 37) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 100, 0, 255); if(i>=8) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 39) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 50, 0, 255); if(i>=7) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 41) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 0, 255); if(i>=6) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 43) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 50, 255); if(i>=5) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 45) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 100, 255); if(i>=4) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 47) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 150, 255); if(i>=3) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 49) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 200, 255); if(i>=2) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else if (distance < 51) { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 255, 255); if(i>=1) { strip.setPixelColor(i, 0, 0, 0); } } strip.show(); } else { for (int i=0; i<12; i++) { strip.setPixelColor(i, 0, 0, 0); } strip.show(); } // LED for strip 02 -------------------------------------------------------------------------------------- if (distance2 < 5) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 0, 0); } strip2.show(); } else if (distance2 < 7) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 255, 255); if(i>=1) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 9) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 200, 255); if(i>=2) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 11) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 150, 255); if(i>=3) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 13) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 100, 255); if(i>=4) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 15) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 50, 255); if(i>=5) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 17) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 0, 255); if(i>=6) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 19) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 50, 0, 255); if(i>=7) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 21) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 100, 0, 255); if(i>=8) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 23) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 150, 0, 255); if(i>=9) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 25) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 200, 0, 255); if(i>=10) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 27) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 255, 0, 255); if(i>=11) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 29) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 255, 100, 255); } strip2.show(); } else if (distance2 < 31) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 255, 0, 255); if(i>=11) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 33) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 200, 0, 255); if(i>=10) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 35) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 150, 0, 255); if(i>=9) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 37) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 100, 0, 255); if(i>=8) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 39) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 50, 0, 255); if(i>=7) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 41) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 0, 255); if(i>=6) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 43) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 50, 255); if(i>=5) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 45) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 100, 255); if(i>=4) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 47) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 150, 255); if(i>=3) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 49) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 200, 255); if(i>=2) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else if (distance2 < 51) { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 255, 255); if(i>=1) { strip2.setPixelColor(i, 0, 0, 0); } } strip2.show(); } else { for (int i=0; i<12; i++) { strip2.setPixelColor(i, 0, 0, 0); } strip2.show(); }

// when all LED's are on this animation plays and opens the lock

if (distance >= 27 and distance < 29 and distance2 >= 27 and distance2 < 29) {

//First it shows the user that all LED's where actually on for (int i=0; i<12; i++) { strip.setPixelColor(i, 255, 100, 255); } strip.show(); for (int i=0; i<12; i++) { strip2.setPixelColor(i, 255, 100, 255); } strip2.show(); delay(300);

//After that the animation begins strip2.setPixelColor(0, 0, 255, 0); strip2.setPixelColor(1, 0, 0, 0); strip2.setPixelColor(2, 0, 0, 0); strip2.setPixelColor(3, 0, 0, 0); strip2.setPixelColor(4, 0, 0, 0); strip2.setPixelColor(5, 0, 0, 0); strip2.setPixelColor(6, 0, 0, 0); strip2.setPixelColor(7, 0, 0, 0); strip2.setPixelColor(8, 0, 0, 0); strip2.setPixelColor(9, 0, 0, 0); strip2.setPixelColor(10, 0, 0, 0); strip2.setPixelColor(11, 0, 0, 0); strip2.show(); strip.setPixelColor(0, 0, 255, 0); strip.setPixelColor(1, 0, 0, 0); strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, 0, 0, 0); strip.setPixelColor(4, 0, 0, 0); strip.setPixelColor(5, 0, 0, 0); strip.setPixelColor(6, 0, 0, 0); strip.setPixelColor(7, 0, 0, 0); strip.setPixelColor(8, 0, 0, 0); strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, 0, 0, 0); strip.show(); delay (150); strip2.setPixelColor(0, 100, 200, 0); strip2.setPixelColor(1, 150, 255, 0); strip2.show(); strip.setPixelColor(0, 100, 200, 0); strip.setPixelColor(1, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(0, 50, 150, 0); strip2.setPixelColor(1, 100, 200, 0); strip2.setPixelColor(2, 150, 255, 0); strip2.show(); strip.setPixelColor(0, 50, 150, 0); strip.setPixelColor(1, 100, 200, 0); strip.setPixelColor(2, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(0, 0, 100, 0); strip2.setPixelColor(1, 50, 150, 0); strip2.setPixelColor(2, 100, 200, 0); strip2.setPixelColor(3, 150, 255, 0); strip2.show(); strip.setPixelColor(0, 0, 100, 0); strip.setPixelColor(1, 50, 150, 0); strip.setPixelColor(2, 100, 200, 0); strip.setPixelColor(3, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(0, 0, 50, 0); strip2.setPixelColor(1, 0, 100, 0); strip2.setPixelColor(2, 50, 150, 0); strip2.setPixelColor(3, 100, 200, 0); strip2.setPixelColor(4, 150, 255, 0); strip2.show(); strip.setPixelColor(0, 0, 50, 0); strip.setPixelColor(1, 0, 100, 0); strip.setPixelColor(2, 50, 150, 0); strip.setPixelColor(3, 100, 200, 0); strip.setPixelColor(4, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(0, 0, 0, 0); strip2.setPixelColor(1, 0, 50, 0); strip2.setPixelColor(2, 0, 100, 0); strip2.setPixelColor(3, 50, 150, 0); strip2.setPixelColor(4, 100, 200, 0); strip2.setPixelColor(5, 150, 255, 0); strip2.show(); strip.setPixelColor(0, 0, 0, 0); strip.setPixelColor(1, 0, 50, 0); strip.setPixelColor(2, 0, 100, 0); strip.setPixelColor(3, 50, 150, 0); strip.setPixelColor(4, 100, 200, 0); strip.setPixelColor(5, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(1, 0, 0, 0); strip2.setPixelColor(2, 0, 50, 0); strip2.setPixelColor(3, 0, 100, 0); strip2.setPixelColor(4, 50, 150, 0); strip2.setPixelColor(5, 100, 200, 0); strip2.setPixelColor(6, 150, 255, 0); strip2.show(); strip.setPixelColor(1, 0, 0, 0); strip.setPixelColor(2, 0, 50, 0); strip.setPixelColor(3, 0, 100, 0); strip.setPixelColor(4, 50, 150, 0); strip.setPixelColor(5, 100, 200, 0); strip.setPixelColor(6, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(2, 0, 0, 0); strip2.setPixelColor(3, 0, 50, 0); strip2.setPixelColor(4, 0, 100, 0); strip2.setPixelColor(5, 50, 150, 0); strip2.setPixelColor(6, 100, 200, 0); strip2.setPixelColor(7, 150, 255, 0); strip2.show(); strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, 0, 50, 0); strip.setPixelColor(4, 0, 100, 0); strip.setPixelColor(5, 50, 150, 0); strip.setPixelColor(6, 100, 200, 0); strip.setPixelColor(7, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(3, 0, 0, 0); strip2.setPixelColor(4, 0, 50, 0); strip2.setPixelColor(5, 0, 100, 0); strip2.setPixelColor(6, 50, 150, 0); strip2.setPixelColor(7, 100, 200, 0); strip2.setPixelColor(8, 150, 255, 0); strip2.show(); strip.setPixelColor(3, 0, 0, 0); strip.setPixelColor(4, 0, 50, 0); strip.setPixelColor(5, 0, 100, 0); strip.setPixelColor(6, 50, 150, 0); strip.setPixelColor(7, 100, 200, 0); strip.setPixelColor(8, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(4, 0, 0, 0); strip2.setPixelColor(5, 0, 50, 0); strip2.setPixelColor(6, 0, 100, 0); strip2.setPixelColor(7, 50, 150, 0); strip2.setPixelColor(8, 100, 200, 0); strip2.setPixelColor(9, 150, 255, 0); strip2.show(); strip.setPixelColor(4, 0, 0, 0); strip.setPixelColor(5, 0, 50, 0); strip.setPixelColor(6, 0, 100, 0); strip.setPixelColor(7, 50, 150, 0); strip.setPixelColor(8, 100, 200, 0); strip.setPixelColor(9, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(5, 0, 0, 0); strip2.setPixelColor(6, 0, 50, 0); strip2.setPixelColor(7, 0, 100, 0); strip2.setPixelColor(8, 50, 150, 0); strip2.setPixelColor(9, 100, 200, 0); strip2.setPixelColor(10, 150, 255, 0); strip2.show(); strip.setPixelColor(5, 0, 0, 0); strip.setPixelColor(6, 0, 50, 0); strip.setPixelColor(7, 0, 100, 0); strip.setPixelColor(8, 50, 150, 0); strip.setPixelColor(9, 100, 200, 0); strip.setPixelColor(10, 150, 255, 0); strip.show(); delay (150); strip2.setPixelColor(6, 0, 0, 0); strip2.setPixelColor(7, 0, 50, 0); strip2.setPixelColor(8, 0, 100, 0); strip2.setPixelColor(9, 50, 150, 0); strip2.setPixelColor(10, 100, 200, 0); strip2.setPixelColor(11, 150, 255, 0); strip2.show(); strip.setPixelColor(6, 0, 0, 0); strip.setPixelColor(7, 0, 50, 0); strip.setPixelColor(8, 0, 100, 0); strip.setPixelColor(9, 50, 150, 0); strip.setPixelColor(10, 100, 200, 0); strip.setPixelColor(11, 150, 255, 0); strip.show(); delay (150); strip3.setPixelColor(0, 0, 255, 0); strip3.show(); strip2.setPixelColor(7, 0, 0, 0); strip2.setPixelColor(8, 0, 50, 0); strip2.setPixelColor(9, 0, 100, 0); strip2.setPixelColor(10, 50, 150, 0); strip2.setPixelColor(11, 100, 200, 0); strip2.show(); strip.setPixelColor(7, 0, 0, 0); strip.setPixelColor(8, 0, 50, 0); strip.setPixelColor(9, 0, 100, 0); strip.setPixelColor(10, 50, 150, 0); strip.setPixelColor(11, 100, 200, 0); strip.show(); delay (150); strip3.setPixelColor(1, 0, 255, 0); strip3.show(); strip2.setPixelColor(8, 0, 0, 0); strip2.setPixelColor(9, 0, 50, 0); strip2.setPixelColor(10, 0, 100, 0); strip2.setPixelColor(11, 50, 150, 0); strip2.show(); strip.setPixelColor(8, 0, 0, 0); strip.setPixelColor(9, 0, 50, 0); strip.setPixelColor(10, 0, 100, 0); strip.setPixelColor(11, 50, 150, 0); strip.show(); delay (150); strip3.setPixelColor(2, 0, 255, 0); strip3.show(); strip2.setPixelColor(9, 0, 0, 0); strip2.setPixelColor(10, 0, 50, 0); strip2.setPixelColor(11, 0, 100, 0); strip2.show(); strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, 0, 50, 0); strip.setPixelColor(11, 0, 100, 0); strip.show(); delay (150); strip3.setPixelColor(3, 0, 255, 0); strip3.show(); strip2.setPixelColor(10, 0, 0, 0); strip2.setPixelColor(11, 0, 50, 0); strip2.show(); strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, 0, 50, 0); strip.show(); delay (150); strip3.setPixelColor(4, 0, 255, 0); strip3.show(); strip2.setPixelColor(10, 0, 0, 0); strip2.setPixelColor(11, 0, 0, 0); strip2.show(); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, 0, 0, 0); strip.show(); delay (150); strip3.setPixelColor(5, 0, 255, 0); strip3.show(); delay (150); strip3.setPixelColor(6, 0, 255, 0); strip3.show(); delay (150); strip3.setPixelColor(7, 0, 255, 0); strip3.show(); delay (150); strip3.setPixelColor(8, 0, 255, 0); strip3.show(); delay (150); strip3.setPixelColor(9, 0, 255, 0); strip3.show(); delay (150); strip3.setPixelColor(10, 0, 255, 0); strip3.show(); delay (150); strip3.setPixelColor(11, 0, 255, 0); strip3.show(); Servo1.write(110); // set servo position to open the lock delay (15000); for (int i=0; i<12; i++) { strip3.setPixelColor(i, 0, 0, 0); } strip3.show(); delay (100); for (int i=0; i<12; i++) { strip3.setPixelColor(i, 255, 0, 0); } strip3.show(); delay (100); for (int i=0; i<12; i++) { strip3.setPixelColor(i, 0, 0, 0); } strip3.show(); delay (100); for (int i=0; i<12; i++) { strip3.setPixelColor(i, 255, 0, 0); } strip3.show(); delay (100); for (int i=0; i<12; i++) { strip3.setPixelColor(i, 0, 0, 0); } strip3.show(); delay (100); for (int i=0; i<12; i++) { strip3.setPixelColor(i, 255, 0, 0); } strip3.show(); delay (100); for (int i=0; i<12; i++) { strip3.setPixelColor(i, 0, 0, 0); } strip3.show(); delay (100); for (int i=0; i<12; i++) { strip3.setPixelColor(i, 255, 0, 0); } strip3.show(); delay (100); strip3.setPixelColor(0, 0, 0, 0); strip3.setPixelColor(1, 0, 0, 0); strip3.setPixelColor(2, 0, 0, 0); strip3.setPixelColor(3, 0, 0, 0); strip3.setPixelColor(4, 0, 0, 0); strip3.setPixelColor(5, 0, 0, 0); strip3.setPixelColor(6, 0, 0, 0); strip3.setPixelColor(7, 0, 0, 0); strip3.setPixelColor(8, 0, 0, 0); strip3.setPixelColor(9, 0, 0, 0); strip3.setPixelColor(10, 0, 0, 0); strip3.setPixelColor(11, 0, 0, 0); strip3.show(); } delay (50);

}

Step 3: The Box

I created the box myself, but you can use an existing box if you want. Be sure that the box is big enough for the LED's.

I cut a few holes in the box, 4 at the sides and 16 in the front with some space in between. This is so that you can add lights in the box that shine through the holes. I also made 2 holes in each side for the sonar. The last holes I made were 3 holes in the middle of the box at the front so I could put the three wires from the Neopixel ring through them.

When I was done with all this, I glued the box together and added perspex to cover the holes. Perspex diffuses light to some extend so this gives it an extra nice looking effect.

For a finishing touch can create a false bottom to hide all the wires.

Step 4: The Lock

To create the lock I used a metal wire that I bend and cut to create a hook for the actual lock, and a small hook for the servo motor. In the lid I screwed a small ring so the hook has something to lock on to. In the code you can find the lock and open position. You have to adjust the code so that the servo opens and closes accordingly.

If you have any questions or if you need help, just ask me in the comments!

Share

    Recommendations

    • Clocks Contest

      Clocks Contest
    • Water Contest

      Water Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    3 Discussions

    Can you post what libraries you used? All you have posted is "#include" i found the libraries for the neopixel leds online. But im not sure if there was any other libraries you used as well? Servo library etc?

    That's a neat lock setup :) Thanks for sharing!

    1 reply