Hello everyone..i'm really need your help..i have a problem to understand how to control the brightness of LED using LDR for PIC16F..can you give me the sample coding??I'm really want to learn about it..i have found a sample of coding according to the title as shown below. However, it used an arduino microcontroller instead of PIC16F..please help me..
Thank you..
Rich (BB code):
int sensorPin = A0;
int sensorPin1 = A1;
int sensorPin2 = A2;
int led = 11;
int sensorValue = 0;
int sensorValue1 = 0;
int sensorValue2 = 0;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(sensorPin, INPUT);
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
}
void loop () {
sensorValue = analogRead(sensorPin);
sensorValue1 = analogRead(sensorPin1);
sensorValue2 = analogRead(sensorPin2);
if (sensorValue<500)
{analogWrite(led, 50);}
if (sensorValue1<500)
{analogWrite(led, 150);}
if (sensorValue2<500)
{analogWrite(led, 255);}
Serial.println(sensorValue);
Serial.println(sensorValue1);
Serial.println(sensorValue2);
delay(10);
}
Last edited by a moderator: