Hi! I'm a newbie on this stuff and been recently fiddling around with some Arduino projects. My idea is to build a humidity/temperature data logger like the one described here (this particular project doesn't include a data logging module but you get the idea): Arduino DTH22 Humidity Temperature With LCD I2C 16x2 Display | Arduino Project Hub
I had the idea of including a physical on/off switch to the LCD display in order to save the batteries. Since it is going to stay in a room with limited access there is no reason to keep it constantly on. There is a simple diagram (https://www.arduino.cc/en/Tutorial/Button) teaching how to turn an LED on and off with a simple button and I've been wondering if I can use the same code for the 16x2 LCD display. Is this possible?
Yes, you can turn the backlight of a standard 1602 LCD on and off under program control. You can also control the brightness of that backlight if you use an output pin the supports PWM. It does require a transistor or mosfet to act as the switching device. If you buy the LCD with an I2C interface, sometimes called a "backpack", the transistor is usually on the module.
I would recommend you use the I2C interface as the are very inexpensive and reduce the number of i/o pins required to control the display from at least six (seven with the backlight control) down to two. This gives you more I/O pins with which to add features to your projects.
Here's a link to a US based supplier, a regular poster here on this forum that has the LCD's and I2C interfaces. Adding the controller to the LCD adds $0.50 to the total cost.
Yes, you can use a pushbutton to turn the backlight on and off but the code would be different if using an I2C interface. The library used to control the LCD provides the on/off methods, you read the pushbutton and then call the library function which turns the led on and off.
Thanks for the tips! I've already purchased the I2C module to combine with the LCD so I can save some pins for other stuff.
I'm trying to assemble the project but I keep getting the same error message from the console:
<<<error: redefinition of 'LiquidCrystal_I2C lcd'>>>
I made a simple assemble with just the lcd using the following line LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE) and it worked just fine but when I try to combine it with the DHT sensor o get the error message from above. Do you have any idea of what is going on?