Categories
TUTORIALS

Using a pH sensor to light up a RGB LED and power a DC motor

Hello Arduino Users!

In this tutorial, we will learn how to light up a RGB LED and power a DC motor using a pH sensor. This tutorial is part of my team’s water quality project. For our project, we will be monitoring sewage outflows using four different water quality sensors (including a pH sensor). We will be creating an aeration wastewater treatment system (powered using a DC motor) and will employ LEDs to signal when the aeration treatment is switched on.

Before getting into the tutorial, let’s briefly explore what a pH sensor does. A pH sensor measures the pH of water-based solutions to determine whether the solution is acidic or basic (alkaline). pH sensors detect pH values by measuring the hydrogen-ion activity of the solution. pH values range from 0-14. Neutral solutions like pure water have a pH value of 7. Solutions that have values less than 7 are deemed acidic and those with values greater than 7 are deemed basic (alkaline).  (Source: Sensorland.com)

To learn about DC motors and RGB LEDs check out these links – Modmypi.com,  Adafruit.com

Now let’s go ahead and set up our tutorial. We will need the following parts :

  • Breadboard x 1
  • 9V or 12V battery x 1
  • Jumper wires x 12
  • 330 ohm resistors x 4
  • Transistor x 1
  • Diode x 1
  • RGB LED x 1
  • DC motor x 1
  • DFRobot analog pH sensor kit x 1
  • Arduino UNO x 1
  • 4 clear glass or plastic containers containing solutions with different pH levels. For this tutorial I have used tap water, salt water, sherry vinegar and diet coke as my test solutions. I leave it up to you to decide what type and how many solutions you want to test.

Note: The DFRobot analog pH sensor kit comes with several components namely a pH electrode, a BNC connector and a pH meter board that has an in-built blue LED to indicate when the pH sensor is on.

Next, we will wire the circuit as per the diagram below. Also, refer the circuit connections instructions provided after the diagram. The instructions will help you understand the wiring in the circuit diagram.

This is what my completed circuit looked like.

In this tutorial I have used the code provided in the DFRobot product website to run the pH sensor. I have added some additional lines of code that will allow us to use the readings from the pH sensor to light up the RGB LED and turn on the DC motor. The RGB LED turns blue when the pH value detected is less than 3, green if the value is greater than or equal to 3 but less than 7 and red if the value is greater than or equal to 7.  The DC motor switches on when the pH value is greater than or equal to 7.

Copy the code provided below into your Arduino IDE.

Take a minute to ensure that all the wiring is as it should be and then run the code. Once you’ve run the code, open the serial monitor. You will see the voltage and pH values displayed.

Your serial monitor should look something like this.

Before we go any further, let’s first calibrate the pH sensor. Open the lid of the pH sensor and dip the sensor into a neutral solution. Record the pH value and calculate the difference between the recorded value and the pH value of 7. Use this difference value as the ‘offset’ value in the code.

Once you’ve set the offset values you can dip your pH sensor into other solutions. It is important to note that if you want to get accurate pH readings, you will have to calibrate the sensor every time you test a new solution (especially if you’re moving from acidic to basic or vice versa). For this tutorial’s demo video (see below) I have dispensed with calibrating while testing different solutions because I’m interested in showing how the pH sensor, RGB LED and DC motor work together. The DFRobot website has some great information on how to calibrate the pH sensor. Click here to check it out.

Demo video

And there you have it! You can tweak the code to test how many ever solutions you want and turn on the RGB LED and DC motor in whatever way you like.

Hope you enjoyed this tutorial!

Leave a Reply

Your email address will not be published. Required fields are marked *