0% found this document useful (0 votes)
89 views1 page

Sensor Servo

This code uses a servo motor to adjust its position based on the amount of light detected by a photoresistor. The photoresistor measures the light level and that value is mapped to a range from 0 to 180 degrees. The servo is then set to that position each time through the loop. This creates a feedback system where the servo adjusts its position continuously to correspond to the current light level.

Uploaded by

api-256260699
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views1 page

Sensor Servo

This code uses a servo motor to adjust its position based on the amount of light detected by a photoresistor. The photoresistor measures the light level and that value is mapped to a range from 0 to 180 degrees. The servo is then set to that position each time through the loop. This creates a feedback system where the servo adjusts its position continuously to correspond to the current light level.

Uploaded by

api-256260699
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Sensor de llum(servo)

// Sweep
// by BARRAGAN <http://barraganstudio.com>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
/*
* A simple programme that will change the intensity of
* an LED based * on the amount of light incident on
* the photo resistor.
*
*/
//PhotoResistor Pin
int lightPin = 0; //the analog pin the photoresistor is
//connected to
//the photoresistor is not calibrated to any units so
//this is simply a raw sensor value (relative light)
//LED Pin
int servo = 9; //the pin the LED is connected to
//we are controlling brightness so
//we use one of the PWM (pulse width
// modulation pins)
/*
* loop() this function will start after setup
* finishes and then repeat
*/
void loop()
{
int lightLevel = analogRead(lightPin); //Read the
// lightlevel
lightLevel = map(lightLevel, 300, 500, 0, 180);
//adjust the value 0 to 900 to
//span 0 to 255
lightLevel = constrain(lightLevel, 0, 180);//make sure the
//value is betwween
//0 and 255
myservo.write (lightLevel);
}

You might also like