Blog - Sketching with Hardware

Inputs, Outputs? OK…. Sensors? Actuators? YAY!

Published on: | Author: Florian Mathis | Categories: 2018a, Tutorials

The following blog post gives you an introduction to input/output pins and shows you basic examples of sensors and actuators we used in our class and how some teams used them in their projects.

The fact that an Arduino can obtain sensor values very simple is one of the features that makes these single-board microcontrollers so powerful.

The pins on the Arduino can be configured as inputs (digital/analog) or as outputs (digital/analog). The default state is input – so there is no need to explicitly declare the pins as inputs.

Let’s start with an INPUT Pin (= high impedance state)… 

There are two different ways to steer an input to a known state if no input is present. In class Bernhard told us both options:

Option 1:
  • adding a pullup resistor (to +5V)
  • or a pulldown resistor (resistor to ground) in the input.
Option 2:

Since the Arduino is awesome (YAY!) you can access a 20K (or even higher) pullup resistor from software. You can access these built-in pullup resistors by setting the pinMode() as INPUT_PULLUP (care! Behaviour of the INPUT mode is inverted -> HIGH = sensor off, LOW = sensor on).

and go on with an OUTPUT Pin (= low impedance state).

The pins can source up to 40mA of current to connected devices/circuits. As you probably already know, this is enough current to brightly light up an LED or run different sensors, but this won’t be enough to run most relays, solenoids or motors. For this case of applications you need an external power supply.

Hugh, what’s about the digital/analog part?

Analogue reads are very slow, but they tell you fairly precisely what the (relative) voltage on a pin is. Compared to analogue reads, digital reads tell you that the voltage is over or under a specified threshold (relative to the supply voltage).

To make it a bit clearer:

  • A light switch is a good example of a digital device. A light switch is either “on” (1) or “off” (0). So you will use digital pin modes when dealing with signals that are either “on” or “off”, such as an LED, a switch, or another digital IC.
  • A potentiometer has a range of resistance (from none to some maximum value). So it can have values between 1 kΩ and 10 kΩ for instance. So you use a analog input when you want to read the voltage potential of something. But be careful, analog outputs are not really analog at all on the Arduino. Instead, the Arduino uses something called PWM to create a pseudo-analog signal.

If you read in a digital pin with digitalRead() you will get HIGH or LOW. If you do the same with analogRead() you will get any number between 0 and 1023.

Okay – that’s enough. Let’s jump into something you can SEE, FEEL or DESTROY (hopefully not).

Sensor? Actuators? 

What are Sensors? Sensors are devices that convert a physical quantity, such as temperature or pressure, into an electrical quantity. There are many different types of sensors:

  • Light sensor
  • Motion sensor
  • Temperature sensor
  • Magnetic field sensor
  • Gravity sensor
  • Humidity sensor
  • Vibration sensor

Actuators – as the name already says – are “active objects”. For instance motors, servos or steppers. There are many different types of actuators:

  • Motors
  • Servos, Steppers
  • Speakers
  • Solenoids
  • LEDs (RGB)
  • Piezos

Sensors in a nutshell

(which are 100% available during the workshop)

Sensor Model additional information
Motion sensor HC-SR501 [LINK] There is 100% one – somewhere – but maybe it’s not so easy to find one. 🙂
Temperature sensor DHT11 [LINK] With the DHT 11 you can measure temperature and humidity.
Light sensor A 9013 THT (for instance) [LINK] There is a huge set of different photo-resistors.
Humidity sensor DHT11 [LINK] With the DHT 11 you can measure temperature and humidity.
Distance sensor Ultrasonic Sensor HC-SR04 [LINK] You can use the HC-SR04 for measuring distances or just to recognize objects in front of the sensor. (like the garden gnome ;))

Actuators in a nutshell

(which are 100% available during the workshop)

Actuators Model additional information
Motor RF-300CA [LINK] Just watch out for some DC motors. Somewhere I found a RF-300CA.
Servo Tower Pro SG90 Micro Servo 9g [LINK] There is a huge set of various different servos. (watch out for the “Servo-Box” :))
Stepper 28BYJ-48 [LINK]

or Nema 17 – SY42STH47 [LINK]

Use additional to the stepper motor a driver board (X113647 or A4988).
Speaker I’m not sure about the specific models – but there are speakers!
LEDs (RGB) LED strip NeoPixels [LINK] There is also a waterproof strip available.
Piezos Homyl 10 x Piezo-Element (for instance) [LINK] If you ask Bernhard for a Piezo – you’ll get one! 🙂

Now you got an overview of some sensors and actuators. YAY! Let’s go!

Let’s sketch and have fun with sensors and actuators! 🙂 

The following four sections (temperature and humidity sensor, servo motor, stepper motor and ultrasonic sensor) give an overview of the wiring and coding of some selected sensors/actuators. At the end of every section, you will find example implementations of some project-teams in Sketching with Hardware WS17/18.

Get temperature and humidity with the DHT11 sensor:

The DHT11 sends the temperature and humidity readings as serial data (not as an analogue signal), so the data pin is a digital pin, not an analogue pin. Hugh! So just connect the data pin to a digital pin on your Arduino. Do not forget to make sure to download and install the DHT library first. You can do this directly in the Arduino IDE [Sketch -> Include Library -> Manage Libraries -> Install (DHT sensor library)].

Click here to see an example wiring and the corresponding code

corresponding arduino code: Download example code


  • 1x Arduino UNO
  • 1x Breadboard
  • 1x DHT11 sensor
  • 3x Jumper wires

I’m sure you want to know what you can build with this awesome sensor! In Sketching with Hardware 2017/18 two project groups used such a temperature/humidity sensor. (in the end there was just one group which used the DHT11 sensor, because the other team designed their own humidity sensor – they did a great job and it worked very well!)

Team 7 used their own humidity sensor to control the water supply.  They just measured the current between to metal parts. By setting some thresholds it was very easy to distinguish dry or wet soil – nice solution!


For further information about each specific project just check out the corresponding blog post!

Team 5 used the DHT11 sensor  for Hans. Hans is a plant. Hans is afraid of water. Hans goes back to his house when it is cold and rainy. Hans is smart. Be like Hans.


For further information just check out their blog entry – but first, guess in what kind of house Hans lives? Check the roof! 😉

Use a servo motor (this little “thing” can be awesome and fits in almost every project 😉 ):

A servo motor allows a precise control of the angular position, velocity, and acceleration. Servos are essential parts if we need to control the position of objects, rotate sensors, move arms and legs of robots, and more. As you will see later at the projects, a servo can be very useful! (I love them! <3)

Click here to see an example wiring and the corresponding code

The ports of the Tower Pro Micro Servo 9g:

corresponding arduino code: Download example code


  • 1x Arduino UNO
  • 1x Breadboard
  • 1x Tower Pro Micro Servo 9g
  • 3x Jumper wires

Are you in love with servos? No? Okay, check this out:


Why should we use our thumb to activate the spray, when we can use a Servo? That was the idea of Team 3 (which was my team). Since we built a Hanging Moss-Spray, it was important to activate the spray without directly interacting with the pressure spray. I just checked my Super Starter Kit and found an awesome servo (every servo is awesome!). I applied the servo in front of the grasp to simulate the activation of the pressure spray. It worked very well with the tiny Tower Pro Micro Servo 9g ! But…  in the end we needed more power and swapped the SG90 9g Micro Servo with a more powerful one.



I told you, every servo is awesome! I’m pretty sure that the image is self-explaining and shows the use case of the servo ;).

Wow! A stepper motor!

A stepper motor is even more awesome! Why? Because a stepper motor can move in accurate, fixed angle increments (steps). Servos though, are usually limited to a 0-180 degree range (you can hack it, so a servo is able to make full rotations 😉 ), while stepper motor can rotate continuously, similar to a regular DC motor.

  • steppers achieve much higher precision and control over the movement as DC motors
  • they are a bit more complex to control than servos and DC motors (but still easy!)

For the following example I used a ULN2003 stepper motor driver board, which allows to easily control the 28BYJ-48 stepper motor from a microcontroller, like the Arduino. Make sure to download and install the AccelStepper library first. You can do this directly in the Arduino IDE [Sketch -> Include Library -> Manage Libraries -> Install (AccelStepper)].

Click here to see an example wiring and the corresponding code

corresponding arduino code: Download example code


  • 1x Arduino UNO
  • 1x Breadboard
  • 1x 28BY-48 stepper motor
  • 1x ULN2003 stepper motor driver
  • 10x Jumper wires
  • 1x 9V Battery
  • 1x Battery connector/clip

One use case for using a stepper motor could be to lift up heavy objects – for instance a pressure spray filled with water (~2kg).

To lift up a pressure spray we used two stepper motors (Nema 17 – SY42STH47) which can be very powerful (we had some problems as you can see in the gif – but in the end it worked! ;)).

To control the stepper motors we used the A4988 driver. The A4988 is a microstepping driver for controlling bipolar stepper motors which has built-in translator for easy operation. To tell the stepper motor what he should do we used the AccelStepper library – it’s amazing! You should give it a try!

Distance Sensing with ultrasonic sensor

You want to calculate a distance? Or just want to recognize, if someone is in front of an object? Use an ultrasonic sensor! It emits an ultrasound at 40kHz which travels through the air and if there is an object in its path it will bounce back to the module.

Based on the travel time and the speed of the sound you can calculate the distance. Great? YES! But don’t forget to halve the distance! 😉

Click here to see an example wiring and the corresponding code


You just have to connect VCC(+5V) , GND, one wire for emitting the ultrasound (blue wire) and one wire (yellow wire) for reading in the echo signal to the ultrasonic sensor.

corresponding arduino code: Download example code


  • 1x Arduino UNO
  • 1x Breadboard
  • 1x Ultrasonic Sensor HC-SR04
  • 3x Jumper Wires
  • 1x an object in front of the sensor 😉

The winner of Sketching with Hardware 2017/18 –  A simple garden gnome? No, the most awesome garden gnome you will ever see!

Based on the Ultrasonic Sensors (one on each front, except on the back) the garden gnome moved to the observer (=cat, dog, human, alien, … what?!). After the correct movement he made a photo and decided – based on your smile – if you are allowed to go through. If your smile was not accurate enough something special happend! Check out the blog of the winner project for further information!

If you made it this far, you probably made it into the (next) Sketching with Hardware course – cool!

The Workshop Sketching with Hardware (7 days) was a lot of fun! Many thanks especially to Bernhard Slawik and Beat Rossmy for leading the workshop! I’m sure, there will be a Sketching with Hardware 2.0 soon! 😉

linked categories 2018a, Tutorials


Write a comment


[…] is at the end of this entry. For more in-depth informations you could take a look at my partners blog entry. He’s covered some of the basic toys in a typical Arduino […]