This lesson uses: Arduino UNO R3 board, TinkerBlock TK20 Ambient Light module, jumper wires (or breadboard). Learn to read light with analog input; outcome: serial shows light value (0–1023)—cover light and value drops, shine light and value rises.
1. Wiring
Connect TK20 Ambient Light to Arduino:
- GND → Arduino GND
- VCC → Arduino 5V
- SIGNAL → Arduino A0
- NC leave unconnected

2. New sketch
- Arduino IDE: File → New (or Ctrl/Cmd + N) to create a blank sketch
- Confirm board and port are selected (same as Lesson 01)
- Type the code below into the default
setup()andloop()yourself
3. Program structure
Same as last lesson: two fixed blocks setup() and loop().
setup(): Start the serial port (to see values on the computer); runs once.loop(): Keep repeating “read A0 → store in variable → print to serial → short delay”.
After the code runs, cover the sensor or shine a light and the serial light value will change.
4. Code to write
Type the code below line by line into setup() and loop() (do not copy-paste; typing it yourself helps you remember):
#define LIGHT_PIN A0 // Light sensor on A0
void setup() {
Serial.begin(9600); // Start serial, baud 9600
Serial.println("Ambient light sensor program started");
}
void loop() {
int val = analogRead(LIGHT_PIN); // Read A0, store in val (0-1023)
Serial.print("Light: ");
Serial.println(val); // Print val (higher = brighter)
delay(200); // 200 ms
}Program notes
Overall idea: A0 reads the TK20's phototransistor, whose current rises with light; a 4.7 kΩ resistor on the block turns that current into a voltage; ADC 0–1023, higher means brighter. Print to serial for observation.
| Code | In this lesson |
|---|---|
analogRead(LIGHT_PIN) | Read A0; 0=darkest, 1023=brightest |
int val | Holds raw light value |
Serial.println(val) | Print to serial to compare cover vs shine |
5. Hands-on
- After entering the code, click Verify (✓) to compile
- Click Upload (→) to upload to the board
- Open Serial Monitor (Tools → Serial Monitor, baud 9600)
- Watch the Serial Monitor:
- Cover the TK20 module: light value decreases
- Shine a phone flashlight on it: light value increases
- In a lit room: usually well under half the scale, roughly 50–250; a phone flashlight close up reads near the top
- Try different lighting and observe the values
Expected result:
Serial monitor shows:
Ambient light sensor program started
Light: 142
Light: 139
Light: 3
Light: 941
Light: 140
...
Note: TK27 Analog MIC Sensor is analog too, but it reads differently: its output rests at a level and swings around it when a loud sound arrives, so a single reading says little. Its handbook shows how to read the swing.
Proceed to Lesson 14.
6. Common issues
| Symptom | What to do |
|---|---|
| Serial monitor shows nothing | Ensure Serial.begin(9600) is in setup(); set Serial Monitor baud to 9600 |
| Light value does not change | Check TK20 wiring GND→GND, VCC→5V, SIGNAL→A0; try covering or shining light on the module |
Edit this page — content/guides/tinkerblock-workshop/13-ambient-light-sensor.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Ambient Light Sensor
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.