Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hackster is hosting Impact Spotlights: Industrial Automation. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Industrial Automation. Stream on Thursday!
attissedain
Published © LGPL

Arduino Uno Colour Lock

A lock that uses colours instead of pins.

IntermediateWork in progress1,120
Arduino Uno Colour Lock

Things used in this project

Hardware components

Adafruit Arduino Compatible RGB LED Strip Module
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Mini Pushbutton Switch
×1
Male/Male Jumper Wires
×6
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Resistor 10k ohm
Resistor 10k ohm
×1
LED (generic)
LED (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

ye_aTsduuemTi.stl

Schematics

Schematic of Circuit

Code

The Awesome Code

Arduino
#include <FastLED.h>//set up the fastLED library

#define DATA_PIN 13//set the data pin for the led strip




#define NUM_LEDS 8 //define number of LED and pin



CRGB leds[NUM_LEDS];// create the led object array
const CRGB sequence = CRGB::Blue;
int B = 1;// Set B or any value you want
long COLOUR[5]= { CRGB(225,0,0), CRGB(0,225,0), CRGB(0,0,225), CRGB(225,128,0), CRGB(225,225,0)};//initilise the colours you are going to use. You can change, add or decrease what colours you want.
long int goTime;//set up the status time
int i = 0;//set what i is for the while loop and the led counter
byte  r, g, b;//set up the colours
const int buttonPin = 7;// the pin our push button is on
const int ledPin = 13;// We will use the internal LED
void setup()
{
  // initialize the LED object
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  // set random seed
  pinMode(buttonPin,INPUT); // Set the Tilt Switch as an input
  pinMode(ledPin,OUTPUT); // Set the internal LED Pin as an output
  pinMode(3,OUTPUT);//set the other led 
}

void loop()
{
      byte colourIndex = 0;//initialize what colour index is
      goTime = millis();//set up the timer
      
         while(i <= 7)//while loop for i
    {         
            
            if(millis()-goTime >= 1000 )//begin the delay timer
            {
              
              leds[i] = COLOUR[colourIndex];  //this will change the led each time the loop happens comes ar
              colourIndex++;
              if(colourIndex > 5)//checks if there are no more colours
              {
                colourIndex = 0;//resets the loop back to the first colour 
              }
              FastLED.show();//show what happened
              goTime = millis();//resets the timer/delay
              if(digitalRead(buttonPin) == HIGH)//check if a button is pressed
              {
                B = 1;//just something to fill in the gap
                     
              }else{
                if (i>7){
                  i = 10;
                }
               i++;//changes the led the loop happens on 
                
              }
             
      
    }
  if (leds[0] == CRGB(0,0,225)
  and leds[1] == CRGB(0,0,225)
  and leds[2] == CRGB(0,0,225)
  and leds[3] == CRGB(0,0,225)
  and leds[4] == CRGB(0,0,225)
  and leds[5] == CRGB(0,0,225)
  and leds[6] == CRGB(0,0,225)
  and leds[7] == CRGB(0,0,225))//checks if the sequence is finished and if it matches then blink the green led. the sequence is just blue for all led.
  {
    digitalWrite(3,HIGH);   
    delay(500);
    digitalWrite(3,LOW);   
    delay(500);
    digitalWrite(3,HIGH);   
    delay(500);
    digitalWrite(3,LOW);   
    delay(500);
    digitalWrite(3,HIGH);   
    delay(500);
    digitalWrite(3,LOW); 

          
  }
           
  

    }

Credits

attissedain
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.