Hi!!
Hope all of you are doing great!! ![]()
Well I am really struggling with timings in Arduino code... Hope I can get some Idea... Here's my code:
#include <Wire.h>
int in1Pin = 10;
int in2Pin = 11;
double Temperature;
double Humidity;
#define HYT221_ADDR1 0x28
void setup(){
 pinMode(in1Pin, OUTPUT);
 pinMode(in2Pin, OUTPUT);
 Serial.begin(9600);
 Wire.begin();
}
void read_HumTemp(){
  // initiate measurement
 Wire.beginTransmission(HYT221_ADDR);
 Wire.write(0);
 Wire.available();
 int Ack1 = Wire.read(); // receive a byte
 Wire.endTransmission();
 delay(100); //This particular delay is the delay between the displayed values (in msec)...
// READ DATA from here on
 Wire.beginTransmission(HYT221_ADDR);
 Wire.requestFrom(HYT221_ADDR,4); //Reade 1 byte
 Wire.available();
 int b11 = Wire.read(); // receive a byte
 int b21 = Wire.read(); // receive a byte
 int b31 = Wire.read(); // receive a byte
 int b41 = Wire.read(); // receive a byte
 Wire.write(0); //NACK
 // combine the bits
 int RawHumidBin = b11 << 8 | b21;
 // compound bitwise to get 14 bit measurement first two bits
 // are status/stall bit (see intro text)
 RawHumidBin = (RawHumidBin &= 0x3FFF);
 Humidity = 100.0/pow(2,14)*RawHumidBin;
 b41 = (b41 &= 0x3F); //Mask away 2 least sign. bits see HYT 221 doc
 int RawTempBin = b31 << 6 | b41;
 Temperature = 165.0/pow(2,14)*RawTempBin-40;
 Wire.endTransmission();
}
void loop(){
   digitalWrite(in1Pin, LOW);
   digitalWrite(in2Pin, HIGH);
   delay(30000);
for(int x=0; x<500; x++){Â Â Â Â
    read_HumTemp();
    Serial.print(Humidity);
    Serial.print(",") ;
    Serial.println(Temperature);
    delay(10);
 }
 }
So as a short description, I have an Arduino UNO, LD293D and HYT221 humidity sensor. A valve remains open through L293D chip for 30 seconds (delay). Then I need to close the valve for 5 sec (5000 msec) and DURING these 5 sec, read from the sensor every 10 miliseconds for 500 times (i.e- total is 5 seconds...)
This code is unfortunately not working... After the initial delay of 30 seconds, when the valve closes then it goes into infinite loop and never opens again... Whts wrong with this code...?? ![]()
Maybe I am missing something silly or maybe there is something new I can try...
Some help would be greeatly appreciated!! ![]()
Thank you so much!!
Pramit