0

percentages with ldr

Hello,

I need to make a circuit in which a LED lights up when the LDR measures a reading of less than 30% of light, two LEDs light up when the LDR measures a reading between 30% and 70% and three LEDs light up when the LDR measures a reading of more than 70%.

I've done this with numbers and it works, but it's not accurate since 300 doesn't equal 30%. I have no idea how to write percentage so that it is understood by the program.

Can anyone help me?

 

[CODE]


const int rojo=13;
const int amarillo=11;
const int verde=10;
const int ldr=A0;


void setup()
{
pinMode(rojo, OUTPUT);
pinMode(amarillo, OUTPUT);
pinMode(verde, OUTPUT);
pinMode(ldr, INPUT);
}

void loop()
{
int ldrStatus = analogRead(ldr);

if (ldrStatus < 30%)
{
digitalWrite(rojo, HIGH);
digitalWrite(amarillo, LOW);
digitalWrite(verde, LOW);
}

else if (ldrStatus > 30% && ldrStatus <70%)
{
digitalWrite(rojo, HIGH);
digitalWrite(amarillo, HIGH);
digitalWrite(verde, LOW);
}

else if (ldrStatus > 100%)
{
digitalWrite(rojo, HIGH);
digitalWrite(amarillo, HIGH);
digitalWrite(verde, HIGH);
}
}

0 comments

Please sign in to leave a comment.