Errors in code

#include <SoftPWM.h>
#include <SoftPWM_timer.h>



#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
float mySensVals[5] ;
float sumv = 0;
float sumi = 0;
float v_previous = 0;
float i_previous = 0;
float duty_cycle = 0;
float batteryVolts = 0;
// set up the LCD's number of columns previous_batteryVolts = 0;
float batteryAmps = 0;
float previous_batteryAmps = 0;
float efficiency = 0;
float batteryWatts = 0;
float maxwatts = 0;
float barwatts = 0;
float Voc = 0;
float Isc = 0;
float tol = .0001;
char tmp[25];
int red_led = 1;
int yellow_led = 2;
int green_led = 8;
int MOSFETPin = 3; // MOSFET connected to digital pin 9
int32_t frequency = 20000; //frequency (in Hz)
float error = .0001;
// the setup routine runs once when you press reset:
void setup() {
  and rows;
  pinMode(red_led, OUTPUT);
  pinMode(yellow_led, OUTPUT);
  pinMode(green_led, OUTPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600); // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD.

  lcd.print("Welcome"); //initialize all timers except for 0, to save time keeping functions
  IntTimersSafe();
  //sets the frequency for the specified pin
  bool success = SetPinFrequencySafe(MOSFETPin, frequency);
  //if the pin frequency was set successfully, turn pin 13 on
  if (success) {
    pinMode(13, OUTPUT);
    digitalWrite(13, HIGH);
  }
}
// the loop routine runs over and over again forever:
void loop()
{
  //this loop calculates the current and voltage average
  for (int i = 0; i <= 4; i++)
  {
    float sensorValue_current = analogRead(A3);
    float voltage_current = (sensorValue_current * 5 / 1023);
    float cur = (610 / 39) * (voltage_current - 3.7375); //using the no 3 sensor
    mySensVals[i] = cur;
    sumi = sumi + mySensVals[i];
    float sensorValue_voltage = analogRead(A1);
    float voltage0 = (sensorValue_voltage * 5 / 1023) * 67.66;
    mySensVals[i] = voltage0;
    sumv = sumv + mySensVals[i];
    delay(200);
  }
  // print out the value of current:
  float current_next = sumi / 5;
  Serial.println("Current: \t");
  Serial.println(current_next);
  delay(1000);
  // print out the value of current:
  float voltage_next = sumv / 5;
  Serial.println("voltage: \t");
  Serial.println(voltage_next); delay(1000); // incremental conductance algorithm starts float dV=voltage_next-v_previous;

  float dI = current_next - i_previous; if (dV == 0)
  { if (dI == 0)
    { voltage_next = voltage_next;
      current_next = current_next;
      Serial.println("Pmax is reached:");
      float P = voltage_next * current_next;
      Serial.println(P);
      delay(1000);
    }
    else if (dI > 0) // that means you have to make dI=0 decrease I,decraese duty cycle
    {
      duty_cycle = duty_cycle + 1;
      pwmWrite(MOSFETPin, duty_cycle);
    }
    else if (dI < 0) // that means you have to increase I to make dI=0;increase duty cycle
    {
      duty_cycle = duty_cycle - 1;
      pwmWrite(MOSFETPin, duty_cycle);
    }
  }
  else
  {
    if (dI / dV + (current_next / voltage_next) <= error)
    {
      voltage_next = voltage_next;
      current_next = current_next;
      Serial.println("Pmax is reached:");
      float P = voltage_next * current_next;
      Serial.println(P);
      delay(1000);
    }
    else if (dI / dV < -(current_next / voltage_next))
    { duty_cycle = duty_cycle - 1;
      pwmWrite(MOSFETPin, duty_cycle);
    }
    else
    { duty_cycle = duty_cycle + 1;
      pwmWrite(MOSFETPin, duty_cycle);
    }
  }
  Serial.println("after changing the duty cycle");
  Serial.println("voltage");
  Serial.println(voltage_next);
  float P = voltage_next * current_next;
  Serial.println("Power");
  Serial.println(P);


  v_previous = voltage_next;
  i_previous = current_next;
  sumv = 0;
  sumi = 0;
  batteryVolts = analogRead(A2) * 25.0 / 1023 - 3.3; //get the battery volts
  Serial.println("batteryVolts \t");
  Serial.println(batteryVolts);
  //batteryVolts = (batteryVolts + previous_batteryVolts) / 2; //average the volts
  //Serial.println("batteryVolts \t");
  //Serial.println(batteryVolts);
  previous_batteryVolts = batteryVolts;
  batteryAmps = (514 - analogRead(A5)) * 27.03 / 1023; //get the panelAmps
  Serial.println("batteryAmps \t");
  Serial.println(batteryAmps);
  batteryAmps = (batteryAmps + previous_batteryAmps) / 2; //average the panelAmps
  previous_batteryAmps = batteryAmps;
  if (batteryAmps < 0) batteryAmps = 0; //don't let the batteryAmps go below zero
  //display the panelAmps
  batteryWatts = batteryVolts * batteryAmps; //calculate the battery watts
  efficiency = (batteryWatts / P * 100);
  Serial.println("effiiciency \t");
  Serial.println(efficiency);
  maxwatts = max(maxwatts, P); //calculate the max watts
  //----------------------------------------LED to denote charging state of battery--------------------------//
  if (batteryVolts < 11) // low satte of charge
  { digitalWrite(red_led, HIGH);
    //disconnect the battery from the load
  } //low voltage
  if (batteryVolts > 12.40 ) // from 75% to 100% state of charge
  {
    digitalWrite(green_led, HIGH); //high voltage
  }
  if (batteryVolts > 14.00 ) // High voltage dicsonnect
  { digitalWrite(green_led, HIGH);
    duty_cycle = 0;
  } //high voltage
  if (batteryVolts > 12.00 && batteryVolts < 12.40) // 60% to 40% state of charge
  {
    digitalWrite(yellow_led, HIGH); // medium volatge
  }
  lcd.begin(20, 4);
  lcd.setCursor(0, 0);
  // Print a message to the LCD.
  lcd.print("Vp=");
  lcd.print(voltage_next);
  lcd.print("V ;");
  lcd.print(" Ip=");
  lcd.print(current_next);
  lcd.print("A");
  lcd.setCursor(0, 1);
  lcd.print("Panel Power=");
  lcd.print(P);
  lcd.print("W");
  lcd.setCursor(0, 2);
  lcd.print("Duty Cycle=");
  lcd.print(duty_cycle);
  lcd.print("%");
  lcd.setCursor(0, 3);
  lcd.print("Efficiency=");
  lcd.print(efficiency);
  lcd.print("%");
  delay(3000);
}
ERRORS

