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(){
  pinMode(1,OUTPUT);
  digitalWrite(1,LOW);
  
  pinMode(0,OUTPUT);
  digitalWrite(0,LOW);  
}

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

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

Advertisements

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:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s