Week 6- Photo Resistor & Servo Motor
- Audrey Schank

- Dec 1, 2024
- 4 min read
Our maker challenge this week was to solve a real-world problem with the help of AI. Our problem was to mimic the opening and closing of blinds based on the amount of light outside. We were given the scenario of Nome, Alaska where the sun may rise and not set again for over 21 hours. Having these automated blinds would help people be able to sleep without being woken by the sun shining in their windows.
I set up an account on ChatGPT and asked it for beginner step-by-step circuit building instructions and code for Arduino Uno using a photo resistor and servo motor. The servo was supposed to move based on how much light the photo resistor was receiving, This could be done by turning a flashlight off and on, or by covering the photo resistor so it received less light.
Within a few seconds of telling ChatGPT what I wanted, I had the instructions and code that I needed. I uploaded the code and of course it had no errors! This was first for me, because my code always has errors and I am not very skilled in fixing them.
Next, I began setting up by breadboard. I tried following the steps given by ChatGPT, but was having trouble understanding some of it so I searched online for a picture and used that set-up. It seemed to match the code, so I thought I was all set.
When I got it completed and ran the code, nothing happened with my servo motor, no turning or anything. I adjusted wires, checked connections, etc. and still nothing. I figured I had done something wrong with the motor so I began to focus on that. As I was playing around with it, I noticed it was getting very hot. I started checking things and reconnecting. wires knowing I must have done something wrong as usual.
As I referred back to the diagram I found online, I couldn't find any differences in that compared to my own set-up. I decided to unplug the motor and let it cool off before trying again.
I waited about 15 minutes and reconnected everything and ran the code again. No errors with the code again, but the motor started getting hot very quickly. After making all the adjustments I could think of, I disconnected everything and posted in our class discussion to see if anyone else ran in to this problem. I didn't find any other posts about the motor getting hot, but did read about several classmates concerned about ruining their breadboard.
I asked ChatGPT why the motor may be getting hot and it gave me several recommendations of things to try, including that it may be overloaded, over voltage, over operation, and incorrect connections. I knew it must be incorrect connections so I checked again and followed the steps it provided toward a solution as shown below. I didn't find any miswirings (but that doesn't mean there weren't any) so I decided to call it quits at this point and wait to see if I received any feedback in the discussion board.
Some real-world examples that come to mind when I think about photo resistors is street lights. (Remember the old days of having to go home when the street lights came on?) I also have a night light that goes off during the day time and comes on as it gets dark in the evenings. I never knew what exactly made these things work this way, but now I have learned a bit about photo resistors.
Incorrect Connections
Cause: Miswiring, such as connecting the servo to the wrong pins or incorrect polarities, can lead to excessive current draw.
Solution:
Double-check your connections:
Red wire: Connect to 5V or external power.
Black/Brown wire: Connect to GND.
Yellow/Orange wire: Connect to the signal pin (e.g., pin 9).
Code from ChatGPT:
#include <Servo.h>
// Pin definitions
const int lightSensorPin = A0; // Analog pin connected to the LDR
const int servoPin = 9; // Digital PWM pin connected to the servo
Servo myServo; // Create a Servo object
void setup() {
// Initialize the servo motor
myServo.attach(servoPin);
// Begin Serial communication (optional, for debugging)
Serial.begin(9600);
}
void loop() {
// Read the light intensity (0 to 1023)
int lightValue = analogRead(lightSensorPin);
// Map the light value to a servo angle (0 to 180 degrees)
int servoAngle = map(lightValue, 0, 1023, 0, 180);
// Move the servo to the mapped angle
myServo.write(servoAngle);
// Print the values to the Serial Monitor (optional)
Serial.print("Light Value: ");
Serial.print(lightValue);
Serial.print(" | Servo Angle: ");
Serial.println(servoAngle);
// Small delay for stability
delay(100);
}
Photo of breadboard set-up:

Photo of electronic diagram provided by ChatGPT:
I didn't even know ChatGPT could give me a digram until it asked if I would like one! Yes, please! Of course I wanted one after asking for step-by-step instructions a couple of times and still not having success! I can't say this diagram was actually helpful though, there are several components that I don't even recognize. I am glad to know that I can ask for visuals of other things in the future if needed.



Comments