Hi,
I connected the MQ2 sensor and LCD to arduino and it shows me the MQ2 values.
When the LCD turns on I want it to display my name and when I push the button I want to change it to show the MQ2 values but I don't know how to do it. Is there anyone who could help? Thanks.
(I've already connected the button to arduino)
My code:
#include <Wire.h> #include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define MQ2pin (0)
int sensorValue; //variable to store sensor value
void setup()
{
lcd.begin(16,2);
lcd.backlight();
}
Welcome to the forums. Please read the sticky post at the top to learn how to properly post your code. It will help people help you.
As for detecting your button, there are many examples in the IDE. I would suggest looking at the stateChangeDetection example (File->examples->02.digital->StateChangeDetection).
You also have to have your button wired up properly. Either with a pull-up or pull-down resistor and declare the pin as INPUT_PULLUP to use the internal pull-up resistor