TINKER PiEDESIGN IN INDIA

Teach a robot traffic signs

Teach the camera three cards (green = go, red = stop, blue = turn). The robot obeys the card you hold up.

AI camerateachablemotorsrobot

Open in TinkerPie Studio

What you need

Step by step

  1. Open Teach a robot traffic signs in TinkerPie Studio. It opens as blocks.
  2. Press Run, then Start camera in the AI camera panel and allow the webcam. No webcam? Use the “Pretend here” controls.
  3. Make three cards: a green one, a red one and a blue one (paper is fine).
  4. Keep Recognise on the whole picture. Hold Teach 1 while showing the green card, Teach 2 for the red card, Teach 3 for the blue card.
  5. Also teach the empty background on one of the numbers you use for "stop", so the robot stops when no card is shown.
  6. Connect TinkerPie with a USB-C cable in Chrome or Edge, press Connect, then Download. Or, with Studio started from the TinkerPie launcher on your computer, open the Arduino C++ tab and press Build & Flash.
  7. Change something: a colour, a number, a sound. Then run it again.

The code

This is the program the blocks make. The same program runs in the simulator and on the board.

JavaScript
ai.onLearned(1, function () {
  motors.tank(50, 50);
  basic.showIcon(IconNames.ArrowUp, Colors.Green);
});
ai.onLearned(2, function () {
  motors.stop(Motor.Both);
  led.fill(Colors.Red);
});
ai.onLearned(3, function () {
  motors.tank(-40, 40);
  basic.showIcon(IconNames.ArrowLeft, Colors.Blue);
  basic.pause(700);
  motors.stop(Motor.Both);
});
Arduino C++ (TinkerPie library)
// Teach a robot traffic signs
// Arduino C++ made by TinkerPie Studio from the blocks. Board: TinkerPie V1 (ESP32-S3).
// Arduino IDE: install the TinkerPie library (Studio menu > Arduino library), then Tools > Board > ESP32S3 Dev Module,
// USB CDC On Boot: Enabled, Flash Size: 16MB, Partition Scheme: 16M Flash (3MB APP/9.9MB FATFS), PSRAM: OPI PSRAM.
#include <TinkerPie.h>
using namespace tinkerpie;

void setup() {
  tinkerpie::begin();
  ai::onLearned(1, []() {
    motors::tank(50, 50);
    basic::showIcon(IconNames::ArrowUp, Colors::Green);
  });
  ai::onLearned(2, []() {
    motors::stop(Motor::Both);
    led::fill(Colors::Red);
  });
  ai::onLearned(3, []() {
    motors::tank(-40, 40);
    basic::showIcon(IconNames::ArrowLeft, Colors::Blue);
    basic::pause(700);
    motors::stop(Motor::Both);
  });
}

void loop() {
  tinkerpie::loop();   // runs the forever blocks and handles events
}

More projects like this

Finger counterShow 1, 2, 3… fingers to the webcam and TinkerPie shows the number. Use both hands for up to 10!AI cameraRock, paper, scissorsPlay against TinkerPie with your hand: fist = rock, open hand = paper, peace sign = scissors.AI cameraThumbs-up votingA class vote: thumbs up counts YES, thumbs down counts NO. Button A shows the result.AI cameraHand-controlled servoMove your hand left and right: a servo on S1 follows it, like a robot arm.AI cameraAir pianoRaise and lower your hand in the air to play high and low notes.AI cameraFace greeterWhen someone looks at the camera, TinkerPie smiles and says HI. When they leave, it falls asleep.AI camera