Pages: [1]   Go Down
Author Topic: Garduino  (Read 650 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey everyone!
I'm running a homemade arduino on a proto board and im having a couple problems with my simple Garduino.
1) Wont wake up in the morning
2) For some reason it reads this:
Potentiometer value reads: 768
Moisture sensor reads: 961
Light value reads: 553
I Need Water!
Potentiometer value reads: 768
------------------------------

every time I run it. I don't know why the water turns on every time. When the water turns on and it actually needs more water, it looks like:
Potentiometer value reads: 1022
I Need Water!
Potentiometer value reads: 1022
I Need Water!
Potentiometer value reads: 1022
I Need Water!
Potentiometer value reads: 1022
I Need Water!
Potentiometer value reads: 1022
I Need Water!


3) How can I make it go to sleep for the 60 second period between testing?


Anyways, heres the code.
Thanks in advance!!!!


Code:

#include <avr/power.h>
#include <avr/sleep.h>
int moistureSensor = 5;
int lightSensor = 1;
int waterPump = 7;
int pin2;
int ledPin = 13;
int moisture_val;
int light_val;
int PotPin = 3;
int PotVal;

void wakeUpNow()
{
Serial.println("Good Morning");
}

void setup()
{
 Serial.begin(9600);
 pinMode (ledPin, OUTPUT);
 pinMode (waterPump, OUTPUT);
 digitalWrite (waterPump, LOW);
 pinMode (pin2, INPUT);
 attachInterrupt(0, wakeUpNow, LOW);
 digitalWrite(ledPin, HIGH);
 delay(250);
 digitalWrite(ledPin, LOW);
 delay(250);
 digitalWrite(ledPin, HIGH);
 delay(250);
 digitalWrite(ledPin, LOW);
}

 void sleepNow()
{
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  attachInterrupt(0,wakeUpNow, LOW);
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();
  sleep_mode();
  sleep_disable();        
  power_all_enable();
}

void loop()
{
 PotVal = analogRead(PotPin);
 moisture_val = analogRead(moistureSensor);
 delay(1000);
 light_val = analogRead(lightSensor);
 Serial.print("Potentiometer value reads: ");
 Serial.println(PotVal);
 Serial.print("Moisture sensor reads: ");
 Serial.println(moisture_val);
 Serial.print("Light value reads: ");
 Serial.println(light_val);
 PotVal = map(PotVal, 0, 255, 0, 1023);
 delay(100);
 while (moisture_val < PotVal)
 {
 Serial.println("I Need Water!");
 PotVal = analogRead(PotPin);
 Serial.print("Potentiometer value reads: ");
 Serial.println(PotVal);
 digitalWrite(waterPump, HIGH);
 delay(250);
 moisture_val = analogRead(moistureSensor);
 }
 digitalWrite(waterPump, LOW);
  if (light_val < 50)
  {
   sleepNow();
  }
Serial.println("------------------------------");
delay(60000);
}

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Why won't this work!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm wondering, you set the "moisture val @ 5, then later the loop:
while (moisture_val < PotVal)
It would seem to me that m-v would always be lower thatn PotVal.

Not sure how your moisture sensor works, but does the value get higher than '5'?  If not then it would always seem to be lower that the PotVal.  Also you have PotVal reading 1022 then you map it to 0,255 so it looks like it would have to be pretty dry for it to read down towards 0. Wouldn't you want to map the moisture sensor?
Just a thought.

As for the sleep mode I haven't delved into that yet.

« Last Edit: April 05, 2010, 08:30:04 pm by gary_white » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Garym,
The moisture value is just a simple two wires, one going to analog, and one going to the Power.

At the end of these two wires there are nails that go in to the soil. It therefore measure from 0-1023. However, The potentiometer can only read from 0-255 (right?), so i mapped that to be the same as the moisture sensor.

I set the Moisture Sensor pin at five, not the moisture value at five so that wouldn't make a difference either.

Also, can the Arduino keep good enough time for me to just tell it when to turn off every night? If it can i won't use photoresistors and I'll just put it on a timer.  
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The value returned by analogRead will be in the range 0 to 1023, regardless of the type of device attached to the pin (homemade moisture sensor or potentiometer).

The actual value may be a small subset of that range, depending on the device attached. A potentiometer will use the full range. The moisture sensor probably will not.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, thanks, for some reason that also fixed my problem with the light randomly turning on too. Now I just need help with questions 1 and 3
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1) Maybe your a sound sleeper?

You are attaching an interrupt handler, wakeUpNow. What is generating the interrupt that the handler is supposed to respond to?

3) Call the sleepNow function?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i know I could call the sleepnow function but how would i make it wake up after the sixty seconds. Been thinking about this for over 3 days haha  smiley . Also if Iknew how to do this, i wouldn't have the problem with the waking up in the morning
« Last Edit: April 06, 2010, 07:36:41 pm by Jaker30528 » Logged

Pages: [1]   Go Up
Jump to: