Hello all,
Wondering if my problem has to do with the sparkcore regarding analog resolution. I am aware that there have been past posts about it, and tried rewiring my circuit to bypass the problem as suggested (by @BDub), but still getting the same readings… wondering if anyone can suggest an alternate solution!
What I’m trying to do: read in a switch/button through analog because it’s been proven with an oscilloscope that the voltages are different when the switch is in water vs dry state.
What I’m getting: analog readings through the arduino ide serial monitor values of 2060 (on) and 870 (rest) states, where the analog resolution is only supposed to be within the range 0-1023
I’ve coded in leds to indicate when the switch is on or off using the analog values I read through the monitor, but neither leds are turning on. Monitor consistently gives corresponding values for on and off states.
Any help would be awesome!!!
const int analogSwitch = A2;
int switchRead = 0;
const int blitz = 7;
const int red = 0;
const int green = 3;
void setup() {
Serial.begin(9600);
pinMode(blitz, OUTPUT);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(analogSwitch, INPUT);
}
void loop() {
switchRead = analogRead(analogSwitch);
//analogWriteResolution(8);
Serial.println(switchRead);
if(switchRead <= 900) {
digitalWrite(green, HIGH);
digitalWrite(red, LOW);
}
if (switchRead >= 2000) {
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
}
else {
digitalWrite(red, LOW);
digitalWrite(green, LOW);
}
}