I've just started working with the ATtiny84 chip and haven't had any issues accessing its digital pins with my sketches. However, I've been unable to figure out how to set up a pin for analogRead() in order to work with a TMP36 temperature sensor.
I've come across various suggestions, including adding this to setup():
DDRA &= ~(1 << PA2); // set pin A2 as input
as well as this post from the forum:
I also looked over the Analog Input Circuitry section starting on page 125 of the Atmel datasheet, but I don't have enough experience to grasp all of the details.
If someone could point me in the right direction for getting a proof-of-concept with the ATtiny84's analog read capabilities, that would be much appreciated.
I've attached a schematic of my circuit as well as my sketch. I'm using the Arduino IDE v1.8.19 with ATTinyCore.
const int analog_TMP36 = A2; // physical pin 11
const int led_green = 7; // physical pin 6
const int led_yellow = 8; // physical pin 5
const int led_red = 9; // physical pin 3
const float baselineTempF = 75.0;
void setup() {
pinMode(analog_TMP36, INPUT);
pinMode(led_green, OUTPUT);
pinMode(led_yellow, OUTPUT);
pinMode(led_red, OUTPUT);
digitalWrite(led_green, LOW);
digitalWrite(led_yellow, LOW);
digitalWrite(led_red, LOW);
}
void loop() {
int TMP36_value = analogRead(analog_TMP36);
float voltage = (TMP36_value / 1024.0) * 5.0;
float tempC = (voltage - 0.5) * 100.0;
float tempF = (tempC * 9.0 / 5.0) + 32.0;
// if tempF between 75 and 85, only green LED on
if ((tempF >= baselineTempF) && (tempF < (baselineTempF + 10.0))) {
digitalWrite(led_green, HIGH);
digitalWrite(led_yellow, LOW);
digitalWrite(led_red, LOW);
// if tempF between 85 and 90, only yellow LED on
} else if ((tempF >= baselineTempF + 10.0) && (tempF < (baselineTempF+15.0))) {
digitalWrite(led_green, LOW);
digitalWrite(led_yellow, HIGH);
digitalWrite(led_red, LOW);
// if tempF 90 or above only red LED on
} else if (tempF >= baselineTempF+15.0) {
digitalWrite(led_green, LOW);
digitalWrite(led_yellow, LOW);
digitalWrite(led_red, HIGH);
// if tempF less than 75, all LEDs off
} else {
digitalWrite(led_green, LOW);
digitalWrite(led_yellow, LOW);
digitalWrite(led_red, LOW);
}
delay(3000);
}
Thanks in advance for any help.



