AVR

Attiny85 LDR and LED – arduino version

In this example we will connect an LDR to an Attiny85, once the value read drops below a certain value we will switch an LED on.

For this example we used the Arduino IDE to write our code. We’ll post a different version using Atmel Studio or equivalent soon.

Schematic

LDR and LED

Code

[c]
int analogPin = 3; //pin 2
int LEDPin = 1; //pin 6
int val = 0;

void setup()
{
pinMode(LEDPin, OUTPUT);
digitalWrite(LEDPin,LOW);
delay(2000);
digitalWrite(LEDPin,HIGH);
}

void loop()
{
val = analogRead(analogPin); // read the input pin
if(val < 200)
{
digitalWrite(LEDPin,HIGH);
delay(200);
}
else
{
digitalWrite(LEDPin,LOW);
}
}
[/c]

Links

Related posts

Programming an Attiny44 using an Arduino

Programming an Attiny85 using an Arduino

Program your attiny2313 with an Arduino