Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

Create a Color-Changing Lamp With Intel Galileo

Create a Color-Changing Lamp With Intel Galileo

In this tutorial, I’ll show you how to create a color-changing lamp with Intel Galileo.

You’ll convert from a temperature to a color on an RGB LED. You can also build this project with an Arduino, pretty much the same way.

If you’re new to this board, check out how to get started with Intel Galileo.

 

Shopping List:

  • Intel Galileo
  • Breadboard with Jumper wires
  • RGB LED
  • 3 x Resistors (330 Ohm)
  • DHT11 Temperature sensor

Step 1: Test the RGB LED

Connect the RGB LED onto a breadboard. Connect the common pin to 5V. Add a 330 Ohm resistor from each of the color pins, and use jumper wires to connect the three of them to pin 9, 10 and 11 on the Galileo.

I used three 330 Ohm resistors, but the voltage drop of the three light-emitting diodes are not equal. Mine had a 2V diode for the red, and 3.2V diodes for the green and blue. Which means that in a perfect world, you should have a different resistors value for the red pin. But it works fine with 330 on all of them.

You can learn how to calculate resistor values here.

Then test to see if all the colors are working. Upload the following code to test the different colors:

const int red_pin = 11;
const int green_pin = 10;
const int blue_pin = 9;
 
void setup() {
  pinMode(green_pin, OUTPUT);
  pinMode(blue_pin, OUTPUT);
  pinMode(red_pin, OUTPUT);
}
 
 
 
void loop() {
  //Red
  setColor(255, 0, 0);
  delay(1000);
 
  //Green  
  setColor(0, 255, 0);
  delay(1000);
 
  //Blue  
  setColor(0, 0, 255);
  delay(1000);
 
  //Pink
  setColor(255, 0, 255);
  delay(1000);
 
  //Turquoise
  setColor(0, 255, 255);
  delay(1000);
 
  //Yellow
  setColor(255, 255, 0);
  delay(1000);
 
  //White
  setColor(255, 255, 255);
  delay(1000);
 
}
 
//Custom made method for setting the color
void setColor(int red, int green, int blue)
{
  analogWrite(red_pin, 255 - red);
  analogWrite(green_pin, 255 - green);
  analogWrite(blue_pin, 255 - blue);
}

This should make your Intel Galileo change the color of the RGB LED like this:

Step 2: Connect the temperature sensor

The DHT11 sensor is pretty straightforward. But it uses a one-wire interface that causes a problem for the Intel Galileo. The problem is that the one-wire interface requires one pin to be switched back and forth between being an input and an output.

On an Arduino this happens really fast and is no problem. But on the Galileo this switching is too slow. Therefore, we need to use a diode to divide the data pin into an input and an output pin. Like this:

Connecting a DHT-11 temperature sensor to Intel Galileo

Note: Different modules have different pin placements. On mine, the data pin is on the middle pin. On others, it’s on the left or right.

Because of the modification above, you need a modified version of the DHT library: DHT library for Intel Galileo (Code by adafruit, modified by Dino Tinitigan)

Learn how to add custom libraries to Arduino.

Step 3: Create code for the Intel Galileo

Now, all you need to do is to create the final code. The code needs to:

  • Read the temperature
  • Convert this temperature into a color
  • Display the color on the RGB LED

Below is the code I created (based on the example code from the DHT library):

#include "DHT.h"
 
// what pins we're connected to
#define DHTIN 2 
#define DHTOUT 3
// Define the type (DHT11)
#define DHTTYPE DHT11
 
DHT dht(DHTIN,DHTOUT, DHTTYPE);
 
const int red_pin = 11;
const int green_pin = 10;
const int blue_pin = 9;
 
void setup() {
  Serial.begin(9600);
 
  pinMode(green_pin, OUTPUT);
  pinMode(blue_pin, OUTPUT);
  pinMode(red_pin, OUTPUT);
 
  //Initialize the sensor
  dht.begin();
}
 
void loop() {
 
  // Read temperature as Celsius and convert from float to int
  int temp = (int)dht.readTemperature();
 
  // Check if any reads failed and try again.
  if (isnan(temp)) {
    Serial.println("Failed to read from DHT sensor!");
  }
  else {
    Serial.print("Temperature: ");
    Serial.println(temp);
 
    // Set temperature range
    int high_temp = 35;
    int low_temp = 15;
    int med_temp = 25;
 
    // Make sure temperature stays within temperature range
    if (temp < low_temp)
      temp = low_temp;
    if (temp > high_temp)
      temp = high_temp;
 
    // Set color based on temperature
    int red_col = map(temp, low_temp, high_temp, 0, 255);
    int blue_col = map(temp, low_temp, high_temp, 255, 0);
    int green_col = 0;
    setColor(red_col, green_col, blue_col);
 
  }      
}
 
void setColor(int red, int green, int blue)
{
  analogWrite(red_pin, 255 - red);
  analogWrite(green_pin, 255 - green);
  analogWrite(blue_pin, 255 - blue);
}

More Intel Galileo Projects

Get started with Intel Galileo

A simple DIY weather station

Read more Here







 

More Articles to Read

Gesture Controlled Smart Home
Gesture Controlled Smart Home
Design for a Wideband, Differential Transimpedance DAC Output
Design for a Wideband, Differential Transimpedance DAC Output
Wrist thrusters let you fly through the water effortlessly
Wrist thrusters let you fly through the water effortlessly
Bertan/Spellman 225-20R HV power supply teardown
Bertan/Spellman 225-20R HV power supply teardown
Blinking Christmas Lights
Blinking Christmas Lights
Adjusting clock with alarm, hygrometer & thermometer on 1.8″ ST7735 display
Adjusting clock with alarm, hygrometer & thermometer on 1.8″ ST7735 display
Adding an “extra sense” with rangefinders
Adding an “extra sense” with rangefinders
This wireless game controller looks like a rug
This wireless game controller looks like a rug
How to run your ESP8266 for years on a battery
How to run your ESP8266 for years on a battery
Calibration of a 3-Phase Energy Meter Board on the ADE7754
Calibration of a 3-Phase Energy Meter Board on the ADE7754
Making beats on a tiny Arduino DJ controller
Making beats on a tiny Arduino DJ controller
Qinsi-QS5100 Sn63Pb37 solder profile
Qinsi-QS5100 Sn63Pb37 solder profile
Water Detection System
Water Detection System
Professional Hi-Fi 15W Tube Amplifier circuit
Professional Hi-Fi 15W Tube Amplifier circuit
This Arduino machine will judge how sick your ollies are
This Arduino machine will judge how sick your ollies are
Turn an old payphone into a boombox for ’90s hits
Turn an old payphone into a boombox for ’90s hits
Big F’n 3D printer build
Big F’n 3D printer build
Temperature alarm for boiling milk
Temperature alarm for boiling milk
QuadBot is a 3D-printable walking robot for everyone
QuadBot is a 3D-printable walking robot for everyone
MicroConverter I2C Compatible Interface
MicroConverter I2C Compatible Interface

Top


Shares