Control an LED with the TEMT6000 ambient light sensor

FunduinoPublished on

Bei Dunkelheit eine LED automatisch einschalten

Wird es dunkel, geht die LED an – wird es hell, geht sie wieder aus. Genau so arbeiten Dämmerungsschalter an Hauseingängen und Straßenlaternen.

In dieser Anleitung liest du den Helligkeitssensor TEMT6000 am analogen Eingang aus, ermittelst im seriellen Monitor deinen Schwellenwert und schaltest damit eine LED.

The TEMT6000 light sensor on its circuit board

You need this

TEMT6000 light sensor - analog, 0-1000 lux, XH2.54 connector TEMT6000 light sensor - analog, 0-1000 lux, XH2.54 connector 4,59 € *Item no. F23108989About the product — TEMT6000 light sensor - analog, 0-1000 lux, XH2.54 connector
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
LED 5 mm - 100 Pieces, 5 Colors, 2 V LED 5 mm - 100 Pieces, 5 Colors, 2 V 1,97 € *Item no. F23107316About the product — LED 5 mm - 100 Pieces, 5 Colors, 2 V
Resistor Assortment - 8 Values, 10 Pieces Each, 10 Ohms to 100 kOhms, ±5% Resistor Assortment - 8 Values, 10 Pieces Each, 10 Ohms to 100 kOhms, ±5% 1,30 € *Item no. F23106603About the product — Resistor Assortment - 8 Values, 10 Pieces Each, 10 Ohms to 100 kOhms, ±5%
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
Breadboard cables male-female - 40 pieces, 20 cm Breadboard cables male-female - 40 pieces, 20 cm 1,74 € *Item no. FUN-1010554About the product — Breadboard cables male-female - 40 pieces, 20 cm

All 6 parts together 22,46 € *

* All prices include statutory VAT, plus shipping costs.

The TEMT6000 light sensor

The TEMT6000 brightness sensor switches an LED: when it gets dark, the LED turns on; when it gets bright again, it turns off.

The sensor outputs a voltage that increases with brightness. The microcontroller measures it at analog input A0 and converts it to a value between 0 and 1023.

The TEMT6000 light sensor on its circuit board

The circuit diagram

  • TEMT6000 signal to A0
  • LED via a 220 Ω resistor to Pin 8
  • Sensor VCC and GND to 5V and GND on the microcontroller respectively

The sketch runs on the NANO and on the UNO R3.

Circuit diagram: TEMT6000 to A0, LED with series resistor to pin 8

The program

You can see the measured brightness values in the serial monitor. Cover the sensor and watch the value decrease. Enter the value at which the LED should light up in the SchwelleDunkelheit variable.

Once you’ve found the right value, you can comment out the serial monitor output and the delay.

The serial monitor displays the measured brightness values
Switch an LED with the TEMT6000
int TEMT6000 = A0;
int LED = 8;
int DarknessThreshold = 30;
void setup()
{
 Serial.begin(9600);
 pinMode(LED, OUTPUT);
}
void loop()
{
  // Comment out lines 15 and 16
  // once the desired value for "darkness" has been set
  Serial.println("TEMT6000 reading: " + String(analogRead(TEMT6000)));
  delay(500);
  if (analogRead(TEMT6000) < DarknessThreshold)
  {
    digitalWrite(LED, HIGH);
  }
  else digitalWrite(LED, LOW);
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.