Arduino and Attiny85

Hi! I have problem with this code.Error: 'Serial was not declared in this scope'.Someone may help me,please? Thath is the code.*/

const int inputPin = A1;
const int outputPin = 0;

const int numReadings = 30; // number of analog read before checking battery status
const int multi = 1614; // multi coefficent for obtaining millivolts from analogread

long interval = 1000; // interval for pulse charging and analog read - don't change this
long interval2 = 250; // pulse off interval - you can adjust power with this. Use 100 for 2-4Ah battery packs, 500 for 1-2Ah battery pack
long interval2b=interval2;
long previousMillis,currentMillis,currentMillis2,trickleMillis = 0;

unsigned int readingtemp;
unsigned int total = 0;
unsigned int average,medium,maxmedium = 0;

boolean executed,endcharge,trickle=false; // booleans for controlling various activities (for example "end of charge")

unsigned int myarray [7]; // array for keeping last 7 readings
int index,i = 0;

void setup()
{
Serial.begin(9600);
pinMode(0,OUTPUT);

// Some readings for initial check
for (i=0;i<10;i++) {
readingtemp = analogRead(inputPin);
total=total+readingtemp;
}
average = (((float)total / 1023.0) * (float)multi) / 10.0 + 0.5;
if (average<=70) endcharge=true; // If there is no battery, end charge
Serial.println(average);

total=0;
average=0;
}

void pusharray() {
// push the array
for (i=0;i<=5;++i) {
myarray*=myarray[i+1];*

  • }*
  • myarray[6]=average;*
    }

void voltread() {

  • readingtemp = analogRead(inputPin); // read analog input*

  • total= total + readingtemp;*

  • index++;*

  • // if numReadings reached, calculate the average*

  • if (index==numReadings) {*

  • index=0;*
    _ average = (((float)total / 1023.0) * (float)multi) / numReadings + 0.5;_

  • if (average<=70) endcharge=true; // stop charge if battery is detached*

  • total=0;*

  • pusharray(); // insert new average in array*

  • medium=(float)(myarray[6]+myarray[5]+myarray[4]+myarray[3]+myarray[2]+myarray[1]+myarray[0])/7.0+0.5; // calculate the average of the last 7 readings*

  • if (medium>maxmedium) maxmedium=medium; // save the value of highest medium in "maxmedium"*

  • Serial.print(medium);*

  • Serial.print(",");*

  • Serial.print(maxmedium);*

  • Serial.print(",");*

  • Serial.println(myarray[6]);*

  • if ( ((medium+1) < maxmedium) && ((millis()/60000)>=11) ) { // if battery charged (average voltage is dropped 0.02v), but not in the firsts 11 mintues*

  • if (!trickle) trickleMillis=millis(); // start trickle timer*

  • trickle=true; // enter final trickle charging mode*

  • if ((millis()/60000)<=15) endcharge=true; // if battery is charged in the firts 15 minutes, don't apply trickle charge (maybe was yet charged)*

  • }*

  • }*
    }

Start by reading the forum guidelines. Edit your post to put your code in code tags. Post the full error as explained in the guidelines.

OK

*/
 
const int inputPin = A1;
const int outputPin = 0;
 
const int numReadings = 30; // number of analog read before checking battery status
const int multi = 1614; // multi coefficent for obtaining millivolts from analogread
 
long interval = 1000;     // interval for pulse charging and analog read - don't change this
long interval2 = 250;     // pulse off interval - you can adjust power with this. Use 100 for 2-4Ah battery packs, 500 for 1-2Ah battery pack
long interval2b=interval2;
long previousMillis,currentMillis,currentMillis2,trickleMillis = 0;
 
unsigned int readingtemp;
unsigned int total = 0;
unsigned int average,medium,maxmedium = 0;
 
boolean executed,endcharge,trickle=false;  // booleans for controlling various activities (for example "end of charge")
 
unsigned int myarray [7];   // array for keeping last 7 readings
int index,i = 0;
 
void setup()  
{
   Serial.begin(9600); 
   pinMode(0,OUTPUT);
 
  // Some readings for initial check
  for (i=0;i<10;i++) {
    readingtemp = analogRead(inputPin);
    total=total+readingtemp;
  }
  average = (((float)total / 1023.0) * (float)multi) / 10.0 + 0.5;
  if (average<=70) endcharge=true;  // If there is no battery, end charge
  Serial.println(average);
 
  total=0;
  average=0;
}
 
void pusharray() {
  // push the array
  for (i=0;i<=5;++i) {
    myarray[i]=myarray[i+1];
   }
  myarray[6]=average;
}
 
void voltread() {
  readingtemp = analogRead(inputPin);  // read analog input
  total= total + readingtemp;
  index++;
 
  // if numReadings reached, calculate the average
  if (index==numReadings) {
    index=0;
    average = (((float)total / 1023.0) * (float)multi) / numReadings + 0.5;
    if (average<=70) endcharge=true;  // stop charge if battery is detached
    total=0;
    pusharray(); // insert new average in array
    medium=(float)(myarray[6]+myarray[5]+myarray[4]+myarray[3]+myarray[2]+myarray[1]+myarray[0])/7.0+0.5; // calculate the average of the last 7 readings
    if (medium>maxmedium) maxmedium=medium; // save the value of highest medium in "maxmedium"
    Serial.print(medium);
    Serial.print(",");
    Serial.print(maxmedium);
    Serial.print(",");
    Serial.println(myarray[6]);
    if ( ((medium+1) < maxmedium) && ((millis()/60000)>=11) ) {  // if battery charged (average voltage is dropped 0.02v), but not in the firsts 11 mintues
      if (!trickle) trickleMillis=millis(); // start trickle timer
      trickle=true; // enter final trickle charging mode
      if ((millis()/60000)<=15) endcharge=true; // if battery is charged in the firts 15 minutes, don't apply trickle charge (maybe was yet charged)
    }
  }
}

ATtiny*5 has no Serial interface.

As Danois90 replied while I was writing this reply, the ATtiny85 has no hardware serial port, so the standard Serial object can't be used. However, if you use the excellent ATTinyCore, then a software serial port named Serial is provide. See the information here:

Thank You! I used this recomended ATTinyCore and problem is resolved! Thank You very much!

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per