Help with, ATtiny13A Water Sensor

Hi all,

I've been toying with my Leonardo and Mega2560 and have my simple code working fine and how I want on both ("code adapted from the Knock Sketch"). Trouble is, when I upload my code to my ATtiny13A with the pin's updated in the code, PB1 (Pin6) is "HIGH" and PB2 (pin7) is "LOW" which is all fine and well but, when I put the probe in water PB1 (Pin6) stays "HIGH" and PB2 (Pin7) is still "LOW" What I was expecting to see what PB1:LOW, PB2:HIGH as this is how it works on the Leonardo and Mega2560

Just to be clear,
The outPin's are LED's for now.

Probe out of water.
PB1:HIGH, PB2:LOW,

Probe in water.
PB1:LOW, PB2:HIGH

Leonardo code:

const int outPin1 = 7;
const int outPin2 = 8;
const int Probe = A0;
const int threshold = 75;
int sensorReading = 0;
void setup() {
  pinMode(outPin1, OUTPUT);
  pinMode(outPin2, OUTPUT);
  Serial.begin(9600); 
}
void loop() {
  sensorReading = analogRead(Probe);  
  Serial.print("\t sensor = " );  
  Serial.print(sensorReading);    
  if (sensorReading >= threshold) {     
    digitalWrite(outPin1, HIGH);  
    digitalWrite(outPin2, LOW);  
  } 
  else {
    digitalWrite(outPin1, LOW);
    digitalWrite(outPin2, HIGH); 

  }
  delay(100);
}

ATtiny13A:

const int outPin1 = 1;
const int outPin2 = 2;
const int Probe = 0;
const int threshold = 75;
int sensorReading = 0;
void setup() {
  pinMode(outPin1, OUTPUT);
  pinMode(outPin2, OUTPUT); 
}
void loop() {
  sensorReading = analogRead(Probe);   
  if (sensorReading >= threshold)
  {     
    digitalWrite(outPin1, HIGH);  
    digitalWrite(outPin2, LOW);
  } 
  else {
    digitalWrite(outPin1, LOW);
    digitalWrite(outPin2, HIGH);
  }
  delay(100);
}

I can only assume some things up with my code, in fact... My assumption is, PB0 to PB5 can be ether used as Analogue or Digital I/O's? Is this correct?

I'll put up an Fritzing pic in a sec.

If there's anything thing have missed out, shout.

Cheers,

According to the datasheet analog input is PB2, Pb3 and PB4 (and PB5 which is reset)

So try this:

const int Probe = A3;

Thank you Erni, will update the code and see how it goes!

Rite, all working now.. Thanks E.

If I changed,

const int Probe = 0;

to,

const int Probe = A3;

I got this, why? I thought this is declaring?

Tiny13:3: error: 'A3' was not declared in this scope

I removed the "A"

And now it's all working fine now, with a few adjustments to "threshold".

const int outPin1 = 1;
const int outPin2 = 2;
const int Probe = 3;
const int threshold = 220;
int sensorReading = 0;
void setup() {
  pinMode(outPin1, OUTPUT);
  pinMode(outPin2, OUTPUT); 
}
void loop() {
  sensorReading = analogRead(Probe);   
  if (sensorReading >= threshold)
  {     
    digitalWrite(outPin1, HIGH);  
    digitalWrite(outPin2, LOW);
  } 
  else {
    digitalWrite(outPin1, LOW);
    digitalWrite(outPin2, HIGH);
  }
  delay(1000);
}

Good you made it work

Tiny13:3: error: 'A3' was not declared in this scope

The pin definition depends on the core you are using, but never mind it works