Project tutorial
Controlling LED light intensity using smartphone light senso

Controlling LED light intensity using smartphone light senso

Light sensor and output on fading LED on a PWM pin

  • 2,217 views
  • 0 comments
  • 3 respects

Components and supplies

About this project


Code

Untitled fileArduino
#define CUSTOM_SETTINGS
#define INCLUDE_LIGHT_SENSOR_SHIELD

#include <OneSheeld.h>

long maxLightIntensity=0;
float ratio = 0;
long ledValue = 0;
long lightValue;
int ledPin = 10;

void setup()
{
  OneSheeld.begin();
  pinMode(ledPin,OUTPUT);
}

void loop()
{
  if(LightSensor.getValue() > maxLightIntensity)
  {
    maxLightIntensity = LightSensor.getValue();
    ratio = 255 / (float) maxLightIntensity;
  }
  lightValue = LightSensor.getValue();
  if(lightValue > maxLightIntensity)
  {
    lightValue = maxLightIntensity;
  }
  ledValue= 255 - lightValue * ratio;
  
  if(ledValue < 10)
  {
    analogWrite(ledPin,0);
  }
  else
  {
    analogWrite(ledPin,ledValue);  
  }
  
}
Codebender

Schematics

Fade-LED_bb.png
Fade led bb

Comments

Similar projects you might like

Control a RGB Led using Arduino and a smartphone's camera

Project tutorial by Mr robot Maker

  • 2,730 views
  • 0 comments
  • 8 respects

4x4x4 LED cube with Arduino Uno and 1sheeld

Project tutorial by Hassan Ibrahim

  • 29,722 views
  • 6 comments
  • 60 respects

Home surveillance system using skype calls

Project tutorial by Manuel Miguel

  • 1,621 views
  • 0 comments
  • 3 respects

Led fading using 1Sheeld

Project tutorial by Nado Hollow

  • 740 views
  • 1 comment
  • 2 respects

Unlock your door with a knock

Project tutorial by Ashraf Nabil

  • 22,839 views
  • 12 comments
  • 60 respects

Skype Mobile

Project tutorial by Guest

  • 1,015 views
  • 0 comments
  • 3 respects
Add projectSign up / Login