84Views8Replies

Author Options:

How to show 3 different temperatures using 3 LEDs connected to a ATtiny85? Answered

Hi people I am trying to build a temperature sensor using 3 LEDs. The aim is to have them come on at specific temperatures. This is for my motorcycle ride to work this coming winter. I want to know when the temp goes below 8c down to 5c from 5c down to 0c then below. I have managed to do this via a arduino board & a LM35 sensor and 3 LEDs. But I cant get this to work on the ATtiny85 chip. Below is the code I wrote for this on the arduino. Any help or different program would be of great.

*my first attempt at a temp warning light
need it to come on when temp lower than 5deg celsius

*/
int tempPin = A1;
int led01 = 8;
int led02 = 9;
int led03 = 10;
int tempMax = 28;
int tempMid = 27;
int tempMin = 5;
int temp;

void setup() {
  Serial.begin(9600);
 
  pinMode (led01, OUTPUT);
  pinMode (led02, OUTPUT);
  pinMode (led03, OUTPUT);
  pinMode (tempPin, INPUT);
}
 
  void loop() {
     temp = analogRead(tempPin);
     temp = temp * 0.48828125;
    Serial.print("TEMPRATURE = ");
  Serial.print(temp);
  Serial.print("*C");
  Serial.println();
  delay(1000);
  if (temp > tempMax){
  digitalWrite(led01, HIGH);
  digitalWrite(led02, LOW);
  digitalWrite(led02, LOW);
  }
if (temp < tempMid){
  digitalWrite(led01, LOW);
  digitalWrite(led02, HIGH);
  digitalWrite(led02, LOW);
 
}


if (temp < tempMin){
  digitalWrite(led01, LOW);
  digitalWrite(led02, LOW);
  digitalWrite(led02, LOW);
}}

Discussions

0
None
r5sb

4 years ago

It's probably the Serial commands that's causing the compile error...you'll need the SoftwareSerial library for the Attiny to communicate serial.

0
None
minimadmalcr5sb

Answer 4 years ago

Sorry should of made it clear the serial part of the sketch I have removed before loading to the ATtiny chip.Its just the Attiny chip pins I need to get right? I need to get the Attiny to switch on & off the correct pins via the temp sensor? I have tried a multitude of variations but no luck!

0
None
r5sbminimadmalc

Answer 4 years ago

Correct...you'll need to change the pin numbers in the code to suit the attiny85 (they're numbered 0 to 4 on the Attiny).

Another thing, you're only using LEDs 1 and 2 in the code..your third istatement in all the if conditions puts LED02 pin to LOW and your last if statement has all LEDs going LOW so it won't output anything.

Also make the changes to your mid condition like steveastrouk said!

0
None
steveastrouk

4 years ago

At temp min, no LED is on.

Your mid condition should be if (temp <= temp_mid)&(temp>temp_min), because even if temp<tempmin, temp is still <tempmid.

0
None
steveastrouk

4 years ago

Does it compile OK ?

What's it not doing ?

0
None
minimadmalcsteveastrouk

Answer 4 years ago

It works ok on arduino board but compiles to ATtiny 85 but when I make the connections to the chip I can get one led to light but its not affected by the change in temperature. Must be something to do with the chip pins (digital or analog in outs)? or am I using the correct code to send the program to the ATtiny? I have tried a number of different int pin settings. I have looked at other programs but can't work it out!

0
None
steveastroukminimadmalc

Answer 4 years ago

try taking the serial lines out, if the code worked. Which led does come on?

0
None
iceng

4 years ago

I would use a single RGB LED and let color tell me temperature....