kk logo

Der Arduino Code für diese Seite (((link)))) 

4 LDR Sonnenlichtverfolger arduino selber bauen

 

Mit 4 LDR

------------------------------------   Code Start -------------------------------------------

 

#include  <Servo.h>

int zeit = 0 ;
int dif = 0 ;
int SERVO = 0 ;
int SERVO2 = 0 ;
int zaehler1 = 0 ;
int zaehler2 = 0 ;
int zaehler3 = 0 ;
int zaehler4 = 0 ;
Servo servo_pin_9;
Servo servo_pin_11;
int LDR1 = 0 ;
int LDR2 = 0 ;
int LDR4 = 0 ;
int LDR3 = 0 ;
int LDR5 = 0 ;

void Unterprogramm0();
void Unterprogramm1();
void Unterprogramm2();
void Unterprogramm3();
void Unterprogramm4();
void Unterprogramm5();

void setup()
{
servo_pin_9.attach(9);
servo_pin_11.attach(11);
Serial.begin(9600);
zeit = 100 ;

dif = 200 ;

SERVO = 90 ;

SERVO2 = 90 ;

zaehler1 = 0 ;

zaehler2 = 0 ;

zaehler3 = 0 ;

zaehler4 = 0 ;

servo_pin_9.write( 90 );

servo_pin_11.write( 90 );

delay( 1000 );

}

void loop()
{
Unterprogramm0();
Unterprogramm1();
Unterprogramm2();
Unterprogramm3();
Unterprogramm4();
Unterprogramm5();
}

void Unterprogramm0()
{
LDR1 = analogRead(1) ;
LDR2 = analogRead(3) ;
Serial.print("LDR 1---");
Serial.print(LDR1);
Serial.println();
Serial.print("LDR 2---");
Serial.print(LDR2);
Serial.println();
}

void Unterprogramm1()
{
if (( ( ( LDR1 - dif ) ) >= ( LDR2 ) ))
{
Serial.print("----------------------------------LDR 1 > LDR 2");
Serial.println();
while ( ( ( ( LDR1 - dif ) ) >= ( LDR2 ) ) )
{
Unterprogramm0();
zaehler2 = ( zaehler2 + 1 ) ;
delay( zeit );
Serial.print("zaheler1-----");
Serial.print(zaehler2);
Serial.println();
if (( ( zaehler2 ) == ( 5 ) ))
{
if (( ( SERVO ) < ( 180 ) ))
{
Serial.print("----- Servo dreht");
Serial.println();
SERVO = ( SERVO + 1 ) ;
zaehler2 = 0 ;
servo_pin_9.write( SERVO );
Serial.print("SERVO");
Serial.print(SERVO);
Serial.println();
}
}
}

zaehler2 = 0 ;
}
}

void Unterprogramm5()
{
if (( ( ( LDR4 - dif ) ) >= ( LDR3 ) ))
{
Serial.print("----------------------------------LDR 4 > LDR 3");
Serial.println();
while ( ( ( ( LDR4 - dif ) ) >= ( LDR3 ) ) )
{
Unterprogramm3();
zaehler4 = ( zaehler4 + 1 ) ;
delay( zeit );
Serial.print("zaheler4-----");
Serial.print(zaehler4);
Serial.println();
if (( ( zaehler4 ) == ( 5 ) ))
{
if (( ( SERVO2 ) > ( 0 ) ))
{
Serial.print("----- Servo dreht");
Serial.println();
SERVO2 = ( SERVO2 - 1 ) ;
zaehler4 = 0 ;
servo_pin_11.write( SERVO2 );
Serial.print("SERVO");
Serial.print(SERVO);
Serial.println();
}
}
}

zaehler4 = 0 ;
}
}

void Unterprogramm4()
{
if (( ( ( LDR3 - dif ) ) >= ( LDR4 ) ))
{
Serial.print("----------------------------------LDR 3 > LDR 4");
Serial.println();
while ( ( ( ( LDR3 - dif ) ) >= ( LDR4 ) ) )
{
Unterprogramm3();
zaehler3 = ( zaehler3 + 1 ) ;
delay( zeit );
Serial.print("zaheler3-----");
Serial.print(zaehler3);
Serial.println();
if (( ( zaehler3 ) == ( 5 ) ))
{
if (( ( SERVO2 ) < ( 180 ) ))
{
Serial.print("----- Servo dreht");
Serial.println();
SERVO2 = ( SERVO2 + 1 ) ;
zaehler3 = 0 ;
servo_pin_11.write( SERVO2 );
Serial.print("SERVO");
Serial.print(SERVO2);
Serial.println();
}
}
}

zaehler3 = 0 ;
}
}

void Unterprogramm3()
{
LDR3 = analogRead(4) ;
LDR4 = analogRead(5) ;
Serial.print("LDR 4---");
Serial.print(LDR4);
Serial.println();
Serial.print("LDR 5---");
Serial.print(LDR5);
Serial.println();
}

void Unterprogramm2()
{
if (( ( ( LDR2 - dif ) ) >= ( LDR1 ) ))
{
Serial.print("----------------------------------LDR 2 > LDR 1");
Serial.println();
while ( ( ( ( LDR2 - dif ) ) >= ( LDR1 ) ) )
{
Unterprogramm0();
zaehler1 = ( zaehler1 + 1 ) ;
delay( zeit );
Serial.print("zaheler1-----");
Serial.print(zaehler1);
Serial.println();
if (( ( zaehler1 ) == ( 5 ) ))
{
if (( ( SERVO ) > ( 0 ) ))
{
Serial.print("----- Servo dreht");
Serial.println();
SERVO = ( SERVO - 1 ) ;
zaehler1 = 0 ;
servo_pin_9.write( SERVO );
Serial.print("SERVO");
Serial.print(SERVO);
Serial.println();
}
}
}

zaehler1 = 0 ;
}
}

------------------------------------   Code Ende ------------------------------------------- 

Mit 2 LDR 

sonnenverfolger ldr und servo selber bauen 

------------------------------------   Code Start -------------------------------------------

#include <Servo.h>

int zeit = 0 ;
int dif = 0 ;
int SERVO = 0 ;
int zaehler1 = 0 ;
int zaehler2 = 0 ;
Servo servo_pin_9;
int LDR1 = 0 ;
int LDR2 = 0 ;

void Unterprogramm0();
void Unterprogramm1();
void Unterprogramm2();

void setup()
{
servo_pin_9.attach(9);
Serial.begin(9600);
zeit = 100 ;

dif = 200 ;

SERVO = 90 ;

zaehler1 = 0 ;

zaehler2 = 0 ;

servo_pin_9.write( 90 );

delay( 1000 );

}

void loop()
{
Unterprogramm0();
Unterprogramm1();
Unterprogramm2();
}

void Unterprogramm0()
{
LDR1 = analogRead(1) ;
LDR2 = analogRead(3) ;
Serial.print("LDR 1---");
Serial.print(LDR1);
Serial.println();
Serial.print("LDR 2---");
Serial.print(LDR2);
Serial.println();
}

void Unterprogramm2()
{
if (( ( ( LDR2 - dif ) ) >= ( LDR1 ) ))
{
Serial.print("----------------------------------LDR 2 > LDR 1");
Serial.println();
while ( ( ( ( LDR2 - dif ) ) >= ( LDR1 ) ) )
{
Unterprogramm0();
zaehler1 = ( zaehler1 + 1 ) ;
delay( zeit );
Serial.print("zaheler1-----");
Serial.print(zaehler1);
Serial.println();
if (( ( zaehler1 ) == ( 5 ) ))
{
if (( ( SERVO ) > ( 0 ) ))
{
Serial.print("----- Servo dreht");
Serial.println();
SERVO = ( SERVO - 1 ) ;
zaehler1 = 0 ;
servo_pin_9.write( SERVO );
Serial.print("SERVO");
Serial.print(SERVO);
Serial.println();
}
}
}

zaehler1 = 0 ;
}
}

void Unterprogramm1()
{
if (( ( ( LDR1 - dif ) ) >= ( LDR2 ) ))
{
Serial.print("----------------------------------LDR 1 > LDR 2");
Serial.println();
while ( ( ( ( LDR1 - dif ) ) >= ( LDR2 ) ) )
{
Unterprogramm0();
zaehler2 = ( zaehler2 + 1 ) ;
delay( zeit );
Serial.print("zaheler1-----");
Serial.print(zaehler2);
Serial.println();
if (( ( zaehler2 ) == ( 5 ) ))
{
if (( ( SERVO ) < ( 180 ) ))
{
Serial.print("----- Servo dreht");
Serial.println();
SERVO = ( SERVO + 1 ) ;
zaehler2 = 0 ;
servo_pin_9.write( SERVO );
Serial.print("SERVO");
Serial.print(SERVO);
Serial.println();
}
}
}

zaehler2 = 0 ;
}
}

 ------------------------------------   Code Ende ------------------------------------------- 

King of my heart

Let the King of my heart
Be the mountain where I run
The fountain I drink from
Oh, He is my song

Ronnie

schwäbischer tüftler und bastler, kraftsportler, ADHS power, 43 Jahre, 1 Frau, 5 Kinder und 1003 Ideen. 

ronnie berzins at mee