Hi
I am trying to program the arduino so that from a single analogue input i get a direct reading from the LM35 and from a second analog input i get another reading from the same sensor but passing through the 4066.
N.B. The 4066 IC is a QUAD BILATERAL SWITCH FOR TRANSMISSION OR MULTIPLEXING OF ANALOG OR DIGITAL SIGNALS. I am going to use this so that the reading i am getting it passes through a different gain. And due to a control switch included in the 4066 i could bypass to whatever gain circuit i want.
In the case i am going to post (note this is just testing) i should get the same reading since i am not bypassing the 4066 reading through no gains.
Due to propagation delay of the 4066 IC i do not get the same reading so i made a simple calculation with the following algorithm.
original signal = read from sensor;
4066 signal = 4066 signal - (4066 signal - original signal);
So example with this algorithm: if i get 40 on the original and 30 on the 4066 i make 40 - 30 to get the difference then subtract again from the 4066 so that i get the two signals to 30.
I programmed this algorithm to be printed on an LCD display and even get a value on the serial monitor.
The code is the following:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float tempS;
float tempC;
float diff;
int ic = 0;
int lm = 1;
int a=0;
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("Sens:");
lcd.setCursor(0,1);
lcd.print("4066:");
}
void loop ()
{
a++;
tempS = analogRead(lm);
tempS = ((5.0*tempC*100.0)/1024.0);
Serial.print(a);
Serial.print(".");
Serial.print("\t");
Serial.print("Sensor: ");
Serial.print(tempS);
Serial.print("\t");
lcd.setCursor (7, 0);
lcd.print(tempS);
tempC = analogRead(ic);
tempC = ((5.0*tempC*100.0)/1024.0);
diff = tempC -tempS;
tempC = tempC-diff;
Serial.print("HCT4066: ");
Serial.print(tempC);
Serial.print("\t");
lcd.setCursor(7, 1);
lcd.print(tempC);
Serial.print("Diff: ");
Serial.print(diff);
Serial.print("\n");
delay(1000);
}
Strange is that on the serial monitor i get:
1. Sensor: 0.00 HCT4066: 0.00 Diff: 40.04
2. Sensor: 0.00 HCT4066: 0.00 Diff: 40.04
and on the LCD display i get:
Sens: 00.00
4066: 00.00
Can you please help me out why is this happening, as you can see my understanding of the problem is correct so i get the same signal, so why is it showing only 0??
More over since the difference is nearly always the same i got the 40.04 and subtracted this from the 4066 signal but strange again the sensor signal decreased drastically (which it shouldn't since i am not doing any calculation) and the difference has changed.
Can you please help me figure out this problem?
Thanks & Regards
Combinu