Connecting to Various Sensors

Below is a guide to hooking up a range of sensors found in the Sensors and Servo Experimenters Pack Kickstarter reward. It is also a helpful reference for those interested in hooking up various sensor to the Robot Core v1.2 board. If you find any instructions that are incorrect or need clarification drop us a email at our Contact Us Page.

Connecting a HC-SR04 

This is a cheap but effective ultrasonic senor for detecting distances. The sensor is simple to connect just make sure to check that the wiring is correct. You will need a HC-SR04 sensor and a 4 pin jumper wire. I like to keep the color red towards +voltage (vcc) to make things uniformed.

Remember the board features the following for this sensor type:

  • Up to 4 HC-SR04 ultrasonic modules supported
  • Filtered readings can be used for better accuracy, unfiltered readings can be used for faster readings
  • Readings are converted into millimeters by the provided library













Connecting a TMP36 Temperature sensor

Simply connect Pin 1 to +5volts, Pin 2 to any Analog input 1-8 on the Robot Core board and Pin 3 to GND.


The TMP36 is a low voltage, precision centigrade temperature sensor. It provides a voltage output that is linearly proportional to the Celsius temperature. It doesn’t require any external calibration to provide typical accuracies of ±1°C at +25°C and ±2°C over the −40°C to +125°C temperature range.

Once connected I then opened program to verify the sensor was working.



Connecting the Piezo Vibration Sensor

Lucky this is yet another analog sensor that is easy to connect to the Robot Core board as it creates it’s own power that can be read by the on-board 16bit Analog to Digital converter.

– Connect a 1Mohm resistor across the Piezo sensor’s pins.
– Connect one leg of the Piezo to GND
– Connect the other leg of the piezo to Analog input 8 (or  1 though 7)

The resistor helps smooth out some of the voltage spikes to safer levels as the sensor can output almost +20V and -12V if you flick the sensor.

I then simply opened program (right click and run in Python 2 (IDLE)  and adjusted the Time.sleep variable to Time.sleep(0.02). You then can click run and run module. I found that with a strong flick I can read 1.60 volts with a floating baseline range of .05-.1 volts. Try shaking the sensor to see the voltages go up. If you plot the voltages over time during normal operation you can establish a baseline. From their you should be able to find a “vibration threshold” for your specific project.

Congratulations you have just added another sensor to your every growing inventory.

Below is a screenshot of the sensor being read on analog input 8.



Connecting a Tilt sensor AT407

This sensor uses a tiny metal ball to make contact with internal pins when upright however when tilted to the side there is no contact between the pins. As this is a sensor that has two states, either on or off it is best to connect straight to the Pi via the on board digital pins.

Hookup Diagram:







Also connect a LED to Pin 40 on the Raspberry Pi.

We will need to write a small test program in python to test the switch

sudo nano
then copy python code and paste the code into
Then type Ctrl X and select Yes to save the file. Then press enter

import RPi.GPIO as GPIO
import time

sensor_pin = 38
led_pin = 40



GPIO.setup(sensor_pin, GPIO.IN)

current_state = 0

while True:
current_state = GPIO.input(sensor_pin)
if current_state == 1:
print("ball tilt sensor value is %s" % (current_state))
print("ball tilt sensor value is %s" % (current_state))

except KeyboardInterrupt:

Finally, you can run the following command in shell window:

sudo python