This IoT project utilizes PubNub API to control a small robot car and receive collected ultrasonic sensors data from anywhere in the world in real time!
Github Repository: https://github.com/megatran/pubnub_iot_tinkering
Setup
- Linux machine
- A basic robot or a chassis from an old RC car
- 5V Portable Power Bank to power raspberry pi via USB
- 9V Li-ion battery to power motors
- H-Bridge L298N to control motors
- Ultrasonic sensors HR-S04, 1k and 2k resistors
- Lots of jumper wires (male to female, male to male, female to female…)
- Motors
- Raspberry Pi 2 Model B
- Python 3 or 2
- PubNub 3.9.0
- RPi.GPIO
- [curses] (https://docs.python.org/2/library/curses.html)
Wiring
See below pictures:

Wiring
– Motors and 9V battery to H-Bridge L298N. Then from H-Bridge -> Pi in pins 7,11,13,15
Ultrasonic Sensor Wiring:
https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi
TRIG goes to pin 36 and ECHO is plugged in to pin 38 of the Pi.
– While running the PubNub sender, you should be able to see some instructions in the terminal screen.
– Press the Arrow (up, down, left, right) to control the robot movement.
– Press ‘s’ to pause/stop – Press ‘q’ to quit program
– You should be able to see the sensor data of the distance between the robot and nearyby object in the sender’s terminal screen.
It gets updated in real time thanks to PubNub feature!

Demo pic of two terminals (top left the Pubnub listener is running on the Pi, and on the bottom right, the PubNub sender is sending keyboard value to control the robot in real time.
Future work
– I plan on attaching a webcam to the pi and tinkering with Computer Vision library OpenCV so that I can control the robot far far away while seeing the livestream of what is happening. The OpenCV will add the human facial recognition feature, too!
Recent Comments