Machine learning in PCOM – Week 02

I trained my Teachable machine model of sound and this is my p5 sketch.

Guidance: https://github.com/yining1023/Machine-Learning-for-Physical-Computing/tree/master/Examples/TeachableMachineArduino

Process:

-Teachable machine(TM) training for sound -> ‘Export model’ -> ‘Update my cloud model’ & copied my link’ ->go p5sketch -> copied my link in ‘mySoundModelURL’ -> in ‘results[0].label’, put the my class name of TM -> open Aruduino and put the code and connect the board -> open P5 serial app(just open) -> Say!

Go : Red LED turn on / Yellow LED turn off

Stop: Yellow LED turn on / Red LED turn off

To further, When I shout ‘one and two’ with a simple sound, I want to turn on and off the lights in my room.

Arduino code:

int ledPin1 = 2;
int ledPin2 = 3;

void setup() {
  pinMode(ledPin1, OUTPUT);  // sets the pin as output
  pinMode(ledPin2, OUTPUT);
  Serial.begin(9600);        // initialize serial communications
}
 
void loop() {
 if (Serial.available() > 0) { // if there's serial data available
   int inByte = Serial.read();   // read it
   if (inByte == 1) {
     digitalWrite(ledPin1, HIGH);  // use it to turn on the LED 1
     digitalWrite(ledPin2, LOW);
   } else if (inByte == 2) {
     digitalWrite(ledPin2, HIGH);  // use it to turn on the LED 2
     digitalWrite(ledPin1, LOW);
   } else {
     digitalWrite(ledPin1, LOW);  // sets the LED off
     digitalWrite(ledPin2, LOW);  // sets the LED off
   }
   delay(200);                // waits
 }
}