Hat-mounted mood broadcasting device

For exercise 2, I modified the same hat that I used in exercise 1. I decided to make a hat that was capable of signalling to other people the mood of the wearer. This is accomplished using a tri-color RGB LED, a potentiometer, momentary push button switch, and the Arduino.

The idea is that the hat wearer can broadcast 3 different moods. By pushing the button, he or she can turn on either the red, blue, or green diode of the LED. Blue = sad, green = happy, and red = angry. Using the potetniometer, the wearer can adjust the brighness of the LED, and this corresponds directly to the intensity of the mood. The brighter the light, the sadder, angrier, or happier the wearer.

The LED, embedded in the brim of the hat, has one cathode and three anodes (one each for red, green, and blue). Each of the anodes is connected to a PWM pin on the Arduino so the brightness can be controlled by an analog input. The push button and potentionmeter are  also mounted on the brim.

After powering up the Arduino, the LED is off. Pressing the button twice will illuminate the blue  diode. Two more button presses turns off the blue diode and illuminates the green diode. Two more presses and the green diode is turned off and the red diode is turned on. Finally, two more button presses turns of the LED completely, and you are back at the beginning of the cycle. During this entire loop, the brightness of the LED is controlled by the potentiometer, which is acting as an analog input into the Arduino.

Below is the code, and below the code is a photo gallery of the finished project.

This is a program used to control a tri-color LED (or three LEDs) with a push button swtich.
The push button turns the various colors (or LEDS) on and off, and the potentiometer controls the brightness

By Rich Pantaleo
Adapted from Greg Saul's 'Button' code, presented during a 'Making Things Interactive' lecture in September 2008


int blueled = 11; // choose the pin for the blue LED
int redled = 10; // choose the pin for the red LED
int greenled = 9; // choose the pin for the green LED
int inputPin = 3; // choose the input pin for the push button
int potPin = 5 ; // analog input pin for potentiometer
int potVal = 0 ; // value from potentiometer
int buttonstatus = 0; // variable for reading the pin status
int counter = 0; // store the number of button presses
boolean buttonDown = false; // a flag that stores if the button is beeing pressed down or not

void setup() {
pinMode(blueled, OUTPUT); // declare blue LED as output
pinMode(redled, OUTPUT); // declare red LED as output
pinMode(greenled, OUTPUT); // delcare green LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
digitalWrite(blueled, LOW); // turn Blue LED OFF
digitalWrite(redled, LOW); // turn Red LED OFF
digitalWrite(greenled, LOW); // turn Green LED OFF
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps


void loop(){

potVal = analogRead(potPin); //Read the potentiometer input
buttonstatus = digitalRead(inputPin); // read input value from button

if (buttonstatus == HIGH && buttonDown == false) { // check if the input is HIGH and the button is not already been held down
buttonDown = true; // set the button flag to down
counter = counter +1; // add one to the counter
Serial.println(counter); // send the current counter value to the computer

if (buttonstatus == LOW){ // if we are no longer pressing the button down
buttonDown = false; // set the buttonDown value to up

if(counter == 2 || counter == 3){ // After the button has been pressed twice
analogWrite(blueled, potVal/3); // Turn on the blue LED to a value equal to the input from the potentiometer divided by 3
if(counter == 4 || counter == 5){ // After two more button presses
analogWrite(blueled, 0); // Turn off the blue LED
analogWrite(greenled, potVal/3); // Turn on the green LED to a value equal to the input from the potentiometer divided by 3
if(counter == 6 || counter == 7){ // After two more button presses
analogWrite(greenled, 0); // Turn off the green LED
analogWrite(redled, potVal/3); // Turn on the red LED to a value equal to the input from the potentiometer divided by 3
if (counter > 7){ // After two more button presses
analogWrite(redled, 0); // Turn off the red LED
counter = 0; // Set the counter back to 0



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s