Tengo mi circuito como tal en proteus usando 2 LDR con 2 resistencias de 220 Ω, el motor servo y un capacitor de 1 uF, pero no sé si esta configuración funcione.
Cuando uso el LDR no funciona para nada el servo.
Cuando uso el LDR no funciona para nada el servo.
PHP:
#include <Servo.h>
Servo myServo; // objeto servo
int angle;
//Varibles para los sensores de luz
int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
int umbral0;
int umbral1;
int sensorValue2;
int sensorLow2 = 1023;
int sensorHigh2 = 0;
int potVal2;
int potVal;
void setup() {
myServo.attach(8);
Serial.begin(9600); // monitor
// calibracion primer sensor
while (millis() < 5000) {
sensorValue = analogRead(A0);
if (sensorValue > sensorHigh) {
sensorHigh = sensorValue;
}
if (sensorValue < sensorLow) {
sensorLow = sensorValue;
}
}
Serial.println(sensorHigh);
Serial.println(sensorLow);
// calibracion del segundo sensor
while (millis() < 10000) {
// valor maximo
sensorValue2 = analogRead(A1);
if (sensorValue2 > sensorHigh2) {
sensorHigh2 = sensorValue2;
}
// valor minimo
if (sensorValue2 < sensorLow2) {
sensorLow2 = sensorValue2;
}
}
Serial.println(sensorHigh2);
Serial.println(sensorLow2);
umbral0 = sensorLow + ((sensorHigh - sensorLow) / 2) - 10;
umbral1 = sensorLow2 + ((sensorHigh2 - sensorLow2) / 2) - 10;
Serial.println(umbral0);
Serial.println(umbral1);
delay(10000);
}
void loop() {
//lectura in del exterior (luz)
potVal = analogRead(A0);
potVal2 = analogRead(A1);
if(potVal < umbral0){
Serial.print("potVal: ");
Serial.print(potVal);
Serial.println(umbral0);
angle = 90;
Serial.print("angle: ");
Serial.println(angle);
//posicion servo
myServo.write(angle);
delay(300);
}
if(potVal2 < umbral1){
Serial.print("potVal2: ");
Serial.print(potVal2);
Serial.println(umbral1);
angle = 0;
Serial.print("angle2: ");
Serial.println(angle);
// posicion servo
myServo.write(angle);
delay(300);
}
}
Adjuntos
Última edición por un moderador: