I have built the circuit below using mux ICs. In a particular interval the respective selector pins get selected and analog signal from hall sensors are read and give a particular analog value out. There is a total of 30 hall sensors which are represented by HS0
to HS31
.
Multiplexer
Now I wanted to set time as in the table below. After 8000ms I would like it to reset the time automatically and start reading. Can someone tell me which timer example would let me achieve this?
TIME IS ms OUT1 OUT2 OUT3 OUT4
0-1000 HS0 HS8 HS16 HS24
1000-2000 HS1 HS9 HS17 HS25
2000-3000 HS2 HS10 HS18 HS26
3000-4000 HS3 HS11 HS19 HS27
4000-5000 HS4 HS12 HS20 HS28
5000-6000 HS5 HS13 HS21 HS29
6000-7000 HS6 HS14 HS22 HS30
7000-8000 HS7 HS15 HS23 HS31
1 Answer 1
Could you tell us which multiplexer IC you are using? This way, we can help you better. Also, why do you need the 8 second cycle? Does it matter if it's a little shorter or longer? If timing does not have to be very precise it would make things a lot easier.
By the way: you say there are 30 sensors, but your table has 32...
The following pseudocode will not work on your Arduino, but you can use the same structure.
int sensorArray[32] // we will store our 32 sensor values here
// these pins control the multiplexer chips
int selectPinZero = 8;
int selectPinOne = 9;
int selectPinTwo = 10;
// these pins will receive the sensor values from the multiplexer chips
int inputPinOne = 0;
int inputPinTwo = 1;
int inputPinThree = 2;
int inputPintFour = 3;
void setup(){
// make sure the correct pins are inputs and outputs
pinMode(selectPinZero, OUTPUT);
pinMode(selectPinOne, OUTPUT);
pinMode(selectPinTwo, OUTPUT);
pinMode(inputPinOne, INPUT);
pinMode(inputPinTwo, INPUT);
pinMode(inputPinThree, INPUT);
pinMode(inputPinFour, INPUT);
}
// all done, now keep reading the sensors
void loop(){
// set selectPins so that each Multiplexer will output its first channel
digitalWrite(selectPinZero, HIGH); // or low, depending on your Multiplexer IC
digitalWrite(selectPinOne, HIGH); // or low, depending on your Multiplexer IC
digitalWrite(selectPinTwo, HIGH); // or low, depending on your Multiplexer IC
// start reading sensors
int i = 0;
while(i<32){
sensorArray[i] = analogRead(inputPinOne);
i++; // variable i was 0, now 1
sensorArray[i] = analogRead(inputPinTwo);
i++; // variable i was 1, now 2
sensorArray[i] = analogRead(inputPinThree);
i++; // variable i was 2, now 3
sensorArray[i] = analogRead(inputPinFour);
i++; // variable i was 3, now 4
/*
use digitalWrite() on all the selectPins to make the Multiplexer IC output the next channel
*/
delay(1000); // wait 1000 milliseconds
}
/*
this will repeat until all 32 sensors are read and stored in the array
*/
}
This code is by no means optimized, but written to make it easy for you to understand. Good luck!
Explore related questions
See similar questions with these tags.