Analog Input for ATtiny2313/2413

Hello all,

I have built a PCB to program an ATtiny2313/2413 IC with headers for prototyping before PCBs are ordered…

Anyway, my question is, is there a way to get analogRead() to work on either AIN0 or AIN1 or is this just a comparitor that does not allow to read from a photoresistor in my case? I have Attachedthe schematic I have drawn up (I must mention that I am not an expert at either the programming or designing schematics)posted below, and I have my code below.

Any help is appreciated and I thank you in advance. I have tried searching for this all day, and I have tried what others have tried for the ATtiny45/85 but it seems I cannot call analogRead() as I normally do while programming an Arduino.

NOTE: If anything looks messy or disorganized, it is… I have been at this for most of the day.

/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 60; //60 seconds on datasheet       

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  
//blink when ready pause
long unsigned int readyPause = 1000;

//Startup sequence blink... not ideal, but it works
int startSequence[5] = {LOW,HIGH,LOW,HIGH,LOW};

boolean lockLow = true;
boolean takeLowTime;
  
//define pins to be used
int photoResistor = 10; //the Photoresistor pin
int pirPower = 1; //the digital pin that turns the PIR sensor on and off
int pirPin = 4;    //the digital pin connected to the PIR sensor's output
int ledPin = 3;    //the digital pin connected to the LED's (5V board pin on v1.0)
int ledPin2 = 13;    //the second digital pin connected to the LED's (5V board pin on v1.0)
int prSensorValue = 0; //Set the photoresistor value to 0


/////////////////////////////
//SETUP
void setup(){
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(photoResistor, INPUT);
  digitalWrite(pirPin, LOW);
  digitalWrite(pirPower, HIGH);

  //Debugging
  //Serial.begin(9600);

  //give the sensor some time to calibrate
    for(int i = 0; i < calibrationTime; i++){
      //delay(1000);
      }
      for(int i = 0; i < sizeof(startSequence); i++){
      digitalWrite(ledPin, startSequence[i]);
      digitalWrite(ledPin2, startSequence[i]);
      delay(100);
      }
  digitalWrite(ledPin, LOW);
  digitalWrite(ledPin2, LOW);
  }

////////////////////////////
//LOOP
void loop(){
    //debugging
     prSensorValue = analogRead(photoResistor);
     //Serial.println(prSensorValue);
     
     if(prSensorValue > 200){
      //Serial.println("Too Bright, will try again");
      delay(1000);
      return;
     }
//Serial.println("I should not see this"); //debugging only

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       digitalWrite(ledPin2, HIGH);
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){       
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state
       digitalWrite(ledPin2, LOW);

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){  
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;                        
           delay(50);
           }
       }
  }

I doubt it will help, but I also have attached a picture of the project on a breadboard.

Just a comparator. The tX313 family does not have an analog-to-digital converter.

Thank you, I guess I can stop driving myself nuts and design the motion light around an ATtiny45 since I have some of those coming...

I never understand the appeal of 2313/4313. They’re surprisingly expensive for their tiny flash and miserable selection of peripherals.