Hi, could someone please point me in the right direction with regards to Analogue Inputs using EOL.
I would like to monitor a switch having 1k in its normal state and triggering when it reaches 2k.
Advice on coding for below and above these values as a SC or OS would also be grateful.
I am sure there is probably a thread on here that may be similar, with so much useful information on here it will take me for ever.
Many thanks in advance
Do you have a circuit designed already?
There is not enough information in your post to formulate a reply.
The ADC in the Arduino measures a voltage, not a resistance. So, you have to create a voltage that is proportional to your resistance to measure. Once you have this circuit and connect this circuit to the Arduino then we can help you with the Software Design.
A simple circuit would be to connect a 1k resistor from the switch to VCC, the junction between the 1k resistor and the switch is also connected to an Arduino Analog input (A0…A5 for UNO), the Other end of the switch is connected to ground.
If this describes your circuit then the following is code that would measure it.
#define SWITCHPIN A0 // circuit connected to A0
#define LOWTRIP 512 // ADC ranges from 0..1023 1K -> 1K(switch closed) becomes 1/2 Vcc or 512
#define HIGHTRIP 682 // 1k -> 2K(switch open) become 2/3 Vcc or 682
#define UNK 0
#define OS 1
#define SC 2
uint16_t swVal=analogRead(SWITCHPIN); //first read is usually off a little
swVal=analogRead(SWITCHPIN); // second reading is better
if(swVal<=LOWTRIP) result = OS;
else if(swVal>=HIGHTRIP) result = SC;
pinMode(SWITCHPIN,INPUT); // no pullup
Serial.begin(9600); // debug to Serial monitor
sw = readSwitch();
Serial.print("Switch is OS");
Serial.print("Switch is SC");
but if the circuit does not match what I described, the program will fail.