Built-in project · Arduino Uno R3

Ambient light sensor on A0, on an Arduino Uno

A TEMT6000 ambient light sensor on A0: about 5 mV a lux on its 10k, so the brighter the room, the higher the reading, printed twice a second. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $29. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Reading a light sensor with analogRead
  • How a phototransistor turns light into current
  • Why a resistor turns current into a voltage
  • Printing readings to the Serial Monitor
  • Difficulty: Beginner
  • Time: About 10 minutes
  • Board: Arduino Uno R3
  • Parts: 2

How it works

The TEMT6000 is a phototransistor. More light means more current, and a 10k resistor on the module turns that current into a voltage on SIG. It is about 5 mV for each lux.

SIG goes to A0 on the Uno. The sketch reads it with analogRead and prints the number twice a second. Drag the light level in the simulator: a brighter room gives a higher reading.

Parts list

2 parts, plus the jumper wires. They retail for about $29; on Mokxi they're free.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
Ambient light sensor, TEMT6000 pin VCCArduino Uno R3 pin 5V
Ambient light sensor, TEMT6000 pin GNDArduino Uno R3 pin GND
Ambient light sensor, TEMT6000 pin SIGArduino Uno R3 pin A0

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Ambient light sensor on A0.
//
//   module SIG -> A0   VCC -> 5V   GND -> GND
//
// The TEMT6000 is a phototransistor with 10k from SIG to GND: its current
// grows with the light, 50 uA at 100 lux, and the 10k turns it into a
// voltage on A0, about 5 mV a lux.
//
// Drag the light level.

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: Ambient light sensor on A0");
}

void loop() {
  int reading = analogRead(A0);
  Serial.println(reading);
  delay(500);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Runs once. Serial.begin(9600) starts serial output at 9600 baud, then the sketch prints a title line so you know which project is running.

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: Ambient light sensor on A0");
}

loop sketch.ino

Calls analogRead(A0) to get a number from 0 to 1023, prints it with Serial.println, then waits 500 milliseconds with delay. That gives two readings per second.

void loop() {
  int reading = analogRead(A0);
  Serial.println(reading);
  delay(500);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The reading is stuck at 0 This project
    Check that SIG goes to A0, VCC to 5V and GND to GND. Also make sure the simulated light level is above zero.
  • The light reading is always near zero or always maxed out. Ambient light sensor
    Check the signal wire goes to an analog input and the board is powered from the same voltage as your ADC reference. Do not point it at a strong light source.
  • Readings do not match a lux meter. Ambient light sensor
    The signal is a voltage that rises with light. Convert counts to volts, then volts to lux using the sensor's sensitivity. Treat the result as an estimate.
  • Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
    Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected.
  • Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
    Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.