'IntTimersSafe' was not declared in this scope
'SetPinFrequencySafe' was not declared in this scope

"not declared in this scope" means some library is not loaded.

But,i have already added pwm library

Spelling error? Perhaps InitTimersSafe()?

SetPinFrequencySafe() is part of the PWM library but you didn’t include <PWM.h>.

This seems to be the same problem as this thread. There were answers in the other thread that will probably be repeated in this one wasting the time of members that tried to help before. Why start a new thread?

yes it is,inittimersafe() .but it is also giving errors

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here using code tags.

i am struck in this part
please guide me

" float sensorValue_current = analogRead(A3);
float voltage_current=(sensorValue_current5/1023); why multiplied by (5/1023)
float cur=(610/39)
(voltage_current-3.7375);//using the no 3 sensor (why multiplied by 610/39)

mySensVals = cur;
_ sumi=sumi+mySensVals*; *_
float sensorValue_voltage = analogRead(A1);
float voltage0=(sensorValue_voltage5/1023)67.66; "( similarly facing same issue here)
_
code error.png
_

Did you create a new account? Or is this someone else working on the same code? We were Moinh to post some error messages. Now you show up and post only code (despite the name of the attachment. I’m confused about what’s going on here.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar, then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

It’s also usually not helpful to post code snippets.

Muhammad_Sajid’s picture:
be8586a50d03e48a8ed18bbb5008de2e7c46dcf6.png
Don’t post pictures of text! That’s extremely unhelpful.