Light Sensor Lamp With ATtiny85, 12V LEDs and L7805 Voltage Regulators

I always liked interactive works of art and I realized that thanks to micro-controllers like Arduino, I can make my art interactive too. So, I started experimenting and I finally have a project finished.

Because the best way to make sure you understand something is to explain it, I decided to make this Instructable.

The lamp has three LEDs that light up one after the other when the light in the room is decreasing. I made the circuit using an Arduino Uno, but I figured this micro-controller is too big for such a lamp, so I looked at an Arduino Mini Pro, when I found a tutorial about how to make such a project with ATtiny85 and decided to make the final circuit with that. I will post all the tutorials I found useful while creating this project in the last step.

I hope you find it useful and if you have any suggestions of improvement, I would love to hear them.

Step 1: What You Need to Create the Circuit?

  • Arduino board
  • ATtiny 85
  • Breadboard
  • Jumper wires
  • 3x 12 V LEDs
  • 3x G4 sockets
  • 3x 1 Ohms resistors
  • Light sensor
  • 1x Electrolytic Decoupling Capacitors - 10uF/25V
  • 1x 10k Ohms resistor
  • 3x L7805 voltage regulator
  • 9V battery
  • 9V battery connector
  • Insulating tape

Step 2: Programming an ATtiny With Arduino

First thing you have to do is upload to the Arduino board the program Arduino ISP that you can find in the examples that come with the Arduino IDE. This program will allow you to use Arduino to program an AVR microcontroller, like ATtiny45 or 85.

For this step you will need the the Arduino, an Attiny85, 12uF/25V capacitor, a small breadboard and jumper wires.

ATtiny85 has 8 pins. If you look at the microchip you'll see it has a dot or a semicircle at one end.
As you look at that end from above, the pin on the left is the Reset pin, next to it is Pin 3, Pin 4 and Ground. On the other side, starting with the pin opposite to Reset are VCC, Pin 2, Pin 1 and Pin 0. See the pins' diagram here.

The capacitor should connect the Arduino ground to the Arduino Reset. See on the capacitor a white line - the pin on that line should be connected to the ground. That is also the shorter pin of the capacitor.

Connect the Arduino (left) to the ATtiny85 (right) as follows:

  • Ground to ground
  • 5V to VCC
  • Pin 10 to Reset
  • Pin 11 to Pin 0
  • Pin 12 to Pin 1
  • Pin 13 to Pin 2

Before uploading to program to the ATtiny, you need to :

  • download the library
  • create a Hardware folder in the Scketchbook folder on your computer
  • paste the library in this folder
  • select from Boards in the Arduino IDE menu, the one that says ATtiny85 (w/ Arduino as ISP)
  • select from Programmer - Arduino as ISP

Now you can upload the desired program.

The first time I tried to upload a program, I got this error: avrdude: usbdev_open(): did not find any usb device "usb". It turned out I didn't select Arduino as ISP as Programmer.
So, if you get an error:

  • Check that the wires are connected correctly
  • Make sure the ISP program is installed on the Arduino
  • Verify that the right Board, Serial port and Programmer are selected.

(not necessarily in this order)

Step 3: The Circuit With Light Sensor and 12V LEDs

The G4 LED socket doesn't always come with wires, and the wires are not appropriate for connection with a breadboard, so when you're trying out the circuit to make sure it works, you'll have to add a jumper wire to the socket's wires. You can just roll one end of the jumper wire together with the end of the socket's wire and put some insulating tape around it.

The L voltage regulator is used so that the circuit, which is powered at 9V, is able to light the 12V LEDs. You will need a regulator for each LED you use. I use three LEDs. I do not know if there is a limit to how many LEDs you can connect like this, either than the limit given by the number of pins, in this case, four because I also have a sensor. Since I do not like even numbers, I have only there LEDs, so threes regulators. It has 3 pins, which are as you look at it from left to right: input, ground and output.

  • Input pin of the regulator connects to the input of the LED and through a 1 Ohm resistor to the pin of ATtiny45
  • Ground pin of the regulator connects to the ground of the LED
  • Output connects to the ground of the circuit

The pins of the 12V LEDs can be either ground or input so you can connect them however you want.

The photo resistor, which will detect how much light is in the room (if you place the sensor on the opposite side from the light source, it will detect the room as dark even if there is light), has two pins that just like those of the LEDs can be either ground or input. Connect on pin to the ground of the circuit and the other pin through a 10k Ohms resistor to a pin of the ATtiny (in this case, pin 3).

The ATtiny is connected through:

  • VCC (opposite the Reset pin) to the source of the circuit
  • ground pin to the ground of the circuit
  • pin 3 to the photo resistor
  • pin 0,1 and 4 with 1 Ohm resistors to the 7805 voltage regulators, which turns the 5V current coming from the ATtiny45 into the 12V current necessary to light the LEDs.

The source of this circuit is a 9V battery.

Step 4: The Code

int Led1 = 1;
int Led2 = 0;
int Led3 = 4; // initialize LED pins
int lightSensorPin = 3; //initialize light sensor pin
int analogValue = 0; // initialize the value that will store the information from the sensor

Void setup (){
pinMode(Led1, OUTPUT);
pinMode(Led2,OUTPUT);
pinMode(Led3,OUTPUT); //set LED pins as outputs
}

void loop(){
analogValue = analogRead(lightSensorPin); // read the value from the sensor
if(analogValue < 50){ //if it's dark or the lights are on
digitalWrite(Led1, HIGH);
digitalWrite(Led2, HIGH);
digitalWrite(Led3, HIGH);
}
else if(analogValue <= 100){ //if it is a little more light, only two are on
digitalWrite(Led1, HIGH);
digitalWrite(Led2, HIGH);
digitalWrite(Led3, LOW);
}
else if(analogValue <= 150){ // if it is even more light, only one LED is on
digitalWrite(Led1, HIGH);
digitalWrite(Led2, LOW);
digitalWrite(Led3, LOW);
}
else { //if there is even more light, all lights are off
digitalWrite(Led1, LOW);
digitalWrite(Led2, LOW);
digitalWrite(Led3, LOW);
}
delay(200); // wait a while before reading the sensor again
}

Before uploading the code to the ATtiny45, verify it with Arduino because if something is wrong it will be easier to adjust.

Some changes will be necessary because the pins on Arduino and those on ATtiny45 do not coincide. For instance, my code will change as follows:

int Led1 = 7;
int Led2 = 8;
int Led3 = 4;
int lightSensorPin = A0;

The rest is the same.
You may add a Serial.begin (9600); in the setup function and a Serial.println (analogValue); in the loop function to check the values the sensor returns in certain situations and you can adjust the values for which the LEDs turn on or off.

The circuit you saw above stays the same except the pins connect on the Arduino to 4,7,8 instead of 0,1,4 for the LEDs and A0 instead of 3 for the light sensor.

Step 5: Resources

Here are a few tutorials I found useful when working on this project:

  • ATtiny:
  • The video that gave me the idea:

  • The video that clarified everything for me:

Step 6: Issues

Out of the three 12V LEDs in the picture only the out most left one works with this circuit.

Since they are all from Diall, so the brand isn't the problem, I guess it is due to the fact that it has a circuit of it's own in the grey part.

It was the only kind of LED I had when I did this and if it worked I didn't think anything of it until I tried another kind of LED.

The video in Resources for Voltage regulator shows a way to connect them with capacitors. I'm thinking that this way it would work with the other LEDs too. I didn't have time to try it, but I will.

In the mean time, if you have any other ideas why the other LEDs do not work and how to fix this, let me know.

Many thanks! :)

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018

    3 Discussions

    0
    None
    SabinaS4DIY Hacks and How Tos

    Reply 3 months ago

    Thank you. :) I'm learning a lot from the Instructables community, so it's nice to be able to give something back. :)