i use arduino wemos d1. It has a 1 analog pin. so i use multiplexer to connect two sensor.
But i have a problem. serial monitor show simple value.
my code is
#define EN 13
#define S0 0
#define S1 2
#define S2 15
#define S3 12
#define SIG A0void setup() {
Serial.begin(115200);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);digitalWrite(S0, LOW);
digitalWrite(S1, LOW);
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);pinMode(EN, OUTPUT);
digitalWrite(EN, LOW);
// put your setup code here, to run once:}
void loop() {
for(int i = 0; i < 2; i ++){
Serial.print(readMux(i));
Serial.print(".");}
Serial.println();
delay(1000);
// put your main code here, to run repeatedly:}
int readMux (int channel) {
int controlPin[] = {S0, S1, S2, S3};
int muxChannel[2][4]={
{0,0,0,0},
{1,0,0,0},
};for(int i = 0; i < 2; i ++){
digitalWrite(controlPin_, muxChannel[channel]);}_
* int val = analogRead(SIG);*
* return val;*
* }*
[/quote]
i use 1 sound sensor, 1 o2 sensor.
o2 sensor is used by this code
> const float VRefer = 3.3;
> const float pinAdc = A5;
>
>
> void setup() {
> Serial.begin(9600);
> Serial.println("O2 Sensor...");
> // put your setup code here, to run once:
>
> }
>
> void loop() {
>
> float Vout =0;
>
*> *
> Serial.print("Vout =");
> Vout = readO2Vout();
> Serial.print(Vout);
> Serial.print(" V, O2 = ");
> Serial.println(readConcentration());
> delay(500);
> }
>
> float readO2Vout()
> {
> long sum = 0;
> for(int i=0; i<32; i++)
> {
> sum += analogRead(pinAdc);
> }
>
> sum >>= 5;
>
> float MeasuredVout = sum * (VRefer / 1023.0);
> return MeasuredVout;
> }
>
> float readConcentration()
> {
> // Vout samples are with reference to 3.3V
> float MeasuredVout = readO2Vout();
>
> //float Concentration = FmultiMap(MeasuredVout, VoutArray,O2ConArray, 6);
> //when its output voltage is 2.0V,
> float Concentration = MeasuredVout * 0.21 / 1.02;
> float Concentration_Percentage=Concentration100;
> return Concentration_Percentage;
_> }_
_>_
_> // put your main code here, to run repeatedly:*_
so, Can i add this code to multiplexer? i want to read O2 concentration, not simple value.
if i can't, tell me different way that i use 2 sensor on arduino wemos d1.