Hi guys I desperately need your help in solving, what looks like, a very trivial issue. Today we spent over 7 hours debugging the hardware and software for our project and have narrowed the problem down to something that is truly mind boggling to us. the code below is a snippet of the whole project, but its is the main issue no doubt.
float sensorValue;
float voltage;
float x = 2.0;//some voltage threshold
void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
}
void loop() {
sensorValue = analogRead(A0);
voltage = sensorValue * (5.0 / 1023.0) * 5;//mult by 5 b/c sensor divides actual sensed voltage by 5
//to prevent damage and return that value to us
Serial.println(voltage);
if(voltage <= x){
digitalWrite(4,HIGH);
//delay(50);
}else if(voltage > x){
digitalWrite(4,LOW);
//delay(50);
}
}
the voltage sensor in question is this
http://www.emartee.com/product/42082/Voltage%20Sensor%20Module%20%20Arduino%20Compatible
we have confirmed that the sensor is working correctly. We are driving leds using mostfets as switches through digital pins and they are working correctly as well, so long as the if statements are taken out, and a delay is added for a blinking effect, BUT AS SOON AS WE TRY AND MAKE A DECISION OF WHEN TO TURN ON THE LEDs BASED ON THE VALUE FROM THE SENSOR, IT STOPS WORKING. the leds are either fully on or off, there is no response to the sensed value/if statements.
If you need to see the circuit please let me know I can quickly make one, but again it works as a simple blinking exercises as long as the if statements are gone. The sensor reads and displays the correct voltage, which we are applying and changing manually.
I don't see how this is possible, can someone please help us!
Desperate haha
