hello people !
i use arduino mini 328p and i wanna use 2 dalas 18B20 to show me on my car oil temp and water temp
but only one sensor work ...
change with 1 button 2 rows x 2 rows to LCD.
dalas sensor 1 - D10
Dalas sensor 2 - D11
where is a problem ?
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
// Il terminale data del sensore è connesso
// alla porta 2 di Arduino
#define ONE_WIRE_BUS1 10 //sensor 1
#define ONE_WIRE_BUS2 11 //sensor 2
// Imposta la comunicazione oneWire per comunicare
// con un dispositivo compatibile
OneWire oneWire(ONE_WIRE_BUS1);
// Passaggio oneWire reference alla Dallas Temperature.
DallasTemperature sensors(&oneWire);
// this constant won't change:
const int buttonPin = 9; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(void)
{
// Start up the library
sensors.begin();
// display LCD
lcd.begin(16, 2);
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop(void)
{
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 2 == 0) {
digitalWrite(ledPin, HIGH);
sensors.requestTemperatures(); // Invia il comando di lettura delle temperatura
lcd.setCursor(0, 0); // bottom left
lcd.print("water : ");
lcd.print (sensors.getTempCByIndex(10));
lcd.print(" C ");
lcd.setCursor(0, 1); // bottom left
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
int sensorValue1 = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 15V):
float voltage1 = sensorValue1 / 18.00 ;
lcd.print("volt : ");
lcd.print(voltage1);
lcd.print(" V ");
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
} else {
lcd.setCursor(0, 0);
// read the input on analog pin 7
sensors.requestTemperatures(); // Invia il comando di lettura delle temperatura
// print out the value you read:
lcd.print("Oil temp:");
lcd.print (sensors.getTempCByIndex(11));
lcd.print("C ");
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
int sensorValue3 = analogRead(A3);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 15V):
float voltage3 = sensorValue3 * (18.00);
// print out the value you read:
lcd.print("Oil pres:");
lcd.print(voltage3);
lcd.print("Bar ");
digitalWrite(ledPin, LOW);
}}}
and another problem : data display are not dynamic. change only when the button is pressed and change its state. why?
how to refresh display every 0.1 sec to show curently temp/volt/pressure ?