Go Down

Topic: my code is ALMOST working: attiny45 reading a soil moisture sensor with leds out (Read 10 times) previous topic - next topic


Hello my saviors!!
So this code reads from the soil sensor and lights a bunch of leds depending on voltage. As I upload the sketch with the sensor in wet ground, it works: I could have 4 or 5 leds lighted up on 8, meaning it reads the expected voltage (not too dry -8 leds- not too wet -0 leds-). When I take off the sensor and leave it in the air, it comes back to 8 leds, which is normal. But afterwards, if I put it back in wet soils, it will stay at 8 leds on, meaning it might not overwrite the voltage of the sensor anymore, because it should go back to 4 or 5 leds, as the sensor was reading in the soil when I uploaded the sketch first.  So, it seems like the sketch works at first, but then something goes bad.. This means I need to upload it everytime I want to measure soil moisture.. Not convenient! Any idea?

Thanks for your help, this community saved me so many times!!

Code: [Select]
int sensor_pin = A3;
int output_value ;
int latchPin = 0;
int clockPin = 1;
int dataPin = 2;
byte leds =0;

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);


void loop() {

for (int i = 0; i <= nbLed; i++)
      output_value= analogRead(sensor_pin);

// afficher l'humidité avec les leds
  int nbLed = map(output_value,0,1023,0,7);
    bitSet(leds, i); //fct qui met un 1 à une bit donnée ds le byte
//delay(1000);  //laisse le temps de voir la valeur avant de erase
void updateShiftRegister()
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);

Go Up