Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
analogRead(gndPin);
delay(100);
analogRead(photocellPin);
delay(100);
int photocellReading = analogRead(photocellPin);
delay(100);
analogRead(gndPin);
delay(100);
analogRead(tempPin);
delay(100);
int tempReading = analogRead(tempPin);
delay(100);
// converting that reading to voltage, for 3.3v arduino use 3.3, for 5.0, use 5.0
float voltage = tempReading * aref_voltage / 1024;
float temperatureC = (voltage - 0.5) * 100;
float voltage1 = photocellReading * aref_voltage / 1024;
// float temperatureF = (temperatureC * 9 / 5) + 32;
//Converts Photocell Reading to Lux Reading, This will be unique for each Sensor and will change between diodes/Photoresistors
// Sensor 12 (C) = y = 626.06x6 - 3395.4x5 + 7395.5x4 - 7264.1x3 + 3743.7x2 - 148.26x
double luxReading = ((626.06*(pow(voltage1,6)) -(3395.4*(pow(voltage1,5))) + (7195.5*(pow(voltage1,4))) - (7264.1*(pow(voltage1,3))) + (3743.7*(pow(voltage1,2))) - (148.26*voltage1)));
Seconds (S) Light (10 bit) Light (lux)
1 244 544.59
2 265 607.21
3 275 638.49
4 251 565.03
5 245 547.49
6 276 641.67
7 256 579.89
8 247 553.3
9 276 641.67
10 272 629
11 254 573.92
12 253 570.95
13 276 641.67
14 254 573.92
15 245 547.49
16 271 625.86
17 276 641.67
18 248 556.22
19 250 562.09
20 275 638.49
Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
#include "Wifly.h"
#include <SoftwareSerial.h>
WiflyClass Wifly(2,3);
int sensors[6];
void setup()
{
Serial.begin(9600);//use the hardware serial to communicate with the PC
bool wifi = true;
if(wifi){
Wifly.init();//Initialize the wifishield
Wifly.setConfig("MyWiFi","12345678");//here to set the ssid and password of the Router
Wifly.join("MyWiFi");
Wifly.checkAssociated();
while(!Wifly.connect("192.168.137.1","40020"));//connect the remote service
Wifly.writeToSocket("Connected!");
}
}
void loop(){
Serial.print("Sensors:");
for( int i = 0 ; i < 6 ; i++ ){
analogRead(i);
delay(10);
sensors[i] = analogRead(i);
Serial.print(sensors[i]);
Serial.print(", ");
delay(30);
}
Serial.println(";");
}
void WiflyClass::init() {
pinMode(WIFLY_RST, OUTPUT);
pinMode(WIFLY_GPIO6, INPUT);
SoftwareSerial::begin(9600);
reset();
unavailConn = 0;
}
Re: Problem reading two sensors with analogRead()
If i set wifi = true, then sensors show me some rubbish, every pin shows value is about 1010, and does not change on differenr ranges.
Re: Problem reading two sensors with analogRead()
adafruit_support wrote:Could be interference from the WiFly radio. Have you posted this over at Sparkfun to see if it is a known issue?
Re: Problem reading two sensors with analogRead()
Nope, they said that they do not support this shield.
Re: Problem reading two sensors with analogRead()
#define tsp 5 //temp sensor input port
#define ADCsamples 64 //Number of temperature sensor values to take for average
float tempCurrent = 0.0; //current temperature
void readTemp() {
float tempFlast = tempCurrent; //For monitoring temperature sensor/ADC noise
float ADCavg = 0.0; //To store average ADC value
float ADCsum = 0.0; //Store sum of ADC samples
for (int i = 0; i < ADCsamples; i++) {
ADCsum += analogRead(tsp);
}
ADCavg=ADCsum / (float)ADCsamples;
float tspVolts = ADCavg * (aRef/1024.0); //convert ADC value to voltage
float tempC = (tspVolts - 0.5) * 100.0; //convert voltage to Centigrate temp for TMP36 temp sensor
float tempF = (tempC * 9.0 / 5.0) + 32.0; //Convert Centigrade to Farenheit
tempCurrent = tempF; //Set current temperature to user expected Farenheit value
Serial.println(tempF - tempFlast); //Output difference from last average
}
Re: Problem reading two sensors with analogRead()
I'm using the default 5v reference,
Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
#include <LiquidCrystal.h>
float Voltage;
float TempC;
int FAN = 9; // FAN Optocoupler (CNY74-2) connected to digital PWM pin 9
int Temperature;
int PAvalue;
int PAVin = 0;
const int LM35 = 0; // analog pin 0 (LM35CZ).
const int PA = 2; // analog pin 2 (PA signal Input).
const int LowTemp = 30; // Setting LOW Temperature setpoint. The Fan reach full speed then temperature is more than 10°C above setpoint.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16,2);
pinMode(FAN, OUTPUT); // Set pin for output to control FAN Optocoupler.
pinMode(TempC, INPUT); // sets analog pin 0 for input
pinMode(PA, INPUT); // sets analog pin 2 for input
}
void loop()
{
Temperature = analogRead(LM35); // read the value from the LM35 sensor
Voltage = Temperature * (5.0/1024); // convert reading to voltage (in V), for 5V input
TempC = ( 5.0 * Temperature * 100.0) / 1024.0; // convert voltage to temperature
analogWrite(FAN, constrain( (TempC - LowTemp) * 25, 0, 255)); // If the temperature is highher than the set point, run the fans.
lcd.setCursor(0,1);
lcd.print(TempC); // Print Celsius temperature to LCD
lcd.print((char)223); // degree symbol
lcd.print("C ");
{
}
PAvalue = analogRead(PA); // read the value from the PA output driver.
float PAVin = PAvalue * (4.5 / 1024.0);
if (PAVin>4)
{
lcd.setCursor(8, 0);
lcd.print("10");
}
else
if (PAVin>3 && PAVin<4)
{
lcd.setCursor(8, 0);
lcd.print(" 8");
}
else
if (PAVin>2 && PAVin<3)
{
lcd.setCursor(8, 0);
lcd.print(" 6");
}
else
if (PAVin>1 && PAVin<2)
{
lcd.setCursor(8, 0);
lcd.print(" 4");
}
else
if (PAVin>0.5 && PAVin<1)
{
lcd.setCursor(8, 0);
lcd.print(" 3");
}
else
if (PAVin>0 && PAVin<0.5)
{
lcd.setCursor(8, 0);
lcd.print(" 2");
}
{
lcd.setCursor(0, 0);
lcd.print("Output:");
lcd.setCursor(11, 0);
lcd.print("Watt");
lcd.setCursor(10, 1);
lcd.print(PAVin);
lcd.setCursor(15, 1);
lcd.print("V");
}
}
Re: Problem reading two sensors with analogRead()
Temperature = analogRead(LM35); // read the value from the LM35 sensor
Temperature = analogRead(LM35); // First time was for practice. Now read it for real.
PAvalue = analogRead(PA); // read the value from the PA output driver.
PAvalue = analogRead(PA); // read it again, just to make sure.
analogReference(EXTERNAL);
Re: Problem reading two sensors with analogRead()