JBC soldering iron and ATTiny85 digispark -- HELP

LCD is working however analog inputs are not being read or calculated correctly ... responds like digital input


#include <LiquidCrystal_I2C.h>
#include <Wire.h>                  // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
#include <avr/interrupt.h>


LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

#define tempSensor A3//pin2
#define knob A2 //pin3
#define iron 6 //Pin6
//#define LED 5;

int
minTemp = 27,       //Minimum aquired iron tip temp during testing (°C)
maxTemp = 525,      //Maximum aquired iron tip temp during testing (°C)
minADC  = 234,      //Minimum aquired ADC value during minTemp testing
maxADC  = 733,      //Maximum aquired ADC value during minTemp testing

maxPWM    = 255,    //Maximum PWM Power
avgCounts = 5,     //Number of avg samples
lcdInterval = 80,   //LCD refresh rate (miliseconds) 

pwm = 0,            //System Variable
tempRAW = 0,        //System Variable
knobRAW = 0,        //System Variable
counter = 0,        //System Variable
setTemp = 0,        //System Variable
setTempAVG = 0,     //System Variable
currentTempAVG = 0, //System Variable
previousMillis = 0; //System Variable

float 
currentTemp = 0.0,  //System Variable
store = 0.0,        //System Variable
knobStore = 0.0;    //System Variable

void setup(){
  pinMode(tempSensor,INPUT); //Set Temp Sensor pin as INPUT
  pinMode(knob,INPUT);       //Set Potentiometer Knob as INPUT
  pinMode(iron,OUTPUT);      //Set MOSFET PWM pin as OUTPUT
 // pinMode(LED,OUTPUT);       //Set LED Status pin as OUTPUT
  Wire.begin() ;
  lcd.backlight();
  lcd.init();
  lcd.clear();
  lcd.setCursor(0,1);lcd.print("PRESET T: ");  
  lcd.setCursor(0,0);lcd.print("ACTUAL T:"); 
}

void loop(){
  //--------Gather Sensor Data--------//
  knobRAW = analogRead(knob); //Get analog value of Potentiometer
  setTemp = map(knobRAW,0,1023,minTemp,maxTemp);  //Scale pot analog value into temp unit

  tempRAW = analogRead(tempSensor);  //Get analog value of temp sensor adjust for opamp-2.5V + temp mv
  currentTemp = map(analogRead(tempSensor),minADC,maxADC,minTemp,maxTemp);  //Scale raw analog temp values as actual temp units
  
  //--------Get Average of Temp Sensor and Knob--------//
  if(counter<avgCounts){  //Sum up temp and knob data samples
    store = store+currentTemp;
    knobStore = knobStore+setTemp;
    counter++;
  }
  else{
    currentTempAVG = (store/avgCounts)-1;  //Get temp mean (average)
    setTempAVG = (knobStore/avgCounts);  //Get knob - set temp mean (average)
    knobStore=0;  //Reset storage variable
    store=0;      //Reset storage variable
    counter=0;    //Reset storage variable
  }
  
  //--------PWM Soldering Iron Power Control--------//
  if(analogRead(knob)==0){  //Turn off iron when knob as at its lowest (iron shutdown)
    //digitalWrite(LED,LOW);
    pwm=0;
  }
  else if(currentTemp<=setTemp){  //Turn on iron when iron temp is lower than preset temp
   // digitalWrite(LED,HIGH);
    pwm=maxPWM;
  }
  else{  //Turn off iron when iron temp is higher than preset temp
    //digitalWrite(LED,LOW);
    pwm=0;
  }
  analogWrite(iron,pwm);  //Apply the aquired PWM value from the three cases above

  //--------Display Data--------//
  unsigned long currentMillis = millis(); //Use and aquire millis function instead of using delay
  if (currentMillis - previousMillis >= lcdInterval){ //LCD will only display new data ever n milisec intervals
    previousMillis = currentMillis;
 
    if(analogRead(knob)==0){
      lcd.setCursor(10,1);lcd.print("OFF  ");
    }
    else{
      lcd.setCursor(10,1);lcd.print(setTempAVG,1);lcd.print((char)223);lcd.print("C ");
    }
    
    if(currentTemp<minTemp){
      lcd.setCursor(10,0);lcd.print("COOL ");
    }
    else{
      lcd.setCursor(10,0);lcd.print(currentTempAVG,1);lcd.print((char)223);lcd.print("C ");
    }   
  } 
}

Have you tried defining your analog pin without the "a" such as:

int analogPin = 0;

Post an annotated schematic, I see a potential conflict with the I2C configuration.

i2c works well tho

How about the temperature sensor? It appears they are sharing a pin which is a NoNo.

how do I do that ... Sorry, i'm 69yo

No problem, I did that when I was about 74. I downloaded KiCad and spent some time with it. It is definitely not a 1 night learning experience.

Posting an annotated schematic showing exactly how you have wired it helps us help you. By showing all connections, power, ground and power sources you will save a lot of clarifying questions and time for all of us. Be sure to note any logic wires over 10/25 inches/cm in length. Post links to technical information on the hardware items including the motors, shield, and Arduino. This should include all component values or model numbers and details of all power supplies used (which could be USB power for example). Posting the code following forum guidelines using code tags will also help. With this information we should be able to answer your question accurately. "How to get the best from this forum".

If you don't understand what a schematic is, please Google to find out. It is not the same thing as a wiring diagram. Hand-drawn is OK. Some bright, sharp photos of the circuit may also be useful.

The thing I see is many of the users do not want to draw schematics yet a large portion of there problems are in the connections, power etc. It appears they spend about a week or so with lots of questions and then maybe, give up, and some get lucky. It is amazing how many problems you find when doing a real labeled schematic including Technical links. That schematic makes them look like a pro. It appears to me that most of the time when a proper schematic is posted the solution is usually within day or so. Good schematic capture software can be gotten for the downloading. Months later a wire comes off, looking at the schematic and putting it back saves lots of headaches.

What is a schematic What Is a Schematic Diagram?
https://learn.sparkfun.com/tutorials/how-to-read-a-schematic/all
HOW to READ a Schematic: https://www.youtube.com/watch?v=9cps7Q_IrX0&t=15s

KiCad: There are many out there and you will find just like color different people like different colors, some blue, red, ..etc. CAD (Computer Aided Design) programs are like that. You will need to learn a schematic capture program that will work for you.

Draw with pen and paper :wink: We should be able to see every connection and get a clear idea of power/gnd.
Take a photo and upload here (you can use drag-and-drop) in a new reply.

Are you using this board (Fig-1)? What to do with the soldering iron here? Is this JBC refers to thr brand of the soldering Iron?
DigisparkAttiny85Board