Introduction
pH sensors are essential scientific instruments found everywhere from automated water treatment plants and aquarium monitors to advanced chemical testing laboratories! Learn what a pH sensor is, how hydrogen ion concentration translates into measurable analog voltages, how to interface a pH sensor probe with Quarky, and program it with ease in PictoBlox – our Scratch blocks-based graphical programming platform with advanced hardware interaction abilities. Once you’re equipped with the basic knowledge of reading analog sensor values, calibrating baseline voltage levels, and mapping acidic and alkaline ranges, we’ll show you how to monitor real-time water quality and build exciting DIY smart environmental monitoring and hydroponics projects using Quarky.
To work in PictoBlox, you’ll first need to download it from HERE.
Ready? Set. Go!
Prerequisites
- ph4502c pH Sensor to detect the pH in solution.
- LCD 16X2 to display the pH.
- Quarky as the main controller.
- PictoBlox to create and run the program.
- Jumper Wires
How to connect with Quarky
- First, open PictoBloxand select the Block Coding environment.

- Click on the Board tab on the toolbar and select Quarky.

- Connect your Quarky to your computer using a USB cable.

- Next, click on the Connect button and select the appropriate serial port.
- In the top right corner, there is a toggle button named Mode. This button is used to switch between the two working modes of PictoBlox, namely the stage mode and the upload mode.
- Switch to Upload mode by toggling this button. You’ll observe some changes in the UI.

Connection Diagram
ph4502c pH Sensor Connection
Connect the pH Sensor pins to Quarky as follows:
- Connect GND of the pH Sensor to GND on Quarky.
- Connect VCC of the pH Sensor to V on Quarky.
- Connect P0 of the pH Sensor to D1 on Quarky.
LCD 16X2 Connection
Connect the LCD 16X2 Display pins to Quarky as follows:
- Connect GND of the LCD 16X2 to GND on Quarky.
- Connect VCC of the LCD 16X2 to V on Quarky.
- Connect SDA of the LCD 16X2 to D2 on Quarky.
- Connect SCL of the LCD 16X2 to D3 on Quarky.
Note: Refer to the connection diagram for the exact wire placement, pin position, and orientation.
Step-by-Step Block Coding Guide
- Go to the Quarky palette and drag the ‘when Quarky starts up’ block into the scripting area.
- Click on Add Extension.

- Add the ‘initialize LCD‘ block from the Advance Sensors palette.
- Add the ‘initialize pH sensor at ()’ from the Advance Sensors palette. Set the pin input at ‘D1‘.
- Add the ‘clear LCD’ block from the Advance Sensors palette.

- Add the ‘display () at row () and column ()‘ from the Advance Sensors palette. Set the display option to ‘smiley’. For the row, select ‘0‘ and for the column, select ‘0‘ from their respective dropdowns.
- Next, add the ‘display ()‘ block from the Advance Sensors palette. For the display text, enter ‘pH value:‘.
- Add the ‘forever‘ block from the Control palette.

- Go to Variables palette and click on ‘Make a variable‘. For the name, enter ‘ph_value‘.
- Inside the forever block, add a ‘set () to ()‘ block from the Variables palette. Set the variable to ‘ph_value‘ and use ‘get pHValue‘ block from Advance Sensors palette to fetch the value.
- Underneath the ‘set () to ()‘ block, add a ‘move cursor to () and ()‘ block. For the row, select ‘0‘ and for the column, select ‘1‘ from the respective dropdowns.

- Add the ‘display ()‘ block from the Advance Sensors palette. For the display text, use the ‘get pHValue‘ block from Advance Sensors palette.
- Finally, add the ‘wait () seconds‘ block from the Control palette. For the duration, set ‘0.5‘.

- To upload the code, click on the Upload Code button.

Output
Conclusion
In this lesson, we learned how hydrogen ion concentration is translated into measurable analog voltages and how to interface a PH4502C pH sensor probe along with an I2C 16×2 LCD display with Quarky. Using PictoBlox’s Upload mode and the Advance Sensors extension, we explored how to configure digital pin D1 for sensor signal acquisition and pins D2 and D3 for real-time LCD communication. We created a continuous polling loop to update our tracked ph_value variable and display live water quality readings directly onto the screen. With these core principles of scientific chemical sensing, calibration, and alphanumeric display interfacing mastered, you are now fully equipped to build automated water treatment systems, smart aquarium monitors, and advanced DIY hydroponics projects using Quarky!


