Automatic Sunglasses

introduction

The automatic sunglasses were one of the first projects I ever built, and it was my introduction to using Arduino.
The inspiration for the project came from the video on the right, but there were a few things that I wanted to change to increase the project’s complexity.
The original project used an Arduino Pro mini to run the system, a relatively large controller for such a small project.
Instead, I used the ATTINY85 microcontroller to run the system as well as leveraging 3D printing to create enclosures for the electronics.
I also added a small bluetooth module connected to headphones to allow the wearer to listen to while wearing the glasses.

Mechanics

The mechanical system in the sunglasses was very simple, with a servo being connected to the lenses to raise and lower them during operation.
The system’s frame was a cheap pair of sunglasses purchased at Walmart.
The electronics were housed in a small 3D-printed enclosure designed in Solidworks to protect solder joints and provide a mounting point for the electronics.

Electronics

To add a level of automation to the sunglasses, as the Instructables did, I used an LDR to sense the intensity of light the wearer was exposed to.
Based on the threshold values set in the software, the value sent from the LDR to the ATTINY85 determined whether or not to open or close the glasses.
Also, I added a 9V rechargeable battery to power the system to provide extended power and recharge ability.
However, all of the devices in the system ran at 5V so a L7805CV MOSFET was added to protect the powered components.
As an enhancement to the original design in the Instructables, I added Bluetooth headphone capabilities by placing a cheap Bluetooth audio module on one side of the glasses and soldering small earbuds to the output port to remove the excess wire and keep the system compact.

Software

The code written to operate the automatic sunglasses is relatively straightforward.
As mentioned earlier the only control needed was to read the LDR value and move the servo accordingly.
Using the “SoftwareServo1” library allowed for the ATTINY85 to control the servo on the glasses and including a call to refresh method after every move allowed for the servo movements to be repeatable as it would get stuck after moving is this call was not made.
Another complication introduced by the ATTINY85 was uploading software. S
Since there is no dedicated programming port on the ATTINY, an external microcontroller like the Arduino Uno shown had to be used to upload code.
However, now there are dedicated ATTINY85 programming modules that allow for this step to be bypassed.
C++
#include <SoftwareServo1.h>  /* use SoftwareServo Library (Allows for ATTINY 85 usage integration as well) */

SoftwareServo1 myServo;       /* Name the servo "myServo" */
int servoPin = 0;           /* Create variable for Servo on Pin 0 */
int ldr = A1;
int value = 0;
int i;/* Create variable for counting refreshes */

void setup()
{
  myServo.attach(servoPin);          /* Attach servo object to desired output pin */


  /* The best minimum & maximum pulse widths will depend on the brand & type
     of servo used.  These settings work well with our Towerpro microservos.   */

  myServo.setMinimumPulse(496);  /* set minimum pulse width */
  myServo.setMaximumPulse(2245); /* set maximum pulse width */
}

void loop()
{
  value = analogRead(ldr); // Read the sensor value and check if the value is above or below our desired threshold
  delay(100);
  if(value<100)
  {
    myServo.write(155);
    for (i = 1; i < 30; i++)
  { SoftwareServo1::refresh();  /* Refresh servo after moving */
    delay(50); 
  }
  }
  else
  {
    myServo.write(80);
    for (i = 1; i < 30; i++)
  { SoftwareServo1::refresh();  /* Refresh servo after moving */
    delay(50); 
  }
  }
}
Produced @ UTSA Robotics & Automation Laboratory

Final Prototype Testing

Build Tutorial