Hi there :D!
Okay so I'm using a CD4067B analogue multiplexer to control several sensor inputs. Now I want to control each channel which represents the different sensors. Below is an example of what I'm getting on the Serial Monitor. I have (0,1,2,3) 4 channels which represent different sensors. I want to be able to convert each of these channel from the voltage to the corresponding units eg.(temperature-degrees, gas -ppm, humidity % etc. ). How can I do that so i could convert those voltage values to the real value??
(Serial Monitor) - Example:
0 = 826 1 = 796 2 = 775 3 = 733
0 = 826 1 = 796 2 = 777 3 = 735
0 = 826 1 = 797 2 = 777 3 = 736
0 = 826 1 = 796 2 = 777 3 = 735
0 = 826 1 = 797 2 = 776 3 = 734
0 = 826 1 = 796 2 = 776 3 = 735
0 = 826 1 = 796 2 = 777 3 = 735
......
Help would be very much appreciated.
This is the code i used:
// This code reads the inputs using a CD 4067B multiplexer
/// the address pins will go in order from the first one:
const int A = 8; // First address pin corresponding to pin 8 on the microcontroller
void setup() {
Serial.begin(9600);
// set the output pins, from the first to the fourth:
for (int pinNumber = A; pinNumber < A + 4; pinNumber++) {
pinMode(pinNumber, OUTPUT);
// set Address pins A,B,C and D to low
//to connect input 0 to the output:
digitalWrite(pinNumber, LOW);
}
}
void loop() {
//loop over all the 4 input channels
for (int Channel = 0; Channel < 4; Channel++) {
setChannel(Channel);
//read the analog input and store it in the value array:
int analogReading = analogRead(0);
//print the result out:
Serial.print(Channel, DEC); // print the channel number
Serial.print(" = "); // insert = sign
Serial.print(analogReading, DEC ); // read the channels
Serial.print("\t"); // Insert tab between each channel
}
// linefeed after channels appear
Serial.println();
delay(500);
}
//Which channel connected to the output:
void setChannel(int whichChannel) {
// loop over all four bits in the channel number:
for (int bitPosition = 0; bitPosition < 4; bitPosition++) {
// read a bit in the channel number:
int bitValue = bitRead(whichChannel, bitPosition);
// pick the appropriate address pin:
int pinNumber = bitPosition + A;
// set the address pin
// with the bit value you read:
digitalWrite(pinNumber, bitValue);
}