Fablab_Irbid
Published © CC BY-NC-SA

Katara Water Lamp

A water fountain equipped with LED lighting controlled by Bluetooth.

IntermediateWork in progressOver 1 day1,248
Katara Water Lamp

Things used in this project

Hardware components

ATmega328
Microchip ATmega328
×1
Washer Pump
12V Car Universal Windshield Windscreen Washer Pump
×1
Bluetooth Module
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

3D Design

Schematics

Katara board

Code

Katara Code

Arduino
//Flash two LEDs at different rates using Simon Monk's Timer library
//http://www.doctormonk.com/2012/01/arduino-timer-library.html
//
//Jack Christensen 30Sep2013
//
//Beerware license: Free for any and all purposes, but if you find it
//useful AND we actually meet someday, you can buy me a beer!
#include <Servo.h>

#include <FastLED.h>
#include "Timer.h"                     //http://github.com/JChristensen/Timer
int pos=0;
int pump = 5;   // pump is connected to pin 5   
int pos1=170; 
int pos2=180; 
#define potentiometer A0 // to get the reading of the potentiometer and write it to the delay of the servo.                 
unsigned long PERIOD1 = 2;    

Timer t;                            
Servo myservo; 
#define LED_PIN     7 //Strip Data pin is connected to pin 10 of the arduino 
#define NUM_LEDS    30 // initially there were 30 LEDs in the strip, I cut the last 2 so there are only 28 now

CRGB leds[NUM_LEDS]; //initial values for the LED 
int x = 100;
int y = 50;
int z = 20;

unsigned long previousMillis = 0;        // will store last time Servo was updated
unsigned long previousMillisLED = 0;  // will store the last time the LED was lit

// constants won't change :
long interval;  // for the servo delay
long intervalLED = 20; // for the servo delay of the LED Strip
void setup(void)
{
    Serial.begin(9600); // for BT communication 
    FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);  myservo.attach(9); //define the LED Strip used
    pinMode(pump, OUTPUT);
    t.every(15,servo);  // call the servo function every 15 milliesecond
    t.every(25, LED); // call the LED function every 25 milliesecond
    t.oscillate(pump, PERIOD1, HIGH);
}

void loop(void)
{
    t.update(); //Update the timer
    if (Serial.available()){ // check if data is received 
      {
        char input=Serial.read(); 
       switch (input){
        case '1': // stop the servo
        pos1=0; 
        pos2=0; 
        break; 
        case '2':  // let the servo sweep 
        pos1=170; 
        pos2=180; 
        break; 
        case'3': // turn off strip 
        x=0; 
        y=0; 
        z=0; 
        break;
        case '4': //light the strip back 
        x = 80;
        y = 0;
        z = 125;
        break;  
        case '5':  // Make LED strobe slower
        intervalLED=30; 
        break;
        case '6':
        intervalLED=5;  // Make LED strobe faster 
        break;
        case '7': 
        intervalLED=20;  // Make LED strobe medium 
        break; 
       }
    }

    }
}

void servo(){ // Servo Function 
  interval= map (analogRead(potentiometer),0,1023,0,10); // change the delay of the servo depending on the potentiometer reading 
  for (pos = pos1; pos <=pos2; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos); 
  }// tell servo to go to position in variable 'pos'
    unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;                     // waits 15ms for the servo to reach the position
  
  for (pos = pos2; pos>= pos1; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  }
}

void LED(){
  memset(leds,(x,y,z),sizeof(leds)); //use this instead of for loop 
  FastLED.show();
  unsigned long currentMillisLED = millis();

  if (currentMillisLED - previousMillisLED >= intervalLED) {
    previousMillisLED = currentMillisLED;           
    // save the last time you blinked the LED
  memset(leds,(0,0,0),sizeof(leds));
  FastLED.show();  
}
} 

Credits

Fablab_Irbid
6 projects • 32 followers
Contact

Comments

Please log in or sign up to comment.