Need help for reading sensor data

I'm doing a project using arduino uno, ultrasonic sensor, lcd and push buttons. I can display the sensor reading on the lcd, but I want to take just the reading on the specific time or every time I pushed a button so it can display a number without continuously changing. Is there any way I can do that?


Please read the advising topic telling how to get the best out of this forum: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum

You just need to encapsulate the LCD display code in a conditional clause; that is an "if" clause.

Something like:

global variables
bool button_pushed = false;

Instantiate your LCD object

setup() {
... whatever you need

loop () {

   button_pushed = YourFunctionToTestandDebounce button() ;
   if ( button_pushed ) {
      output to LCD or serial whatever you need

Research how to debounce a button.

Learn how to write a bool function to return true/false

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.