Introduction: 5 Simple ATtiny85 LDR Scripts

Picture of 5 Simple ATtiny85 LDR Scripts

For a short intro course "Smart Textiles" at the school in Rotterdam I made these 5 scripts. The students who aren't supposed to be able to program can choose one of the LDR variations for their textile design. They solder the components together and use this "smart" microcontroller to add some interactivity to some textile item they made on the sewing machine, can be a top, vest, trousers, or something completely different, interactive textile product, something for domotics...

The parts used:

  • ATtiny85 (using the ARDUINO programming environment)
  • chip holder
  • battery holder for a 3V coin cell battery
  • 2 bright LED's
  • LDR
  • 2K resistor
  • some wires


  • soldering device
  • USBASP or this TINY programmer (or comparable) - in ARDUINO, use the SHIFT U to program.

By the way, i print my coin cell battery holders myself:

You have to add the metal wires (eg from resistor, or LED legs) inside the holes and push the coin cell battery in.

Step 1: Some Prep and the Course

Picture of Some Prep and the Course

After an intro soldering and sewing, the students learn what a circuit is, they make a soft button in a top or vest.

They use this instructable for the soft button:

Then we do one ARDUINO night, experimenting with LED's and the Light Depending Resistor, LDR as a prototype for a sensor.

After one night you cannot program (the students can learn programming in other courses).

The goal of this course is to design on two levels: sewing and interactivity (electronics). It is meant for fashion students, but also architecture, product design, illustration, animation, advertising etc.

Powerpoints can be found here (so you can give this course yourself :)

This instructable is the fifth night...the sixth is finishing the prototype design.

For the textile design, the decision to either hide or show the wires is important. You can do fun things with wires!

Step 2: Soldering

Picture of Soldering

The students followed the pictures. They know about circuits and had practiced with the LDR-resistor combination during one evening with the ARDUINO.

  • Solder to the chip holder, mind the "North" sign on this holder.
  • First the resistor to pin 8 (V) and PB2, then the LDR to PB2 and pin 4 (GND).
  • The battery holder to pin 8 (plus) and pin 4 (GND)
  • the short legs of the LED's to pin 4 (GND)
  • the long legs to pin 5 and 6, PB1 and PB2.
  • (You could add a switch.)

If all is soldered, insert the programmed ATtiny85.

You have to put the speed on 8MHz with AVRdude setting the fuses:

avrdude -c USBASP -P usb -p t85 -U hfuse:w:0xdf:m -U lfuse:w:0xe2:m

Step 3: Scripts

There are two scripts included.

You can also find them here:

The first script contains 4 subscripts, which you can choose in this line:

int scriptNumber = 2;//for the second script

  1. The first script is basic: LDR high or low value: either LED1 or LED2 is on
  2. The second script sends a bleep (i am alive) and has an LED shining on low light value.
  3. The third script makes alternate glowes slow or fast, depending on the light value
  4. The fourth script blinks both when low light, otherwise alternates

The second script is slightly more advanced, using the Watchdogtimer.

This script sends your name (or some word) in Morse code, and independently glows the second LED.

(Change "Beam" to your name :-)! )

Because the memory is quickly filled some unused characters are commented out, if your name contains these letters, please uncomment. Also names that are too long can give this problem. This is apparently about the "working memory", not the flash memory.

In the interrupt code, you see the 64 and the 17. These are counters used as interval timers for the MORSE code and the glow. You can make these intervals faster or slower by changing these numbers.

(For the Morse code I used some script I found on the internet and revised it, also the Watchdog routine is from some nice programmer putting her or his script available for everyone.)

Step 4: Sewing: Finishing the Interactive Design

Picture of Sewing: Finishing the Interactive Design

By making the wires the length you need, you can place the LED's and the LDR where you want in a top or a vest, or some other item which will have some interactivity with this circuit.

The coin cell will hold for a few hours...

I use these script too!

For example in my Alien Sock Shop during the 2016 e-textile summercamp


chuckr44 (author)2017-04-18

How many LEDs could this ATTTiny support? I want to program it to turn green lights on like fireflies, with about 4 LEDs in a jar.

AndreasO1 (author)2017-03-08

This is great! I like it!

About This Instructable




Bio: Happiness is invisible? Then you cannot sell it? You cannot copy it nor like it:-) You have to arrive there yourself??? But i am just ... More »
More by contrechoc:E-chopsticksPersonalized Ledstrip5 Simple ATtiny85 LDR Scripts
Add instructable to: