Pages: [1]   Go Down
Author Topic: ATtiny my night light, can't find the bug.  (Read 181 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello folks,
I am new to programming and the arduino, as my first project I wanted to build a small night light, which turned out fine using a Duemilanove, I now want to shrink the night light, using a ATtiny 85. I am using the arduino as a programmer and sketches like blink and fade work just fine, my project however shows nothing, not even the LED turns on and I really don't know why, I got a CR 2032 and the Duemilanove as a power source, both work with blink and fade.

The code:
Code:

 int LDR = 2;  // I also tryed 1 and 3
 int LEDO = 0;
 float fade = 255;
 int off = 0;
 
 
 void setup() {
   pinMode(LDR, INPUT);
   pinMode(LEDO, OUTPUT);
 }
  void loop() {
   int v = analogRead(LDR);

// turns the LED off when their is light  
   if (v > 100) {
     fade = LOW;
     analogWrite(LEDO,fade);
     off = 0;
  
// resets the dimming when the light turns on and off  
   }
   else {
     if (off == 0) {
     fade = 255 ;
     off = 1;

     }

// stops the dimming going into -
     else {
            if ( fade <= 0.5){
       off = 1;
       fade = 0;
       analogWrite(LEDO,fade);

   // slowly fades the LED
   }
       else {
       delay(100);
     analogWrite(LEDO,fade);
     fade = fade-0.1;

   }
   }
   }
  }

I hope this makes some sense, like I said the code works just fine with a real arduino, but I will gladly take any advise !
Can somone help me to port this onto the ATtiny, or at leat tell me what I am doing wrong ?
I added a picture of my setup !



Thank You !


* Untitled Sketch 2_Steckplatine.jpg (339.52 KB, 1293x702 - viewed 33 times.)
« Last Edit: September 29, 2014, 07:05:45 pm by Rivet » Logged

Wahiawa, Hawaii
Online Online
God Member
*****
Karma: 34
Posts: 667
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Depends, what clock speed are the fuse bits set to?  Which attiny software core are you using?
« Last Edit: September 29, 2014, 08:02:55 pm by hiduino » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I burned the bootloader, and selected 8 MHz clock, using the "https://github.com/damellis/attiny" files, or did you mean something else with software core ?

Thank you for the help !
Logged

Wahiawa, Hawaii
Online Online
God Member
*****
Karma: 34
Posts: 667
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The LDR is connected to pin PB2 on the ATtiny85.  This corresponds to analog input A1.

You should try:
Code:
int LDR = A1;
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote from:  link=topic=269800.msg1901815#msg1901815 date=1412047834
The LDR is connected to pin PB2 on the ATtiny85.  This corresponds to analog input A1.


No wonder I was not getting anywhere, Thank You !

Unfortunately my trouble is not over, I had some trouble with the reading of the Photoresistor, so I changed the wiring.
I also used a smaller sketch, to just test basic functionality, I will move back to the full one when everything else is working.

Now the Photoresistor works, the threshold is really weird but, it turn the LED on and off, hoever the LED itself is really dim, barley visible at all, I had to use a lower power LED, to even see that it is working, without darkening my complete room.
This did not happen with the fade sketch, which worked quite nicely, can anyone tell me why it is doing this now ?

New sketch:
Code:
int LDR = A1;
 int LEDO = 0;
   void setup() {
   pinMode(LDR, INPUT);
   pinMode(LEDO, OUTPUT);

 }
 
 void loop()
 {
 
  if (analogRead(LDR) > 50)
        {
   
     analogWrite(LEDO,LOW);
        }
   else       {
     
     analogWrite(LEDO,HIGH);
       
              }
 }


* Night Light_Steckplatine.jpg (342.53 KB, 1293x702 - viewed 3 times.)
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5744
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
analogWrite(LEDO,HIGH);

"HIGH" is defined as "1".

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
analogWrite(LEDO,HIGH);

"HIGH" is defined as "1".


Thank You !
This makes me feel really stupid now ! The LED works like a charm, could be a little brighter with 3 Volts, but that's something I can worry about later. I also changed the resistor from 10 to 22 K Ohm, which fixes the weird threshold.  I hope I will get the full program working now!
Logged

Pages: [1]   Go Up
Jump to: