Continued from my first project (First Arduino Project )
This time i was able to connect 2 more sensors, bring total to 3.
Not sure what happened but sensor B was reading "correctly" (3-4 degree difference from Sensor A that was right next to it) and now it's reading 185 and won't change. Not sure what I did there.
Sensor C is a analog sensor from a kit I bought that provided very little info on the sensors. So i just googled how to convert analog to Celsius, pretty sure I found the wrong formula for it. and it wont change either.
The goal of this project was to read multiple sensor data and display it on the LCD. Yes the data is inaccurate, which I'll work on fixing. All in all I'm calling it a success.
Next project: LCD menu
// Display temp and humidity on LCD
// Display multiple sensor data on LCD
// DHT11 SensorA
#include <SimpleDHT.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd (4,5,6,7,8,9); //pins for RS, E, DB4, DB5, DB6, DB7
//DS18B20 SensorB
#include <DallasTemperature.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// For DHT11 (SensorA)
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int sensor = 10; // sensorA is on pin 10
SimpleDHT11 dht11;
#define LED 11 // LED is on pin 11
// For DS18B20 SensorB
// Data wire is plugged into port 2 on the Arduino
#define SensorB 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(SensorB);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Analog Temp Module SensorC
// select the input pin for the Sensor
int sensorC = A0;
// variable to store the value coming from the sensor
int sensorCValue = 0;
void setup() {
// LCD setup
lcd.begin(16,2);
lcd.clear();
pinMode(LED,OUTPUT); // set led to output
// Start up the library SensorB
sensors.begin();
}
void loop()
{
lcd.clear(); // clear LCD
// SensorA Check
byte temperature = 0;
byte humidity = 0;
if (dht11.read(sensor, &temperature, &humidity, NULL)){
// if sensor shows no data let me know
lcd.setCursor(1,0);
lcd.print("**************");
lcd.setCursor(0,1);
lcd.print("**CHECK SENSOR**.");
delay(1000);
digitalWrite(LED,HIGH); // turn on LED if no data found
return;
}
// convert C to F SensorA
float cA = 0;
float tempA = 0;
cA = temperature;
tempA = (1.8 * cA) + 32;
// convert C to F SensorB
float cB = 0;
float tempB = 0;
cB = sensors.getTempCByIndex(0);
tempB = (1.8 * cB) + 32;
// convert Analog to C to F SensorC
sensorCValue = analogRead(sensorC);
float cC = 0;
cC = ((((sensorC) - 500) * 0.1) * -0.1);
float tempC = 0;
tempC = (1.8 * cC) + 32;
// Display data
digitalWrite(LED,LOW); // turn LED off
// Display Temp and Humidity From Sensor A
lcd.setCursor(4,0);
lcd.print("SENSOR A ");
lcd.setCursor(1,1);
lcd.print(tempA,1);
lcd.print(" F ");
lcd.print((int)humidity);
lcd.print("%");
delay(2000);
// Display Temp From Sensor B
lcd.clear(); // clear LCD for new sensor data
lcd.setCursor(4,0);
lcd.print("SENSOR B ");
lcd.setCursor(1,1);
lcd.print(tempB,1);
lcd.print(" F ");
delay(2000);
// Display Temp From Sensor B
lcd.clear(); // clear LCD for new sensor data
lcd.setCursor(4,0);
lcd.print("SENSOR C ");
lcd.setCursor(1,1);
lcd.print(tempC,1);
lcd.print(" F ");
delay(2000);
}