ATTiny Photocell/PWM demo

I wrote a little program and made a circuit for the ATTiny which enables a photocell to control an LED and a motor with pulse width modulation.

Here’s the video:

And here’s the circuit diagram:

photo pwm

And here’s the code for the Arduino IDE:

int val = 0;
int qval = 0;

void setup(){

void loop(){
  val = analogRead(1);
  qval = int(val/4);
  if (val<200){
    qval = 0;

The LED doesn’t seem to ‘fade’ on. Rather, it seems to come on suddenly.

About engineerzero

Once and future engineer.
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s