Author Topic: powering soil moisture sensor from digispark  (Read 3858 times)

jerome187

  • Newbie
  • *
  • Posts: 7
powering soil moisture sensor from digispark
« on: May 26, 2016, 06:42:13 am »
hello,

I am trying to power the sensor from pin1 (turning the sensor on/off only when its being used greatly increases the probes life and reduces power consumption) I seem to be doing all the right things, waiting 1 second after powering before reading.

The sensor works fine if I connect it to the 5V pin, but just dosen't seem to work if i try and use any of the switchable pins on the digispark.

im stumped, been working on it for a few hours now... trying and checking everything.  is there some limitation with the digispark that would cause this to happen?

Code: [Select]
  1 //This uses the soil moisture probe and based on that controls LEDs to show anyone current moist    ure statuses.
  2
  3 #include "DigiKeyboard.h"
  4
  5 //int ledGreenPin = 0;
  6 int ledRedPin = 2;
  7 int sensorPowerPin = 1; //to extend the life of the probe
  8 int sensorPin = 0; //this is pin 5 on the digispark
  9
 10 void setup() {
 11     // setting the led pins to outputs
 12 //  pinMode(ledGreenPin, OUTPUT);
 13     pinMode(ledRedPin, OUTPUT);
 14     pinMode(sensorPowerPin, OUTPUT);
 15   
 16     // make sure leds and the sensor are off
 17 //  digitalWrite(ledGreenPin, LOW);
 18     digitalWrite(ledRedPin, LOW);
 19     digitalWrite(sensorPowerPin, LOW);
 20 }
 21
 22 void loop() {
 23     //turn on sensor and pause for driver
 24     digitalWrite(sensorPowerPin, HIGH);
 25     delay(1000);
 26     // read the analog input
 27     int sensorValue = analogRead(sensorPin);
 28     // print out the value that was read
 29     DigiKeyboard.println(sensorValue);
 30     
 31     if (sensorValue >= 820){
 32 //      digitalWrite(ledGreenPin, LOW);
 33         digitalWrite(ledRedPin, HIGH);
 34     }   
 35     else if (sensorValue >= 615  && sensorValue < 820){
 36 //        digitalWrite(ledGreenPin, LOW);
 37         digitalWrite(ledRedPin, LOW);
 38     }
 39     else if (sensorValue < 615){
 40 //      digitalWrite(ledGreenPin, HIGH);
 41         digitalWrite(ledRedPin, LOW);
 42     }
 43     //turn off the sensor
 44     digitalWrite(sensorPowerPin, LOW);
 45     // delay 1 second between reads !change to like 1 minute for production!)
 46     delay(1000);
 47 }




jerome187

  • Newbie
  • *
  • Posts: 7
Re: powering soil moisture sensor from digispark
« Reply #1 on: May 26, 2016, 07:26:26 am »
whoop!

got it working... after reading this http://digistump.com/wiki/digispark/tutorials/relay

ended up having to use pin2 to turn the sensor on/off.

can I get an explanation why though?

jerome187

  • Newbie
  • *
  • Posts: 7
Re: powering soil moisture sensor from digispark
« Reply #2 on: May 26, 2016, 08:05:23 am »
ok im stumped again.. trying to read in analog (or even digital I guess) off the soil moisture sensor output(s).  most of the time when I connect the analog output to the digispark (ive tried the 4 pins listed here: http://digistump.com/wiki/digispark/tutorials/basics ) the digispark just stops working..

is it just me or is this an extreemly finicky device..?

AMBODACH

  • Newbie
  • *
  • Posts: 4
Re: powering soil moisture sensor from digispark
« Reply #3 on: May 26, 2016, 01:14:24 pm »
Hi Jerome
I certainly can't help you on this except offer another solution. 

I'm well below you on the learning curve for Attiny's, but have a similar project, hence my interest.  It may well be that you wish to continue on the route you are on purely out of cussedness, but can I recommend this website to you as this is the way I am going to go once I get over my failure to even program a Digistump from my PC !!.  Furthermore all the code is there !!!!

https://arduinodiy.wordpress.com/2016/02/

This strikes me as a far more elegant solution.  My target is to get the moisture information passed wirelessly from several beds to a central control station.

Rob

AMBODACH

  • Newbie
  • *
  • Posts: 4
Re: powering soil moisture sensor from digispark
« Reply #4 on: May 26, 2016, 03:20:01 pm »
Jerome - I'm back again - taken a step or two up the learning curve this evening in that I have at least got the IDE to talk to the digispark board.  I'm going to have to learn how to program an Attiny chip on a stand alone board at some point but that I think is well documented I'm sure, and anyhow is well down the project.

I'm pretty well a novice on all this though a retired electronics engineer.  I now have to plan out how I am going to implement the soil moisture project so that I can see that I am getting it right in each phase of the development.

It would be good if I could gently persuade you to jump ship and go the same way that I am.  I know that using someone else's code is not quite so adventurous, but the wireless element will be interesting as will the other requirement of maximising battery life to a year at least requiring playing with long sleep periods.

The purpose of the task is to manage the watering of the two beds in my polytunnel.  Quite how one calibrates such moisture gauges is something to be looked into, but the software and hardware developments looks fun, and then -- I already have a sale to a neighbour if I get it working - big carrot! (and they're in the polytunnel too!). 

Rob

jerome187

  • Newbie
  • *
  • Posts: 7
Re: powering soil moisture sensor from digispark
« Reply #5 on: May 29, 2016, 10:23:00 am »
jump ship?  no, no... not on something as simple as this!  I got it working, the problems were from a faulty digispark either made faulty by me using wrong version of the ide or because I messed up USB communications on pin 3 and/or 4.  good thing I bought 2 sparks... and good thing they are sooooo much cheaper elsewhere..  I am highly unimpressed with support though.  I can post my working code in a little bit if you like though after I clean it up a bit.