Automatic Sunglasses Hat

The coolest hat this side of the Mississippi

After my experiences from the first two exercises, I wanted to create something that went beyond using just LED-based outputs for Project 1. I also wanted to implement a sensor-based input, something I hadn’t tried previously. These desires led me to create the automatic sunglasses hat.

The idea was to attach a pair of sunglasses to a hat, then add a motor to raise and lower them. A light sensor embedded in the hat would read in the amount of light reaching the hat and user, then the sunglasses would be raised or lowered based on the amount of light being above or below a certain threshold. Additionally, there would be a switch so the user could override the system. For a light sensor, I used a photoresistor, and a simple pushbutton switch for the override.

To control the motor to raise and lower the glasses, an additional circuit was needed. This circuit is called an H-bridge, and allows the motor run off of an alternate power supply and be controlled by digital outputs from the Arduino. Different combinations of high/low signals sent to three pins will make the motor turn forwards or backwards, as well as stop the motor. To make the H-bridge control circuit, I used an L298N full bridge driver. The L298N contains two H-bridges, though I only needed to use one for this project. One of my motivations for doing this project was learning to create more advanced circuits, and making the H-bridge circuit helped me achieve that goal. Creating the circuit was challenging, but in the end, rewarding. I had trouble getting the circuit to run the motor, and tore it down and rebuilt it several times. Eventually, I realized that the H-bridge was causing a small voltage drop from the input power to the motor, and this drop was just enough to take the voltage below the operating threshold of the motor. I bumped up the power on power supply by 1 volt, and then everything worked perfectly.

The sunglasses are attached to the hat by two metal brackets bolted to the rim. Attached to one bracket is a motor with integrated gearbox. A small socket head cap screw joins the sunglasses to the gearbox output, which creates the connection that transfers the rotation from the motor to the sunglasses. Attached to the other bracket is a simple momentary push button switch. The light sensor is attached directly in the middle of the brim of the hat, pointing straight ahead.

The hat operates under simple principles. If the light is brighter than the set threshold, the sunglasses are lowered to protect the wearer’s eyes (the defalt position for the sunglasses is up). If the light is not brighter than the set threshold, then the sunglasses go to the raised position. If the push button is pressed when the glasses are down, the sunglasses will return to the up position and stay there for as long as the user presses the button. If the light is still too bright when the button is released, the glasses are lowered; if the light is no longer bright when the button is released, the glasses reamain up.

Below is an image gallery, along with the code used to control the hat.

/*sunglasses is code for controlling automated sunglasses on a hat. A light sensor takes
continuous readings and automatically lowers a pair of sunglasses to protect the wearer's
eyes when the light reaches a certain brightness threshold. If the light drops below the
brightness threshold, the glasses are raised. A push button can act as an override and raise
the sunglasses from the down position, keeping the sunglasses up for the lentgh of time it
is held down.

An h-bridge controls the motor to raise and lower the glasses. It has three inputs:
one to enable and two to control direction. Setting the control pins to opposite values
(one HIGH, one LOW) sets the motor's direction. Setting the control pins to equal values
brakes the motor. Setting the enable pin to HIGH turns on the motor, setting it to LOW turns
the motor off.

By Rich Pantaleo, October 2008
*/


int Cpin = 9;  //High/low h-bridge pin
int Dpin = 10; //High/low h-bridge pin
int Vpin = 11; //Main h-bridge enable pin
int pushButton = 2;  //Pin for push button switch
int lightSensor = 0; //Pin for light sensor input
int brightness = 0;  //Set up variable for reading value from light sensor
int buttonVal = 0;   //Set up variable to reading value from push button input
boolean glassesDown = false; //Flag that stores if sunglasses are up or down
boolean buttonDown = false;  //Flag that stores if the push button is pressed or notm
void setup(){
pinMode(Cpin, OUTPUT); //Declare pin as output
pinMode(Dpin, OUTPUT); //Declare pin as output
pinMode(Vpin, OUTPUT); //Declare pin as output
pinMode(pushButton, INPUT); //declare push button as input
pinMode(lightSensor, INPUT);//delcare ligth sensor as input
digitalWrite(Vpin, LOW); //Disable motor
}
void loop(){

brightness = analogRead(lightSensor); //Read the input value of the light sensor
buttonVal= digitalRead(pushButton);   //Read the input value of the push button

  if(brightness<=530 && glassesDown == false && buttonDown == false){ //If the brightness is below a set threshold, the glasses are not down, and the push button is not down
    sunglassesdown();//Put the sunglasses down
  }
 
  if(brightness>530 && glassesDown == true && buttonDown == false){ //If the brightness is above a set threshold, the glasses are down, and the push button is not down
    sunglassesup();//Put the sunglasses up
  }
 
  if(buttonVal == HIGH && buttonDown == false && glassesDown == true){//If the push button is pressed down and the sunglasses are down
   sunglassesup(); //Put the sun glasses up
   buttonDown = true; //Set the push button flag to down

  }
  if(buttonVal == LOW){//If the push button is not being pressed
  buttonDown = false; //Set the push button value to up
  }
}
void sunglassesdown(){       //Put the sunglasses down
 digitalWrite(Cpin, LOW);    //Send no signal pin C on the h-bridge
  digitalWrite(Dpin, HIGH);  //Send a signal to pin D on the h-bridge, now the motor is set to turn forward and lower the sunglasses
  digitalWrite(Vpin, HIGH);  //Send a signal to pin V on the h-bridge, enable the motor
  delay(380);                //Run the motor for 380 milliseconds
  digitalWrite(Cpin, HIGH);  //Brake the motor
  digitalWrite(Vpin, LOW);   //Disable the motor
  glassesDown = true;        //Set the glasses flag to down
}

void sunglassesup(){         //Put the sunglasses up
  digitalWrite(Cpin, HIGH);  //Send a signal pin C on the h-bridge
  digitalWrite(Dpin, LOW);   //Send no signal to pin D on the h-bridge, now the motor is set to turn backward and raise the sunglasses
  digitalWrite(Vpin, HIGH);  //Send a signal to pin V on the h-bridge, enable the motor
  delay(380);                //Run the motor for 380 milliseconds
  digitalWrite(Dpin, HIGH);  //Brake the motor
  digitalWrite(Vpin, LOW);   //Disable the motor
  glassesDown = false;       //Set the glasses flag to up
}

 

 

 

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s