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.
Components:
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);
Serial.begin(115200);
}
void loop() {
delay(2000);
if (Serial.available() > 0) { // see if there's incoming serial data
int inByte = Serial.read();
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);
}
delay(500);
}
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
delay(300);
}
Demo
Comments