Aware Cap

19:59 PM 14 Jul, 2018
  • 0
  • 0
  • 0

A Cap that senses its surroundings. The cap is having a UV protected sunglasses and fitted to a servo motor whenever the sensor detects high UV Radiation the servo motor gets activated and it brings the sunglasses down.

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <Servo.h>



double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
double angale;
Servo servo_13;
Servo servo_12;



void setup(){
    pinMode(A0+0,INPUT);
    angale = 0;
    
}

void loop(){
    
    if((analogRead(A0+0)) > ( 800 )){
        for(int i=0;i<30;i++)
        {
            servo_13.attach(13);
            servo_13.write(angale);
            servo_12.attach(12);
            servo_12.write(angale);
            angale += 1;
            delay(1000*0.01);
        }
    }else{
        for(int i=0;i<30;i++)
        {
            servo_13.attach(13);
            servo_13.write(angale);
            servo_12.attach(12);
            servo_12.write(angale);
            angale += -1;
            delay(1000*0.01);
        }
    }
    
    _loop();
}

void _delay(float seconds){
    long endTime = millis() + seconds * 1000;
    while(millis() < endTime)_loop();
}

void _loop(){
    
}