Lava lamp – Learning path project 6

Our Learning Path is an itinerary designed to teach all the foundaments and a little more about electronics, coding and robotics.

When you complete all the projects you will be able to develop almost any project you can imagine. In each chapter new concepts are introduced. You will learn by doing in a funny way.

Build a lamp able to show and fade different colors thanks to the RGB LED.

Project 6
LAVA LAMP

Discover all the secrets of RGB and Neopixel LEDs

BEFORE TO START

DIFFICULTY LEVEL: Beginner
DURATION OF THE ACTIVITY: 40 min.

MATERIALS:
4in1 board
Buzzer
Battery holder & wires
Battery holder & wires

1 - Build&Code 4in1 board
1 - RGB Module
1 - Buzzer
1 - Switch Button

Battery holder, USB cable and wires.

6. Lava lamp - RGB LED

The RGB Led emits any color on the visible spectrum by combining the red (R), green (G), and blue (B) values. Our module uses NeoPixel addressable LED

Common RGB LEDs are 3 different color leds encapsulated together, and we can control each color as a regular led. This requires 3 digital outputs to control it.

NeoPixel addressable LED?

Yes! it's a regular LED combined with a little chip which make it adressable, so we can control with only one digital output a serial of NeoPixel LEDs, and set each of them with different state .

To use it, we need to install some additional libraries in our programming software. In MBlock5 it is not possible to use them yet, you must change to MBlock3

6. RGB LED - Circuit

As a Neopixel RGB LED, we just need one digital output to control the three base colors.

Connect wires according colours from 4in1 board to components:

- DIO4 to Button module
- DIO6 to RGB module
- A1 to Potentiometer

6.1 RGB LED - Program

We need to use function from Adafruit library. Here how install it in Arduino IDE . For mBlock5 we use the extension from Robokacija de Ivan Kunovi (not v2) See the coding video for details.

Arduino Coding
// include the libery of adafruit neopixel.h
#include <Adafruit_NeoPixel.h>

int ledpin = 6;

// change == strip but is just and variable.
Adafruit_NeoPixel change = Adafruit_NeoPixel(1, ledpin, NEO_RGB + NEO_KHZ800);

void setup() 
{
  // put your setup code here, to run once:
  change.begin(); //neopixel begin the rgb
  change.show();
  }

void loop() 
{
  // put your main code here, to run repeatedly:
  // Led color blue
  change.setPixelColor(0, 0, 0, 255);
  change.show();
  delay(2000);
  change.setPixelColor(0, 0, 255, 0);
  change.show();
  delay(2000);
  change.setPixelColor(0, 255, 0, 0);
  change.show();
  delay(2000);
  }
6.2 Rainbow

With 3 led colors, Red, Green and Blue, we can show any color. Let's see a beatiful rainbow colours sequence as example

Block coding
Arduino code
#include <Adafruit_NeoPixel.h>

//int rainbow = random(0,255);
int i = 0;

Adafruit_NeoPixel change = Adafruit_NeoPixel(1, 6, NEO_RGB + NEO_KHZ800);

void setup() 
{
  // put your setup code here, to run once:
  change.begin();
  change.show();
}

void loop() 
{
  // put your main code here, to run repeatedly:
   change.setPixelColor(0, 254, 0, 0);//red
   change.show();
   delay(350);
   change.setPixelColor(0, 250, 147, 0);//orange
   change.show();
   delay(350);
   change.setPixelColor(0, 238, 249, 0);//gellow
   change.show();
   delay(350);
   change.setPixelColor(0, 79, 249, 0);//green
   change.show();
   delay(350);
   change.setPixelColor(0, 5, 249, 249);//light blue
   change.show();
   delay(350);
   change.setPixelColor(0, 5, 68, 249);//dark blue
   change.show();
   delay(350);
   change.setPixelColor(0, 169, 68, 248);//purple
   change.show();
   delay(350);
   change.setPixelColor(0, 248, 68, 248);//pink
   change.show();
   delay(350);
}
6.3 Sound level warning

Do you remeber exercises of project 3? You can try same exercise but using RGB LED instead of 3 colored LED's

Block coding
Arduino code
#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel semaforo = Adafruit_NeoPixel(1, 6, NEO_RGB + NEO_KHZ800);

int valor = A0 + 1;


void setup() 
{
  // put your setup code here, to run once:
  semaforo.begin();
  semaforo.show();
}

void loop()
{ 
   valor = analogRead(valor);
    
   
   if(valor < 341)
   {
     semaforo.setPixelColor(0,0,255,0);
     semaforo.show();
          
   }
   else if(valor < 682) 
   {
      semaforo.setPixelColor(0, 0, 255, 0);
      semaforo.setPixelColor(0, 147, 250, 0);
      semaforo.show();
   }
   else if(valor < 1023)
   {
      semaforo.setPixelColor(0, 255, 0, 0);
      semaforo.show();
   }      
} 
6.4 - Vehicle emergency siren

Recover from your memory the siren of Project 4, it can be done also with a RGB LED instead of regular leds. Let's try!!

Block coding
Arduino code
#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel sirena = Adafruit_NeoPixel(1, 6, NEO_RGB + NEO_KHZ800);
 
void setup() 
{
  sirena.begin();
  sirena.show();
  pinMode(4, INPUT);
}

void loop() 
{
  if(digitalRead(4) == HIGH){
    sirena.setPixelColor(0, 0, 255, 0);
    sirena.show();
    delay(200);
    sirena.setPixelColor(0, 0, 0, 255);
    sirena.show();
    delay(200);
  }
  else
  {
    sirena.setPixelColor(0, 0, 0, 0);
    sirena.show();
    noTone(10);
  }
}
Final project - Lava lamp

In life there is also space for beautiful creations and not just practical systems. Get out your creative part to do this lava lamp shine incredible!! Here cardboard template if you need it.

Block coding
Arduino code
#include <Adafruit_NeoPixel.h>
int i = 0;
Adafruit_NeoPixel change = Adafruit_NeoPixel(1, 6, NEO_RGB + NEO_KHZ800);

void setup() 
{
  // put your setup code here, to run once:
  change.begin();
  change.show();
}

void loop() 
{
  // put your main code here, to run repeatedly:
   change.setPixelColor(0, 254, 0, 0);//red
   change.show();
   delay(350);
   change.setPixelColor(0, 250, 147, 0);//orange
   change.show();
   delay(350);
   change.setPixelColor(0, 238, 249, 0);//gellow
   change.show();
   delay(350);
   change.setPixelColor(0, 79, 249, 0);//green
   change.show();
   delay(350);
   change.setPixelColor(0, 5, 249, 249);//light blue
   change.show();
   delay(350);
   change.setPixelColor(0, 5, 68, 249);//dark blue
   change.show();
   delay(350);
   change.setPixelColor(0, 169, 68, 248);//purple
   change.show();
   delay(350);
   change.setPixelColor(0, 248, 68, 248);//pink
   change.show();
   delay(350);
}
previous arrow
next arrow
Slider

The Mega Maker Kit fits perfectly with the Learning Path, you can build all projects with it, but if you have other kits, you can also follow the entire itinerary and finish some projects, or buy the missing components. You can check in our Learning Path page.

0 0

0