Servo y LDR con Arduino en Proteus

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. :confused:

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

  • peaje2.jpg
    peaje2.jpg
    106.3 KB · Visitas: 25
Última edición por un moderador:
220 ohms? Se me hace un valor muy pequeño para usarlo junto con LDR. De qué valor es el LDR? 1K, 5K, 10k, 100k? Intenta colocar un potenciómetro de 10k en vez de la resistencia de 220 y vas variando, Saludos.
 
Voy a colocar el potenciometro que dices ruben90, sin embargo los LDR que están allí vienen por defecto como los coloca proteus y la verdad en otros proyectos nunca cambie el valor de la resistencia, pero haré lo que me dices. Gracias
 
Para elegir el valor de resistencia en serie que te de la mayor diferencia de voltaje aplica la siguiente formula: raiz(Rmax*Rmin) ,donde Rmax y Rmin es el valor máximo y mínimo que midas en el LDR.
 
Atrás
Arriba