1709Views8Replies

Author Options:

Programming an Attiny85 with Arduino Uno as ISP, but I keep getting Serial was not declared in this scope? Answered

The sketch runs fine on the uno, but as soon as I switch the board to Attiny 85, i get an error that says serial was not declared in this scope. 

Any help is greatly appreciated!

Here is the sketch for reference.

#include <IRremote.h>

const int relay = 9; //Relay Control
const int RECV_PIN = 8; //IR Sensor

int relayState = LOW;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();

  pinMode(relay, OUTPUT);


}

void loop() {

  if (irrecv.decode(&results)){
        long int decCode = results.value;
Serial.println(decCode);
switch (results.value) {
 

        case 1637937167: // Power Button
     {
      relayState = !relayState;
      digitalWrite(relay, relayState);
      delay(100);
}
irrecv.resume(); // Receive the next value
  }

  }
}

Discussions

You can't use the SAME pins for Soft serial as the relay and the IR.

Sorry, I'm new to the softwareserial command. What pins should I set it to?

Any two other than two that are already in use for other things. Your other problem will be taking serial out to the real world - you will need a TTL serial to USB cable.

If you want to use serial, you will need to use softwareserial

http://arduino.cc/en/Reference/SoftwareSerial

You may need to modify the library itself (I seem to remember it having a hard frequency ifdef)

http://digistump.com/board/index.php/topic,212.msg1214/topicseen.html#msg1214

Still no luck, although I'm fairly certain i'm using SoftwareSerial wrong

#include
#include

SoftwareSerial mySerial (8, 9);
const int relay = 9; //Relay Control
const int RECV_PIN = 8; //IR Sensor

int relayState = LOW;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
mySerial.begin(9600);
irrecv.enableIRIn();

pinMode(relay, OUTPUT);


}

void loop() {

if (irrecv.decode(&results)){
long int decCode = results.value;
mySerial.println(decCode);
switch (results.value) {


case 1637937167: // Power Button
{
relayState = !relayState;
digitalWrite(relay, relayState);
delay(100);
}
irrecv.resume(); // Receive the next value
}

}
}

Now I'm getting an error originating in the ir libraries.