attiny85 + serial monitor + lm35

hi, what can i solve this problem?
this is the code for receive temperature

void setup() {
  Serial.begin(9600);
}
void loop() {
  int Valore = analogRead(A0);
  Serial.println(5.0*Valore*100/1024); Serial.println(" gradi");
  delay(1000);
}

error

Arduino:1.6.4 (Windows 8.1), Scheda:"ATtiny, ATtiny85, 8 MHz (internal)"

AnalogReadSerial.ino: In function 'void setup()':
AnalogReadSerial:2: error: 'Serial' was not declared in this scope
AnalogReadSerial.ino: In function 'void loop()':
AnalogReadSerial:6: error: 'Serial' was not declared in this scope
'Serial' was not declared in this scope

The Tiny85 does not have hardware serial. You can use software serial.

untested but shows how to set up software serial (mind the RX and TX pins).

#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 4); // RX, TX

void setup()
{
    mySerial.begin(9600);
}
void loop()
{
    int Valore = analogRead(A0);
    mySerial.println(5.0*Valore*100/1024);
    mySerial.println(" gradi");
    delay(1000);
}

thank you very much, but I have never used this library; RX and TX pin in what has to be connected?what it means to pins 3 and 4?

Pin PB3 is physical pin 2, pin PB4 is physical pin 3. So, PB3 (RX) goes to the USB to serial adapter TX and pin PB4 (TX) goes to USB to serial adapter RX. How are you programming the Tiny85?

i don't have USB serial adapter, i use arduino as ICSP..
However I tried to connect the pin D3 and D4 of the tiny to TX (D1) and RX (D2) on my "arduino mega" and in serial monitor I find these
"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ" :o

Can you show the Mega code to receive from Tiny85? Are the baud rates the same at each end?

what? :open_mouth:
I just loaded the program on the tiny and I opened the serial monitor.
I also tried to change "baud rate" but never came out a value numbers, always written at random.

I just loaded the program on

What program?

What serial port is the serial monitor connected to? Is it the Mega hardware serial? If you want to see the output from the Tiny85 in serial monitor, you will need to write a program for the Mega to receive data from the Tiny85 via a different serial port than is connecting the Mega to the computer (serial monitor) and the Mega will transmit to the computer (serial monitor). The only way, that I know of, to connect a Tiny85 directly to serial monitor is through the use of a USB to serial adapter.

We start again from scratch.
This program

#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 4); // RX, TX

void setup()
{
    mySerial.begin(9600);
}
void loop()
{
    int Valore = analogRead(A0);
    mySerial.println(5.0*Valore*100/1024);
    mySerial.println(" gradi");
    delay(1000);
}

will load through my "Arduino Mega" in ICSP mode on the tiny, after I connect the pin D3 and D4 of the tiny to TX (D1) and RX (D2) on my "Arduino Mega",
Soon after I start the "Serial Monitor"but I can not display the temperature.
If this is wrong, can you please tell me how to do?
thanks :slight_smile:

You have three other hardware serial ports on the Mega. I am not near my computer right now (and not until 1500) so can't write and test code. What you need to do is connect the Tiny85 to Serial1, Serial2 or Serail3. Add Serialx.begin(); to your latest code (where x is the serial port number that the Tiny85 is connected RX to TX and TX to RX).

In loop():

if(Serialx.available())
{
    Serial.print( Serialx.read());
}