All programs
IoT - Lab Manual (Simplified) · BCS7O3 IoT (Arduino · C++)

Problem Statement Program 7

Develop a program to read the pH value of various substances like Milk, Lime, and Water.

To interface a pH Sensor with an Arduino Uno board and measure the pH value of different substances. The measured pH value is displayed on a 16×2 LCD Display and classified as Acidic, Neutral, or Basic.

Components Required Hardware

Arduino Uno Board – 1
pH Sensor (or Potentiometer for Simulation) – 1
16×2 LCD Display – 1
10kΩ Potentiometer (LCD Contrast) – 1
Breadboard – 1
Jumper Wires – As Required
USB Cable – 1
Arduino IDE Software

Procedure Step by step

Step 1:

Take an Arduino Uno board, pH sensor (or potentiometer), 16×2 LCD Display, breadboard, jumper wires, USB cable, and a 10kΩ potentiometer.

Step 2:

Connect the Arduino 5V pin to the breadboard positive rail and GND to the negative rail.

Step 3:

Connect the pH Sensor VCC to Arduino 5V.

Step 4:

Connect the pH Sensor GND to Arduino GND.

Step 5:

Connect the Analog Output of the pH sensor to Arduino Analog Pin A0.

Step 6:

Connect the LCD RS pin to Digital Pin 7.

Step 7:

Connect the LCD Enable (E) pin to Digital Pin 8.

Step 8:

Connect the LCD Data Pins D4, D5, D6, D7 to Digital Pins 9, 10, 11, and 12 respectively.

Step 9:

Connect the LCD VSS to GND and VDD to 5V.

Step 10:

Connect the V0 pin of the LCD to the 10kΩ Potentiometer for contrast adjustment.

Step 11:

Connect the Arduino Uno to the computer using a USB cable.

Step 12:

Open the Arduino IDE.

Step 13:

Select Tools → Board → Arduino Uno.

Step 14:

Select the correct COM Port.

Step 15:

Copy and paste the Arduino program.

Step 16:

Compile and upload the program.

Step 17:

Observe the pH value on the LCD.

Step 18:

Test different substances such as Milk, Lime, and Water (or simulate using a potentiometer) and observe the classification.

Circuit Connection Wiring

pH Sensor VCC → Arduino 5V
pH Sensor GND → Arduino GND
pH Sensor Analog Output → Arduino Analog Pin A0
LCD RS → Arduino Digital Pin 7
LCD Enable (E) → Arduino Digital Pin 8
LCD D4 → Arduino Digital Pin 9
LCD D5 → Arduino Digital Pin 10
LCD D6 → Arduino Digital Pin 11
LCD D7 → Arduino Digital Pin 12
LCD VDD → Arduino 5V
LCD VSS → Arduino GND
LCD V0 → 10kΩ Potentiometer
Arduino 5V → Breadboard Positive Rail
Arduino GND → Breadboard Negative Rail

Circuit Diagram 1 image

Download the clean, watermark-free circuit diagram — ₹1.00

Arduino Code (C++) Source

program7.cpp
#include <LiquidCrystal.h>

// Initialize LCD (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

#define pH_PIN A0

void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600);

  lcd.print("Simulating pH");
  delay(2000);

  lcd.clear();
}

void loop()
{
  int sensorValue = analogRead(pH_PIN);

  float voltage = sensorValue * (5.0 / 1023.0);

  float pHValue = voltage * 2.8;

  lcd.setCursor(0, 0);
  lcd.print("pH Value: ");
  lcd.print(pHValue);

  lcd.setCursor(0, 1);

  if (pHValue < 6.5)
  {
    lcd.print("Acidic (Lime)");
  }
  else if (pHValue > 7.5)
  {
    lcd.print("Basic (Soap)");
  }
  else
  {
    lcd.print("Neutral(Water)");
  }

  Serial.print("pH Value: ");
  Serial.println(pHValue);

  delay(2000);
}
Protected content · © VTU Developer · Unauthorised distribution is prohibited