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?
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 }