diegostar23lol
Created December 6, 2017

Scarry box xD

When the sensor detects that there is no light, it activates the servomotors that control the box and remove the skull.

Scarry box xD

Things used in this project

Story

Read more

Custom parts and enclosures

pict0968_4w1hkLh69g.JPG

Mr. Bones

Schematics

pict0965_OfnYlMsj8Y.JPG

Code

Scarry box xD

Arduino
#define DUMP_REGS
 
#include <Wire.h>
#include <APDS9930.h>
 
// Global Variables
APDS9930 apds = APDS9930();
float ambient_light = 0; // can also be an unsigned long
uint16_t ch0 = 0;
uint16_t ch1 = 1;
 
#include <Servo.h>
int inputPin = 10;
int encendido=0;

Servo tapa, calaca;

void setup() {
  // Initialize Serial port
  Serial.begin(9600);
  Serial.println();
 
  // Initialize APDS-9930 (configure I2C and initial values)
  if ( apds.init() )
  {
    Serial.println(F("APDS-9930 initialization complete"));
  }
  else
  {
    Serial.println(F("Something went wrong during APDS-9930 init!"));
  }
 
  // Start running the APDS-9930 light sensor (no interrupts)
  if ( apds.enableLightSensor(false) )
  {
    Serial.println(F("Light sensor is now running"));
  }
  else
  {
    Serial.println(F("Something went wrong during light sensor init!"));
  }
 
  // Wait for initialization and calibration to finish
  delay(500);
    pinMode(inputPin, INPUT);
  calaca.attach(6);
  tapa.attach(9);
}

void loop() {
   // Read the light levels (ambient, red, green, blue)
  if (  !apds.readAmbientLightLux(ambient_light) ||
        !apds.readCh0Light(ch0) ||
        !apds.readCh1Light(ch1) ) {
    Serial.println(F("Error reading light values"));
  }
  else
  {
    Serial.print(F("Ambient: "));
    Serial.print(ambient_light);
    Serial.print(F("  Ch0: "));
    Serial.print(ch0);
    Serial.print(F("  Ch1: "));
    Serial.println(ch1);
  }
 
  // Wait 1 second before next reading
  delay(1000);
  if (digitalRead(inputPin) == HIGH) {
    encendido=1;
  }
  else {
encendido=0;
  }

  if (encendido == 1) {
 
  calaca.detach();
  tapa.attach(6);//angulos de donde comienza
  tapa.write(40);//angulos del servo de tapa
  delay(500);

  calaca.detach();
  tapa.attach(6);
 calaca.write(140);
  delay(1000);
  tapa.write(0);
  delay(1000);
   calaca.detach();
  calaca.attach(9);
 calaca.write(0);
  delay(1000);
}
}

Credits

diegostar23lol

diegostar23lol

1 project • 0 followers

Comments