Home

Light sensor arduino servo

I connected a light sensor to control a servo

code

#include <Servo.h> // include the servo library
Servo servoMotor; // creates an instance of the servo object to control a servo
int analogPin = 0; // the analog pin that the sensor is on
int analogValue = 0; // the value returned from the analog sensor
int servoPin = 2; // Control pin for servo motor.  can be any pin
int value;
void setup() {
servoMotor.attach(servoPin); // attaches the servo on pin 2 to the servo object
Serial.begin(9600);
}
void loop()
{
analogValue = analogRead(analogPin); // read the analog input (value between 0 and 1023)
analogValue = map(analogValue, 0, 1023, 0, 179); // map the analog value (0-1023) to the servo angle (0-179)
servoMotor.write(analogValue); // write the new mapped analog value to set the servo position
light = analogRead(analogValue);
value = analogRead(analogValue);
Serial.println(value);// Sends the data value to Grasshopper
delay(500); // waits for the servo to get there
}

light sensor servo Arduino

Assembly List

Label Part Type Properties
Arduino1 Arduino processor ATmega; variant Arduino UNO R3
J3 Basic Servo
R1 Photocell (LDR) package THT; resistance@ dark 300 kOhms@ 10 seconds; resistance@ luminance 16 kOhms@ 10 lux
R2 220 Ω Resistor package THT; tolerance ±5%; bands 4; resistance 220Ω; pin spacing 400 mil

Exported with Fritzing 0.7.12- http://fritzing.org

2 servo were used continuos and standard just to note the difference between the two types.