Example Code for UNIHIKER K10&M10 - Ultrasonic Sensor

Last revision 2026/02/03

Code examples for UNIHIKER with ultrasonic sensors.

Hardware Preparation

If Using UNIHIKER K10

  • UNIHIKER K10 * 1
  • Multi Function Expansion Board for UNIHIKER * 1 (Both “For the UNIHIKER K10-Only” and “For the UNIHIKER K10 & M10” are supported, but “For the UNIHIKER K10 & M10” is recommended, as it allows for easier program uploading and debugging even when using only the K10)

If Using UNIHIKER M10

Note: The multi-functional expansion board requires separate power supply when IN use. It can be powered by installing an 18650 battery or from the USB IN of the expansion board, and the PWR power supply switch needs to be turned on.

Extra hardware

Hardware Connection

Use UNIHIKER K10 & Mind+

Use UNIHIKER K10 & Arduino IDE

#include "unihiker_k10.h"
#include "DFRobot_UnihikerExpansion.h"

DFRobot_UnihikerExpansion_I2C eunihiker(&Wire) ;
UNIHIKER_K10 k10;
uint8_t screen_dir=2;

void setup() {
	k10.begin();
	while(!eunihiker.begin()){delay(1000);}
	k10.initScreen(screen_dir);
	k10.creatCanvas();
}
void loop() {
	k10.canvas->canvasText(eunihiker.getSr04Distance(), 1, 0x0000FF);
	k10.canvas->updateCanvas();
	delay(1000);
}

K10 Result

Use UNIHIKER M10 & Mind+

Use UNIHIKER M10 & Python

import sys
sys.path.append("/root/mindplus/.lib/thirdExtension/drobot_yeezb-unihikerioexpansion-thirdex")
import time
from unihiker import GUI
from pinpong.board import Board
from dfrobot_unihiker_expansion import UnihikerExpansion


u_gui=GUI()
Board("").begin()

eunihiker = UnihikerExpansion()
while True:
    us=u_gui.draw_text(text=eunihiker.get_sr04_distance(),x=0,y=0,font_size=20, color="#0000FF")
    time.sleep(0.5)
    u_gui.clear()

M10 Result

Was this article helpful?

TOP