Build it step by step
0 of 8 doneFit the shield
Press it down on the Uno, pins aligned.
Plug in the servo
Brown to G, red to V, orange to S on D9.
Build the light divider
LDR and 10 kilohm on a breadboard, output to A0.
Wire the knob
Outer legs to V and G, wiper to A1.
Wire the button
D2 signal pin to ground.
Upload the sketch
Open the serial monitor at 9600.
Turn the knob
The servo follows and the table changes.
Cover the LDR
The first column changes.
How do you build a plug-in sensor tray?
A sensor shield on an Uno brings out clean 5 V and ground pins so a light sensor, a knob, a button and a servo can be read and driven from one table on the serial monitor. You need Arduino Uno R3, Sensor shield V5 for Uno, LDR Photoresistor, Resistor 10 kΩ, Potentiometer 10 kΩ, Tactile push button 6 mm, SG90 Micro Servo, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 9
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- InterfacesBuy
- SensorsBuy
- PassivesBuyResistor 10 kΩ × 1
- PassivesBuy
- SwitchesBuy
- Motors & ActuatorsBuySG90 Micro Servo × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LDR leg 1 | Shield A0 V pin (5 V) | Top of the light divider |
| LDR leg 2 and 10 kilohm resistor leg 1 | Shield A0 S pin | Divider output to the analog input |
| 10 kilohm resistor leg 2 | Shield A0 G pin (ground) | Bottom of the divider |
| Pot outer legs | Shield A1 V and G pins | Knob across 5 V and ground |
| Pot wiper (middle) | Shield A1 S pin | Analog knob signal |
| Button | Shield D2 S pin and the G pin beside it | Pressed pulls D2 to ground |
| Servo plug (brown, red, orange) | Shield D9 G, V, S pins | Servo plugs straight into the header |
Code
A sensor shield is a board that plugs onto an Uno and repeats every pin as a row of three: signal, 5 volts and ground. It makes it easy to plug in servos and many sensor modules, because the three pins match the standard servo and sensor plugs. For parts that do not come with a plug, such as a bare LDR, a resistor or a pot, put them on a small breadboard and run jumper wires to the shield pins. This build reads four things at once: a light sensor, a knob, a button and a servo. The LDR and the 10 kilohm resistor form a divider on A0. The pot is read on A1 and its value is mapped to a servo angle. The button on D2 uses the internal pull-up, so pressing it reads low, and the sketch prints one tidy table row four times a second. Check the shield's power jumper: the servo draws current from the shield's V pins, so use the position that matches your supply, and keep an eye on the servo getting stuck, since a stalled servo can pull a lot of current and reset the board. Powering from USB is fine for a small unloaded servo.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Servo.h>
const int LDR_PIN = A0, POT_PIN = A1, BTN_PIN = 2, SERVO_PIN = 9;
Servo arm;
unsigned long lastPrint = 0;
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP); // button to ground, pressed reads LOW
arm.attach(SERVO_PIN);
Serial.begin(9600);
Serial.println("LDR POT BTN SERVO");
}
void loop() {
int ldr = analogRead(LDR_PIN); // 0 to 1023, higher means brighter with this divider
int pot = analogRead(POT_PIN);
bool pressed = (digitalRead(BTN_PIN) == LOW);
int angle = map(pot, 0, 1023, 0, 180);
arm.write(angle);
if (millis() - lastPrint >= 250) {
lastPrint = millis();
char line[40];
snprintf(line, sizeof(line), "%4d %4d %3d %5d", ldr, pot, pressed ? 1 : 0, angle);
Serial.println(line);
}
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
LDR POT BTN SERVO 513 513 0 90 512 512 0 90 512 513 0 90 512 512 0 90 513 513 0 90
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Open the serial monitor | A table of four columns updates four times a second |
| Turn the pot | POT 0 to 1023 and the servo sweeps 0 to 180 degrees |
| Press the button | BTN shows 1 |
| Cover the LDR | LDR value falls |
| Release the button | BTN shows 0 |
If it does not work
Servo twitches
The USB supply sags, power it from the Vin jack or a separate 5 V supply.
LDR value never changes
Check the divider is on A0 and the resistor goes to ground.
Button reads 1 all the time
Check the wiring to ground and the pull-up in the sketch.
Servo does not move
Check the plug direction and that D9 is the signal pin.
Upload fails
Remove the shield briefly and try again.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the plug-in sensor tray?
Arduino Uno R3, Sensor shield V5 for Uno, LDR Photoresistor, Resistor 10 kΩ, Potentiometer 10 kΩ, Tactile push button 6 mm, SG90 Micro Servo, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the plug-in sensor tray take to build?
About 120 minutes for a beginner maker, in 8 steps.
How do I know the plug-in sensor tray works?
Open the serial monitor: A table of four columns updates four times a second. Turn the pot: POT 0 to 1023 and the servo sweeps 0 to 180 degrees. Press the button: BTN shows 1.
Servo twitches: what should I check?
The USB supply sags, power it from the Vin jack or a separate 5 V supply.
LDR value never changes: what should I check?
Check the divider is on A0 and the resistor goes to ground.
Button reads 1 all the time: what should I check?
Check the wiring to ground and the pull-up in the sketch.
Servo does not move: what should I check?
Check the plug direction and that D9 is the signal pin.
