I tried to programm an attiny13a to make a cold chamber controller (a fan will start when it's too hot and stop when enought cold, controled by an solid state relay (ssr in this code)) Temperature set at 27C for test purpose)
int ssr = 0; //Digital pin for my solid state relay (or LED for test
int sensor = 3; //Analog pin for my LM335A sensor
void setup()
{
pinMode(ssr, OUTPUT);
// Serial.begin(9600); //For debugging
}
void loop()
{
delay(5000);
int temp = analogRead(sensor); //read the LM335A sensor
if(temp > 617) //(((température voulue)+273,15)*10/5000*1024.0)(617=27C) compare temperature with desired one
{
digitalWrite(ssr, HIGH); //turn on ssr
}
else
{
digitalWrite(ssr, LOW); //turn off SSR
}
// Serial.println(temp); //check temp value while debugging
}
I tried it on my arduino uno R3 and it work fine but when i put it on my attiny the digitalRead is stuck on 1023 when connected or 0 when grounded, This sketch turn on the LED when it raise 27 celcius (when i touch the sensor with my hand) and turn off when it cool down. It work on Uno R3 but not on attiny.
I used this shematic for my sensor: (but with the good pin number and 2K resistor, not as shown)
Did someone see anything in my code or know something about attiny known problem with analogRead?
Yes I connected it to pin 2, my circuit is exactly that:
I'm a bit confused about pin number on datasheet vs IDE pin asigment, does the Arduino IDE recognise that I want an analog pin if I call an analogRead? The physical pin 2 are the analog and digital input 3 (I chose it to not take the chance with pin number )
And about the const for pin number, I think I doesn't understant exactly what you mean... I'm a newbie programmer and I'm not a beast in english XD
const int ssr = 0; // <<<<<<<<<<<<<<<<<<<< //Digital pin for my solid state relay (or LED for test
const int sensor = 3; // <<<<<<<<<<<<<<<<<<<< //Analog pin for my LM335A sensor
void setup()
{
pinMode(ssr, OUTPUT);
// Serial.begin(9600); //For debugging
}
void loop()
{
delay(5000);
int temp = analogRead(sensor); //read the LM335A sensor
if(temp > 617) //(((température voulue)+273,15)*10/5000*1024.0)(617=27C) compare temperature with desired one
{
digitalWrite(ssr, HIGH); //turn on ssr
}
else
{
digitalWrite(ssr, LOW); //turn off SSR
}
// Serial.println(temp); //check temp value while debugging
}
Making constants actual constants reduces the amount of Flash and SRAM your sketch uses which is extremely important with a processor like an ATtiny13.
const int ssr = 0; // <<<<<<<<<<<<<<<<<<<< //Digital pin for my solid state relay (or LED for test
void setup()
{
pinMode(ssr, OUTPUT);
// Serial.begin(9600); //For debugging
}
void loop()
{
delay(5000);
int temp = analogRead( A3 ); // <<<<<<<<<<<<<<<<<<<< //Analog pin for my LM335A sensor // read the LM335A sensor
if(temp > 617) //(((température voulue)+273,15)*10/5000*1024.0)(617=27C) compare temperature with desired one
{
digitalWrite(ssr, HIGH); //turn on ssr
}
else
{
digitalWrite(ssr, LOW); //turn off SSR
}
// Serial.println(temp); //check temp value while debugging
}
For the sensor it work just well on my Arduino Uno R3, your diagram just
doesn't show the adjust pin, I just don't read anything on analog pin (nor
grounded nor +5V to analog 3) I will try to find others cores on the forum,
I will post the result of my tests.
I WILL program that Attiny and make it do what I want!
Thanks again for your patience. I don't know if it is possible that I
just buy a "cheap" chip, I mean, I don't know if it is possible that I get
five non-working attiny13???
Crud. Your diagram is correct. Putting +5V on the bottom confused me. Sorry about that.
Try this: Remove the temperature sensor and resistor. Remove the delay from your sketch. Upload the new sketch. With the sketch running, connect A3 to GND. The LED should be dark. Connect A3 to +5V. The LED should be lit.
If that does not work, the problem has to be software. Try a different core.
That work now! I downloaded the latest core13 version of smeezekitty (The core I used first
was an old version, I think) The analogRean was not working at all (no reaction to grounded or
+5V on analog pin)
The working core can be found here (permanent link to the latest version):
I will post a photo of my finished project with the diagram and final code I hope that someone will
read it and don't waste time with outdated library found on google