How to program to read analog values in attiny13a?

Kindly anyone tell me how to program to read analog values in attiny13a using Arduino

You can program an Attiny13a just like any other arduino boards. You can use the analogRead function for reading analog input.

int sensor = 2;
int temp = analogRead(sensor);    //read the analog input
2 Likes

I tried but it doesn’t works

Is there a screenshot if there is a problem?
Maybe check through the serial port to see if the values are being read.
Can you take a screenshot of the serial port to share with us?

Post your code here. What output do you get??

MY CODE

int sensorPin = A1;    // select the input pin for the potentiometer
int alert = 0;// select the pin for the LED


void setup() {
  // declare the ledPin as an OUTPUT:
  Serial.begin(9600);
  pinMode(alert, OUTPUT);
  pinMode(sensorPin, INPUT);
}

void loop() {
  int sensorValue = analogRead((sensorPin));

  
  
  if(sensorValue==0){
    digitalWrite(alert, HIGH);   // turn the LED on (HIGH is the voltage level)
    
    }
  else{
    digitalWrite(alert, LOW);   // turn the LED on (HIGH is the voltage level)
    
    }
  
}

Error

Invalid conversion

Sorry for the late reply. I think the issue is with the microcore. Which version of micocore are you using?

Remove the line Serial.begin(9600); from your code and try once again.