top of page
  • Writer's pictureKJ Ha

ML4PCOMP Final Assignment

For the final project, I used Teachable Machine sound classifier to create a watering system controlled by voice command. There are three major components of the circuit: soil sensor, water pump, and red LED. I established a two-way serial communication between Arduino and p5.js. so that users can refer to incoming sensor values from the soil sensor.


  • 1 Arduino Uno

  • 1 Soil sensor

  • 1 Mini water pump (DC 3~5V)

  • 1 Silicon tube

  • 1 Red LED

  • 2 Resistors

  • 1 TIP120 Transitor

  • 1 Diode

  • 1 Water tank

Circuit image

Soil sensor is connected to A0, water pump to 13, and soil sensor to 12 respectively.

Teachable Machine Training using 'Water' and 'Stop' as classes.

There are two commands, 'water' and 'stop', 'water' turns on the water pump, and 'stop' would turn off such activation triggering a red LED to light up to indicate suspension of activation.

Link to p5.js sketch

Arduino Code

int waterPin = 13;
int ledPin = 12;
int sensorPin = A0;
float sensorValue;
int time = 10;

void setup() {
   pinMode(waterPin, OUTPUT);
   pinMode(ledPin, OUTPUT);

void loop() {
  if (Serial.available() > 0) {   // see if there's incoming serial data
    int inByte =;
    if (inByte == 1) {
      digitalWrite(waterPin, HIGH);  
      digitalWrite(ledPin, LOW);
    } else if (inByte == 2) {
      digitalWrite(waterPin, LOW);
      digitalWrite(ledPin, HIGH);
    } else {
      digitalWrite(waterPin, LOW);
      digitalWrite(ledPin, LOW);
  sensorValue = analogRead(sensorPin);


Recent Posts

See All

ML4PCOMP Assignment 4

I have two separate ideas for the final project. Similar to the project I did for Intro to Pcomp class, I would like to build a simple watering device using a teachable machine algorithm. The device w


bottom of page