quinta-feira, 9 de abril de 2015

Arduino UNO R3 - Sensor de luminosidade


1)


2)

byte led_az=13;
byte led_vm=12;
byte led_am=11;
int ldr =A0;
int luz=0;
void setup()
{
pinMode(led_az,OUTPUT);
pinMode(led_vm,OUTPUT);
pinMode(led_am,OUTPUT);
digitalWrite(led_az,0);
digitalWrite(led_vm,0);
digitalWrite(led_am,0);
Serial.begin(9600);
}
void loop()
{
luz = analogRead(ldr);
Serial.println(luz);
if(luz >700)
{
digitalWrite(led_az,1);
digitalWrite(led_vm,0);
digitalWrite(led_am,0);
}
else if(luz < 300)
{
digitalWrite(led_az,0);
digitalWrite(led_vm,0);
digitalWrite(led_am,1);
}
else
{
digitalWrite(led_az,0);
digitalWrite(led_vm,1);
digitalWrite(led_am,0);
}
delay(100);
}