PostsWifi

Automatic adjust brightness according to how bright the environment is

A light that can change it brightness based on how much light the surrounding area have:

This guide is for a light that can adjust its own brightness based on how much light surrounds it. This is just a concept so I will use an LED to demonstrate, but the idea is the same for a real light bulb too, you just need something to control AC power. I used an Arduino Uno for this, but feel free to use whatever you like, the concept will still be the same.

 

Schematics

Both of them needs an 220 ohm resistor

Photoresistor             sensor

GND(+)                      GND(-)

VCC(+)                      VCC(+)

 

LED                            sensor

GND(-)                       GND(-)

VCC(+)                      VCC(+)

 

Source Code


</pre>

//Constants

const int pResistor = A0; // Photoresistor at Arduino analog pin A0

const int ledPin=6;       // Led pin at Arduino pin 9

&nbsp;

//Variables

int value;          // Store value from photoresistor (0-1023)

&nbsp;

void setup(){

Serial.begin(9600);

pinMode(ledPin, OUTPUT);  // Set lepPin - 9 pin as an output

pinMode(pResistor, INPUT);// Set pResistor - A0 pin as an input (optional)

}

&nbsp;

void loop(){

double value = analogRead(pResistor);

Serial.println(value);

&nbsp;

double valueToAnalogOutput =  (value / 1023) * 255;

&nbsp;

Serial.println(valueToAnalogOutput);

analogWrite(ledPin, (value / 1023) * 255);

&nbsp;

//  if(value < 900){ //    analogWrite(ledPin, 0); //  }else if(value >= 900 && value <= 910){ //    analogWrite(ledPin, 102.4); //  }else if(value >= 911 && value <= 920){ //    analogWrite(ledPin, 205.8); //  }else if(value >= 921 && value <= 930){ //    analogWrite(ledPin, 307.2); //  }else if(value >= 931 && value <= 940){ //    analogWrite(ledPin, 409.6); //  }else if(value >= 941 && value <= 950){ //    analogWrite(ledPin, 512); //  }else if(value >= 951 && value <= 960){ //    analogWrite(ledPin, 614.4); //  }else if(value >= 961 && value <= 970){ //    analogWrite(ledPin, 716.8); //  }else if(value >= 971 && value <= 980){ //    analogWrite(ledPin, 819.2); //  }else if(value >= 981 && value <= 990){ //    analogWrite(ledPin, 921.6); //  }else if(value > 991){

//    analogWrite(ledPin, 1023);

//  }

}
<pre>

Related posts
IntegrationPostsThe Things Network

How we integrated an external service to RTW using Webhooks and PhP

PostsWifi

Code used to connect to WIFI with Esp32 (Referenced as WifiCode)

PostsWifi

Automatic trash can opener based on distance

PostsWifi

Doorlock using Keypad with RTW

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *