Hello,
yes i was in a bit of a rush before:) so lets start at the beginning, i have an arduino rev3 with a motor shield.
What i want to accomplish in the end is an automated watering system - however, i've never dealt with micro-controllers before, so im testing stuff out as i go along.
So what i want to do here is connect an LM35 temperature sensor, a relay and 1 motor on channel A of the motor shield.
First off, i got a 9V power supply for the arduino, since it has to be autonomous.
ok, so here is my code:
float tempC;
int tempPin = 2;
int relay = 4;
int reading;
int mAdir = 12;
int mApwm = 3;
int mAbrake = 9;
void setup ()
{
Serial.begin(9600);
analogReference(INTERNAL);
pinMode(relay, OUTPUT);
pinMode(mAdir, OUTPUT);
pinMode(mApwm, OUTPUT);
pinMode(mAbrake, OUTPUT);
}
void loop()
{
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.print(tempC);
Serial.println("C Temperature");
if(tempC > 25.00)
{
digitalWrite(relay, HIGH);
Serial.println("relay ON");
digitalWrite(mAdir, LOW);
digitalWrite(mAbrake,LOW);
analogWrite(mApwm, 255);
Serial.println("motor ON");
}
else
{
digitalWrite(relay, LOW);
Serial.println("relay OFF");
digitalWrite(mAbrake, HIGH);
}
delay(1000);
}
and this actually works fine! the problem begins when i try to add another sensor on the next analog pin!
float tempC;
int water;
int waterPin = 3;
int tempPin = 2;
int relay = 4;
int reading;
int mAdir = 12;
int mApwm = 3;
int mAbrake = 9;
void setup ()
{
Serial.begin(9600);
analogReference(INTERNAL);
pinMode(relay, OUTPUT);
pinMode(mAdir, OUTPUT);
pinMode(mApwm, OUTPUT);
pinMode(mAbrake, OUTPUT);
}
void loop()
{
water = analogRead(waterPin);
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.print(tempC);
Serial.println("C Temperature");
Serial.println(water);
if(tempC > 25.00)
{
digitalWrite(relay, HIGH);
Serial.println("relay ON");
digitalWrite(mAdir, LOW);
digitalWrite(mAbrake,LOW);
analogWrite(mApwm, 255);
Serial.println("motor ON");
}
else
{
digitalWrite(relay, LOW);
Serial.println("relay OFF");
digitalWrite(mAbrake, HIGH);
}
delay(1000);
}
note that i havent connected any sensor to pin 3 yet, but as soon as i upload it i get a totally different reading on the temperature sensor, it just jumps around randomly, hovers at 9 degrees, then 30 etc...
any ideas?