Introduction: Arduino All the Things - Mood Detecting Light

this is a magic crystal mood ball you can make it with arduino so let's go

Step 1: You Need!!!!

to make this stupid pet trick I used 5 RGB LEDs (Digital Output), resistors, wires, a TMP36 temperature sensor (Analog Input), a breadboard, and an Arduino Uno. I built a base for the “crystal ball” and put the circuit with the Arduino inside, and made a little black altar with stars in a box so the LEDs could shine inside.

The mood that the “Magic Crystal Mood Ball” gives to the user is based on measuring his temperature and changing the color of the RGB LED to the its respective color. As in a mood ring, I set different colors for different temperatures. The temperatures coincides with mood state that the person is in.

For exemple, if you are feeling comfortable and calm, the temperature of your skin is going to be normal (about 27 degrees Celsius or 82 degrees Fahrenheit), and the ball is Cyan. Since the last days were colder, the “normal” temperature of the skin was lower, so I adapted this new environment in the code.

Step 2: How I Made It

I wrote the whole code at once without testing and, of course, it didn’t worked. So I wasted 300 hours trying to fix it and, of course, it still wasn’t working. Finally, I ran to Benedetta who helped me and suggested to go testing everything, step by step.

So first I tested the code for the temperature sensor and made sure that it was working properly and reading the right values. Then I tested the RGB LED, playing with the colors and synchronizing it with the Arduino, since each RGB LED was responding differently to the code. After that, I mixed both codes – the temperature sensor and the RGB LED – and doing some alterations it worked.



Finally, I prepared the breadboard with 5 RGB LEDs (2 groups of 2 LEDs in paralel and another one alone). Since I try to be as organized as possible with my wires, I kind of connected everything through wires, so I could one need to use 3 digital pins for all the LEDs (each digital pin represents one different color = Red, Green, Blue), 3 wires for the temperature sensor (it used 2 wires connected to the breadboard – power and ground – and 1 analog pin) and more 2 wires connecting the breadboard to the 5V Power and to the Ground.

Step 3: Code It



The Code

/* “The Magic Crystal Mood Ball”
Stupid Pet Trick – ITP 2011
*/

//TMP36 Pin Variables
int temperaturePin = 0; //input: the analog pin the TMP36 is connected

//RGB LED pins
int ledDigitalOne[] = {9, 10, 11}; //output: the three digital pins of the RGB LED
//9 = redPin, 10 = greenPin, 11 = bluePin

const boolean ON = LOW;
const boolean OFF = HIGH;

//Predefined Colors
const boolean RED[] = {ON, OFF, OFF};
const boolean GREEN[] = {OFF, ON, OFF};
const boolean BLUE[] = {OFF, OFF, ON};
const boolean YELLOW[] = {ON, ON, OFF};
const boolean CYAN[] = {OFF, ON, ON};
const boolean MAGENTA[] = {ON, OFF, ON};
const boolean WHITE[] = {ON, ON, ON};
const boolean BLACK[] = {OFF, OFF, OFF};

void setup()
{
for(int i = 0; i < 3; i++){
pinMode(ledDigitalOne[i], OUTPUT); //Set the RGB LED pins as outputs
}
Serial.begin(9600); //Start the serial connection with the computer
}
void loop()
{
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
temperature = (((temperature – .5) * 100)*1.8)+32; //converting from 10 mv per degree wit 500 mV offset
int newTemperature = temperature; //to degrees ((volatge – 500mV) times 100)
Serial.println(newTemperature); //printing the result

delay(7000); //waiting 7 seconds to get a new result

// Set the three LEDs to any predefined color depending of the temperature in ºF
if ((newTemperature>40) && (newTemperaturesetColor(ledDigitalOne, BLACK);
Serial.println(“Black”);
}
else if ((newTemperature>=72) && (newTemperaturesetColor(ledDigitalOne, WHITE);
Serial.println(“White”);
}
else if ((newTemperature>=74) && (newTemperaturesetColor(ledDigitalOne, GREEN);
Serial.println(“Green”);
}
else if ((newTemperature>=76) && (newTemperaturesetColor(ledDigitalOne, CYAN);
Serial.println(“Cyan”);
}
else if ((newTemperature>=78) && (newTemperaturesetColor(ledDigitalOne, BLUE);
Serial.println(“Blue”);
}
else if ((newTemperature>=80) && (newTemperaturesetColor(ledDigitalOne, YELLOW);
Serial.println(“Yellow”);
}
else if ((newTemperature>=82) && (newTemperaturesetColor(ledDigitalOne, RED);
Serial.println(“Red”);
}
else {
setColor(ledDigitalOne, MAGENTA);
Serial.println(“Magenta”);
}
}
float getVoltage(int pin){
return (analogRead(pin) * .004882814); //converting from a 0 to 1024 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}
// Function to set the color
void setColor(int* led, boolean* color){
for(int i = 0; i < 3; i++){
digitalWrite(led[i], color[i]);
}
}
// A version of setColor that allows for using const boolean colors
void setColor(int* led, const boolean* color){
boolean tempColor[] = {color[0], color[1], color[2]};
setColor(led, tempColor);
}

Comments

author
CselsziE (author)2016-04-12

What resistors did you use in this experiment?

author
kd7eir (author)2015-12-29

Very nice. I am going to adapt this to use WS2812B RGB LED's that I have.

author
Ayush0007 (author)kd7eir2016-01-09

All right












About This Instructable

1,559views

22favorites

License:

More by Ayush0007:Close Set-- a Multiple Little Things Box by Ayush Eye Writer 3.0Arduino All the Things - Mood Detecting Light
Add instructable to: