Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #define MAXHOEK 90
- #define MINHOEK 0
- int LDR = 0; //analog pin to which LDR is connected, here we set it to 0 so it means A0
- int LDRValue = 0; //that’s a variable to store LDR values
- int light_sensitivity = 500; //This is the approx value of light surrounding your LDR
- Servo myservo;
- int teller = 0; //Bezit de waarde 0 als initiële waarde (servo start altijd in dezelfde positie?), is 1 als servo gedraaid is, is 0 als servo terug gedraaid is
- void setup(){
- Serial.begin(9600); //start the serial monitor with 9600 buad
- pinMode(10, OUTPUT); //we mostly use 13 because there is already a built in yellow LED in arduino which shows output when 13 pin is enabled
- myservo.attach(12);
- }
- void loop(){
- LDRValue = analogRead(LDR); //reads the ldr’s value through LDR
- Serial.println(LDRValue); //prints the LDR values to serial monitor
- delay(500); //This is the speed by which LDR sends value to arduino
- if (LDRValue < light_sensitivity){
- digitalWrite(13, HIGH);
- //maakt teller oneven als even, maakt teller even als oneven
- teller++;
- //maakt teller 0 als even, 1 als oneven
- teller %= 2;
- if(teller){ //teller=1
- //code om servo te doen draaien in een richting
- myservo.write(MAXHOEK);
- delay(15);
- } else { //teller=0
- //code om servo terug te doen draaien
- myservo.write(MINHOEK);
- delay(15);
- }
- while(LDRValue < light_sensitivity){
- LDRValue = analogRead(LDR); //reads the ldr’s value through LDR
- Serial.println(LDRValue); //prints the LDR values to serial monitor
- delay(500); //This is the speed by which LDR sends value to arduino
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement