Visitor counter dashboard
An ultrasonic sensor at the door counts people walking past. The total shows live on the phone; RESET starts again.
What you need
- TinkerPie V1 board (or the free online simulator)
- USB-C data cable
- Ultrasonic distance HC-SR04
- A 2.4 GHz Wi-Fi network and a phone
Wiring
Put your Wi-Fi name and password in the first block. Then open the address shown in the console on a phone on the same Wi-Fi. HC-SR04P: TRIG → S1, ECHO → S2, across the doorway.
Step by step
- Open Visitor counter dashboard in TinkerPie Studio. It opens as blocks.
- Wire it: Put your Wi-Fi name and password in the first block. Then open the address shown in the console on a phone on the same Wi-Fi. HC-SR04P: TRIG → S1, ECHO → S2, across the doorway.
- Press Run to try it in the simulator. Use the sliders and buttons under the board picture to test it.
- Type your Wi-Fi name and password into the connect to Wi-Fi block.
- 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.
- 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
var visitors, cm, near;
dashboard.onButton('RESET', function () {
visitors = 0;
dashboard.show('Visitors', visitors);
});
basic.forever(function () {
cm = sensors.ultrasonicCm(Pin.S1, Pin.S2);
if (cm > 0 && cm < 60) {
if (!near) {
visitors = (typeof visitors === 'number' ? visitors : 0) + 1;
dashboard.show('Visitors', visitors);
music.beep();
}
near = true;
} else {
near = false;
}
basic.pause(100);
});
visitors = 0;
near = false;
basic.showIcon(IconNames.Square, Colors.Blue);
wifi.connect('my-wifi', 'my-password');
dashboard.show('Visitors', 0);
basic.showIcon(IconNames.Yes, Colors.Green);Arduino C++ (TinkerPie library)
// Visitor counter dashboard
// 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;
double visitors = 0;
double cm = 0;
bool near = false;
void setup() {
tinkerpie::begin();
dashboard::onButton("RESET", []() {
visitors = 0;
dashboard::show("Visitors", visitors);
});
basic::forever([]() {
cm = sensors::ultrasonicCm(Pin::S1, Pin::S2);
if (cm > 0 && cm < 60) {
if (!near) {
visitors += 1;
dashboard::show("Visitors", visitors);
music::beep();
}
near = true;
} else {
near = false;
}
basic::pause(100);
});
visitors = 0;
near = false;
basic::showIcon(IconNames::Square, Colors::Blue);
wifi::connect("my-wifi", "my-password");
dashboard::show("Visitors", 0);
basic::showIcon(IconNames::Yes, Colors::Green);
}
void loop() {
tinkerpie::loop(); // runs the forever blocks and handles events
}More projects like this
Ultrasonic rulerMeasures how far your hand is, in centimetres, with an HC-SR04 sonar.Sensor projectsSmart dustbin lidWave over the bin: a servo opens the lid for two seconds, then closes it.Sensor projectsGarage parking helperUltrasonic distance on a 4-digit display. A buzzer module beeps faster as the car gets close, and stays on under 10 cm.Sensor projectsHeight measurerFix an ultrasonic sensor 200 cm above the floor, pointing down. Stand under it and it tells your height.Sensor projectsPhone weather stationTemperature, humidity and light from the board, live on your phone.IoTPhone-controlled robotButtons on your phone drive a two-wheel robot. The slider sets the speed.IoT