Serial command and carriage return

I have an Atlas Scientific ph probe with it own imbedded code which works fine. In order to calibrate the probe to say ph 7 you go to your serial monitor and type
cal,mid,7 then return. I am going to enclose the mega board in a box where there will be no access to the usb so i would like to introduce a button where when HIGH issues the same command so that calibration can be carried out without the mega being connected to my computer and serial monitor.
Any ideas how to do this?

Hi @Proietti .

Please, for not an infinite exchange of messages, first read the topic:
How to get the best out of this forum

and then help us to help you.
Information about your project.
For example the datasheet of the product used.

RV mineirin

Very simple, but you want to detect when the button becomes pressed (not when it is in a certain state), then send the message with Serial.print().

Study the State Change Detection Arduino example to learn how to do that.

It is better practice to have a LOW when the button switch is pressed. That uses the internal pullup resistor.

See my addendum to the state change detection example showing how to do the state change detection with an active LOW (wired to ground) button switch.

I think you are misunderstanding my question. I know how to code a button. that is not the issue. my question is if i have something like this:

    if (digitalRead(PHCAL1) == 1 && digitalRead(PHCAL2) == 0)

Will this work as if you are within the serial monitor typing "cal,mid,7 and the carriage return"?

Also there is no data sheet for this product. It is an Atlas Scientific PH probe with their shield which has embedded code within. It connects to the mega via serial3 and you issue commands via the serial monitor via serial.

I got it! Here is the answer for others if needed

if (digitalRead(PHCAL1) == 1 && digitalRead(PHCAL2) == 0)
      Serial3.print("cal,mid,7");      //Atlas scientific calibration command
      Serial3.print('\r');                   //Carriage return to execute the command

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