2

I have set up a BMP180 and a DHT11 to display data on an HD44780 20x4 LCD.

enter image description here

I want to be able to toggle the altitude from meters to feet, the temperature from Celsius to Fahrenheit, and the pressure from absolute to sea level pressure using a tactile push button.

Here is the software code I have:

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <SFE_BMP180.h>
#include<dht.h>
dht DHT;

#define DHT11_PIN 8 // Second pin, leave 3rd pin unconnected 4th is ground
#include <SFE_BMP180.h>
#include <Wire.h>

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

#define ALTITUDE 237.0 // Altitude of Phillaur in Punjab, India. in meters

void setup() {
  lcd.begin(20, 4);
  lcd.setCursor(0, 0); // Zeroth Row
  lcd.print("hello, world!");
  lcd.clear();
  int chk = DHT.read11(DHT11_PIN);
  // Initialize the sensor (it is important to get calibration values stored on the device).
  if (pressure.begin()) {
    lcd.print("BMP180 init Success");
    delay(300);
  } else {
    lcd.print("BMP180 init fail");
    while (1); // Pause forever.
  }
}

void loop() {
  char status;
  double T, P, p0, a;
  lcd.clear();
  lcd.setCursor(0,0);
  //TODO Display in Feet as well using toggle
  lcd.print("Altitude: ");
  lcd.print(ALTITUDE, 0);
  lcd.print(" mtrs ");
  status = pressure.startTemperature();
  if (status != 0) {
    // Wait for the measurement to complete:
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0) {
      // Print out the measurement:
      Serial.print("temperature in deg C, From BMP180: ");
      lcd.setCursor(0, 1);
      lcd.print("Tmpratre: ");
      lcd.print(T, 2);
      lcd.print("'C");
      lcd.setCursor(0, 2);
      lcd.print("Humidity: ");
      lcd.print(DHT.humidity, 1);
      lcd.print("%");
      status = pressure.startPressure(3);
      if (status != 0) {
        // Wait for the measurement to complete:
        delay(status);
        status = pressure.getPressure(P, T);
        if (status != 0) {
          lcd.setCursor(0,3);
          // Print out the measurement:
          lcd.print("Pressure: ");
          lcd.print(P * 0.0295333727, 2);
          lcd.print(" mb");
          p0 = pressure.sealevel(P, ALTITUDE);
          // we're at 234 meters (Phillaur, Pb)
          // TODO: toggle to sea level to absolute pressure
          Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0, 2);
          Serial.print(" mb, ");
          Serial.print(p0 * 0.0295333727, 2);
          Serial.println(" inHg");
          a = pressure.altitude(P, p0);
          Serial.print("computed altitude: ");
          Serial.print(a, 0);
          Serial.print(" meters, ");
          Serial.print(a * 3.28084, 0);
          Serial.println(" feet");
        } else Serial.println("error retrieving pressure measurement\n");
      } else Serial.println("error starting pressure measurement\n");
    } else Serial.println("error retrieving temperature measurement\n");
  } else Serial.println("error starting temperature measurement\n");
  delay(5000);  // Pause for 5 seconds.
}
8
  • 1
    And what part of that "I want" is it you are having problems with, if any?
    – Majenko
    Oct 28, 2016 at 14:17
  • Hooking the tactile button to LCD using arduino UNO :( Oct 28, 2016 at 14:23
  • 2
    Well, you don't. You hook the button to the Arduno. It's then up to your software to decide what to do with it.
    – Majenko
    Oct 28, 2016 at 14:23
  • 2
    Which part? Wiring the button up, or changing your program?
    – Majenko
    Oct 28, 2016 at 14:27
  • 2
    To wire the button up you need two wires - one to an input and one to ground. We can't help you change your program since we don't have your program to know what wants changing. We're not psychic you know (well, most of us aren't)
    – Majenko
    Oct 28, 2016 at 14:29

1 Answer 1

2

You need to connect the button(s) to available digital inputs of the Arduino. I suggest that you use more than one button based on your description in the question.

The following tutorial describes the circuit needed and the associated code to read that input. All you have to do is duplicate it with a few more buttons on separate (available) digital inputs.

Arduino button tutorial

button wiring

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.