How to add sensor code to the following program

Hi, i believe i am on the right platform and i hope that this platform provides me with the solution to my problem.
After several tries, i was successful with reading stable/constant or unchanged battery voltage using internal voltage reference of 1.1v, now the issue i face is that i can read stable sensor voltage only with arduino UNO but the moment i shift to attiny44A IC the same code readings does not work, could you please let me know how can i read my sensor voltage accurately? or do i need additional voltage divider (my sensor goes directly connected to Analog pin and GND pin).

NOTE: I am using Arduino for prototyping purpose, mainly i will be using attiny44A IC. I am using attinyCore library

 void setup(){

void loop() {  
  //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference
  ADMUX |= B11000000;   
  //We read A1 (MUX0) for battery voltage
  ADMUX |= B00000001;       
    //We read A0 for sensor voltage
  ADMUX |= B00000000;                // for my sensor 
  // Start AD conversion
  ADCSRA |= B11000000;
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
  float val = ADCL | (ADCH << 8);
  val = val * 5.7; // Using 4.7k and 1k voltage divider

Something like the code below must workout but unfortunately it does not help!

 int sensorValue = analogRead(A0);
  voltage =  ((sensorValue/ val) * 1023.); 
  Serial.println("voltage:  ");
  if (voltage<=215){
  digitalWrite (led, HIGH);
  else if (voltage>=215){
  digitalWrite (led, LOW);

my code changes for attiny are:

ADMUX |= B10000000;   // internal 1.1V refference
  //We read A1 (MUX0)
  ADMUX = 0b00000001;   //PA1   
  // Start AD conversion
  ADCSRA |= (1<<ADSC);
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
 val = ADCL | (ADCH << 8);

The code works alright with arduino but when i transfer it to attiny it does not work properly for instance, arduino reads 2000 at 3v whereas, attiny does not read 2000 at 3-3.4V.

Unfortunately not.
This forum is neither for Arduino nor for attiny controllers but only Particle devices - which are currently based on STM32, nrf52840 or rtl872x controllers.
Hence none of the heavily hardware dependent calls in your code fall into the realm of this forum.

1 Like

Hi, but i saw some people posted about arduino projects and getting their answers.

The high level programming on both platforms is similar enough to assist with that kind of request. But your code above is rather HW specific and low level and the inner workings of the attiny ADCs is definitely hardware centered.

Also there are plenty members who also have the knowledge to assist even with off-topic requests.
However, this is not the focus of this forum. Dedicated Arduino and/or Atmega forums may be better suited for this kind of question.