Newbie in need of some basic advice RE Analogue Inputs EOL Status

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

Lee

Bootelee:
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

Lee

Lee,
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

uint8_t sw;

uint8_t readSwitch(){
uint8_t result=UNK;
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;
return result;
}

void setup(){
pinMode(SWITCHPIN,INPUT); // no pullup
Serial.begin(9600); // debug to Serial monitor
sw=UNK;
}

void loop(){
sw = readSwitch();
if(sw==UNK){
  Serial.print("Switch  Unknown\n");
  }
if(sw==OS){
  Serial.print("Switch is OS");
}
if(sw==SC){
  Serial.print("Switch is SC");
}
}

but if the circuit does not match what I described, the program will fail.

Chuck.

Hi Chuck,

Thanks for the reply, I work in the security industry and I have a simple idea that I would like to create using the Arduino platform.

Apologies about being so vague with regards to circuit design.

I plan on using a 12v power supply for the main circuitry (I believe this is too high to power my Arduino Uno)

What method would you suggest is the best way to get this down to an acceptable level for the inputs.

If I plan on using the same 12v power supply to run the Arduino would it be simpler to fit a voltage regulator to bring the supply voltage down.

In a nut shell the plan is:

Using a 12v power supply to power the Arduino Monitoring a switch as mentioned previously 1k normal and 2k Active Monitoring will begin when a separate switch is triggered (System armed) Output to trigger when input status changes below 1k i.e SC and also 2K or higher

Basically its similar to a very basic alarm panel, I appreciate any guidance and pointers.

I do not expect it to be all done for me, I am currently working my way through some of the basic projects and hope to suck up as much info as I can.

many thanks

lee

An Uno can be powered from 12volt (DC jack), as long as you don't connect "heavy users" to the 5volt pins. Leo..