TINKER PiEDESIGN IN INDIA

Battery tester

An INA219 measures the voltage of an AA battery: a full green, half yellow or empty red battery on the matrix, with the volts in the console.

Sensor projectsINA219power

Open in TinkerPie Studio

What you need

Wiring

INA219 → SENSOR port. Battery + → VIN+, battery − → GND, with a 10 Ω resistor from VIN− to GND as a small load.

Step by step

  1. Open Battery tester in TinkerPie Studio. It opens as blocks.
  2. Wire it: INA219 → SENSOR port. Battery + → VIN+, battery − → GND, with a 10 Ω resistor from VIN− to GND as a small load.
  3. Press Run to try it in the simulator. Use the sliders and buttons under the board picture to test it.
  4. 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.
  5. 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 volts;

basic.forever(function () {
  volts = sensors.powerVoltage();
  serial.writeValue('volts', volts);
  if (volts >= 1.4) {
    basic.showLeds('XXXXX.|XXXXXX|XXXXXX|XXXXXX|XXXXX.', Colors.Green);
  } else if (volts >= 1.2) {
    basic.showLeds('XXXXX.|XXX.XX|XXX.XX|XXX.XX|XXXXX.', Colors.Yellow);
  } else {
    basic.showLeds('XXXXX.|X...XX|X...XX|X...XX|XXXXX.', Colors.Red);
  }
  basic.pause(500);
});
Arduino C++ (TinkerPie library)
// Battery tester
// 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 volts = 0;

void setup() {
  tinkerpie::begin();
  basic::forever([]() {
    volts = sensors::powerVoltage();
    serial::writeValue("volts", volts);
    if (volts >= 1.4) {
      basic::showLeds("XXXXX.|XXXXXX|XXXXXX|XXXXXX|XXXXX.", Colors::Green);
    } else if (volts >= 1.2) {
      basic::showLeds("XXXXX.|XXX.XX|XXX.XX|XXX.XX|XXXXX.", Colors::Yellow);
    } else {
      basic::showLeds("XXXXX.|X...XX|X...XX|X...XX|XXXXX.", Colors::Red);
    }
    basic::pause(500);
  });
}

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

More projects like this

Thirsty plant alarmA soil moisture sensor tells TinkerPie when the plant needs water: a sad face and a beep.Sensor projectsUltrasonic 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 projectsIntruder alarmA PIR motion sensor sees someone moving: red flashes and a siren.Sensor projectsWeather station on OLEDA DHT11 measures temperature and humidity; an OLED screen shows them with a bar.Sensor projectsRoom climate on an LCDAn AHT20 sensor and a 16 × 2 LCD. The matrix smiles when the room is comfortable.Sensor projects