Ambient light sensor TEMT600

TEMT6000 is ambient light sensor. It is sensitive to visible light much like human eye and has peak sensitivity at 570nm.

Visible spectrum is 390 – 700 nm.

TEMT6000

The sensor can handle voltages from 3.3v and 5v. The sensor has been designed into a voltage divider circuit. To read that voltage connect SIG pin to any analog to digital conversion pin on microcontroller.

Ambient light sensor for control of display backlight dimming in LCD displays and keypad backlighting of mobile devices and in industrial on/off-lighting operation.

TEMT6000 measures illuminance (measured in lux (lx). It is a measure of the total quantity of visible light emitted by a source (referred to as luminous flux, measured in lumens (lm) divided by an area in square meters. 1 lx = 1lm/m2.

Image: Sparkfun

To get the brightness the sensor measures, we then simply have to measure the voltage on the SIG (also called OUT) pin using the Analog To Digital Sensor and convert those voltage measurements to illuminance values in lux.

To get the illuminance in lux, we first need to convert the measured voltage to the current flowing across the TEMT6000 sensor. This current is also equal to the current flowing across the 10kΩ resistor in the voltage divider circuit, which is I = adc_value/10000kΩ.

Volts = analogRead() * 0.5 / 1024.0

Amps = volts / 10000.0

microamps = amps / 1000000

lux = microamps *2.0

float lux = analogRead(TEMT6000_PIN) * 0.9765625; // 1000 / 1024 = 0.9765625

The datasheet for the TEMT6000 specifies a proportional correlation between current and illuminance: Every 2 µA of current correlates to 1 lx in the illuminance.

Code

I’m using Visual Studio Code + PlatformIO. Arduino Uno

#include <Arduino.h>

#define TEMT6000_PIN A0 

void setup() {
  pinMode(TEMT6000_PIN,  INPUT);    
  Serial.begin(9600);
}

void loop() {
  float reading = analogRead(TEMT6000_PIN); //Read light level
  Serial.print("Reading: "); Serial.println(reading);

  double volts = reading * 5.0 / 1024.0;
  Serial.print("Volts: "); Serial.println(volts);

/*
  In the case of 8-bit AVR Arduino boards, 
  the float type is 32-bits 
  which makes the limit 6 or 7 digits.

  double amps = volts / 10000.0; // = 0
  Serial.print("Amps: ");Serial.println(amps);

  double microamps = amps / 1000000; // = 0
  Serial.print("Microamps: ");Serial.println(microamps);

  double lux = microamps * 2.0; // = 0
  Serial.print("Lux: "); Serial.println(lux); 
*/
  Serial.print("Lux: ");
  float lux2 = analogRead(TEMT6000_PIN) * 0.9765625; // 1000 / 1024 = 0.9765625
  Serial.println(lux2);
  Serial.println("");

  delay(1000);
}

Demo:

Links:

Translations:

  • illuminance (lux = lumens/m2) – valgustatus
  • luminous – helendav, valgusküllane
  • luminous flux (lumens) – valgusvoog
  • luminous intenity (candela) – valgustugevus
  • luminance (candela m3) – heledus, eredus
Fotomeetria

Electronic "paper crane" or orizuru

I had a bunch of smd LEDs and no idea what to do with them. But then, when I had watched all these events in Hong Kong. And when I had seen how they make this paper cranes I decided to make my own version.

It use ATtiny13 AVR microcontroller and software PWM to slowly fade wings on and off.

First i made paper crane and the rest is copy-paste basic forms. The basic shapes are actually simple and flat. The most difficult part is soldering SMD components.

All electronics and batterys (4 x AA) are in the bottom wooden box.

Schematic

Electronic paper crane schematic
Soldered circuit

Code

I used Arduino IDE to program ATtiny13.

/**
 * 
 * Hardware  ATtiny13
 * Software  Arduino IDE 1.8.10, Arduino as ISP, MicroCore
 * Clock     9.6Mhz
 * 
 * Author    Tauno Erik
 * Date      29.11.2019
 * 
 * 
 */
 
 /*                        ATtiny13 pins
  *  
  * Reset-ADC0-5/A0-PCINT5-PB5-| U |-VCC
  *  CLKI-ADC3-3/A3-PCINT3-PB3-|   |-PB2-PCINT2-2/A1-SCK-ADC1
  *       ADC2-4/A2-PCINT4-PB4-|   |-PB1-PCINT1-1-MISO-OC0B-INT0
  *                        GND-|___|-PB0-PCINT0-0-MOSI-OC0A
  */

//#define F_CPU 9.6E6L 

#include <avr/io.h>
#include <util/delay.h>

#define WING_UPPER    PB2
#define WING_MIDDLE   PB3
#define WING_LOWER    PB0
#define BODY          PB4

#define FADE_TIME     1024
#define PAUSE         10

void set_pin_high(byte pin) {
  PORTB |= (1 << pin); // or PORTB |= _BV(pin);
}

void set_pin_low(byte pin) {
  PORTB &= ~(1 << pin); // or PORTB &= ~_BV(pin);
}


void fade_in(int ftime, byte pin) {
    unsigned int d_max = ftime;
    
    for (int i = 1; i < ftime; i++) {
        set_pin_high(pin); 
        _delay_loop_2(i);

        set_pin_low(pin);
        _delay_loop_2(d_max - i); // 1 
    }
    
    set_pin_high(pin);
}


void fade_out(int ftime, byte pin) {
    unsigned int d_max = ftime;
    
    for (int i = 1; i < ftime; i++) {
      set_pin_low(pin);
      _delay_loop_2(i); 
        
      set_pin_high(pin); 
      _delay_loop_2(d_max - i);  // 1  
    }
    
    set_pin_low(pin);
}


void fade_out_in(int ftime, byte pin_out, byte pin_in) {
    unsigned int d_max = ftime;
    
    for (int i = 1; i < ftime; i++) {
        // out:on in:off
        set_pin_high(pin_out);
        set_pin_low(pin_in);
        _delay_loop_2(d_max - i);

        // out:off  in:on
        set_pin_low(pin_out);
        set_pin_high(pin_in);
        _delay_loop_2(i);  
    }

    set_pin_low(pin_out);
}


int main(void)
{
    /* setup */        
        // set pins as OUTPUT
        DDRB |= _BV(WING_UPPER);     // sama mis DDRB |= (1 << PB2);
        DDRB |= _BV(WING_MIDDLE);
        DDRB |= _BV(WING_LOWER);
        DDRB |= _BV(BODY);
 
        // set pin to HIGH
        PORTB |= _BV(WING_UPPER);
        PORTB |= _BV(WING_MIDDLE);
        PORTB |= _BV(WING_LOWER); */

        /* Fade in Body */
        delay(500);
        fade_in(FADE_TIME, BODY);    

        byte first_time = 1;
     /* loop */
        while (1) {
            if(first_time){
              fade_in(FADE_TIME, WING_UPPER);
              _delay_loop_2(PAUSE);
              first_time = 0;
            } else {
              fade_out_in(FADE_TIME, WING_UPPER, WING_MIDDLE);
              _delay_loop_2(PAUSE);
              fade_out_in(FADE_TIME, WING_MIDDLE, WING_LOWER);
              _delay_loop_2(PAUSE);
              fade_out_in(FADE_TIME, WING_LOWER, WING_MIDDLE);
              _delay_loop_2(PAUSE);
              fade_out_in(FADE_TIME, WING_MIDDLE, WING_UPPER);
              _delay_loop_2(PAUSE);
            }
        }
        return 0;
}

Links

Shared