Sensor and motor control with the GPIO
Linux Format|December 2021
Les Pounder shows how we can take Scratch further with a community-developed tool that builds on our Scratch knowledge.
Les Pounder

YOU NEED

Pi model 3/4/400

The latest Pi OS HCSR04-P

Ultrasonic sensor

L9110S motor controller DC motor

Micro USB breakout PSU for motor

7x F2F wires

2x M2F wires

Internet

Get the code https:// github.com/ lesp/ S3GPIOLXF283/ archive/ refs/heads/ main.zip

Over the past few issues we’ve learnt how to create games, control electronics and create shapes by calculating angles, all with Scratch 3. As good as Scratch 3 is there’s only so much that we can do with the GPIO, and the GPIO is the best feature of the Raspberry Pi. So how can we take our Scratch GPIO projects further? Well, for that we need S3GPIO.

S3GPIO is short for Scratch 3 GPIO and it was created by Simon Walters, a Raspberry Pi community member who’s campaigned for children to learn coding and electronics with Scratch. Walters first foray into the GPIO for Scratch was ScratchGPIO, based upon Scratch 1.4. This version is still active – in fact we can find out more at http://simplesi.net.

In this tutorial we’ll install S3GPIO, learn how to use an ultrasonic sensor as a controller for a DC motor, effectively setting the speed based on our distance from the sensor.

Connecting the electronic components is relatively simple, but the amount of wires may seem confusing. We’ll break it down into sections. S3GPIO uses physical pin numbering, not the BCM numbering standard set by the Raspberry Pi Foundation. This means that we have two columns of 20 pins. Holding the Pi with the USB ports pointing to the floor, the two columns start with pin 1 at the top left, and pin 2 at the top right. The left column is the “odd” column, with pins following an odd number pattern: 1, 3, 5, 7, 9 etc. The right column is the “even” column, with numbers progressing 2, 4, 6, 8 etc.

Our HCSR04-P ultrasonic sensor has four pins. Using female to female jumper wires, connect GND to any GND pin on the Raspberry Pi, Vcc to 3V (Pin 1). Trigger to pin 11, and echo to pin 13.

Continue reading your story on the app

Continue reading your story in the magazine

MORE STORIES FROM LINUX FORMATView All

Zephix 3.0

A fan of portable, modular distros, Mayank Sharma runs across a relatively new one and wonders how it stacks up against his all-time favourite: Slax.

3 mins read
Linux Format
December 2021

Whonix 16

Mayank Sharma is a busy man, but when it comes to privacy and security then, like Louis Armstrong, he has all the time in the world.

3 mins read
Linux Format
December 2021

UBUNTU VS FEDORA

Jonni Bidwell wants to know everything – and he means everything – about the two most popular Gnome-based distros…

10+ mins read
Linux Format
December 2021

SERIAL PERIPHERAL INTERFACE: Driving SPI displays

Let’s go on an adventure into the SPI protocol, LCD displays and model trains with Sean Conway toot-tooting away!

5 mins read
Linux Format
December 2021

Sensor and motor control with the GPIO

Les Pounder shows how we can take Scratch further with a community-developed tool that builds on our Scratch knowledge.

7 mins read
Linux Format
December 2021

LICENCE TO BILL

Jonni Bidwell has been reading licence minutiae and fears big business threatens the future of copyleft and software freedom.

10+ mins read
Linux Format
December 2021

Devuan GNU+Linux

The backlash against Systemd resulted in this sysvinit-friendly distro, now on version 4. Mayank Sharma assesses its progress.

3 mins read
Linux Format
December 2021

AUTOMOTIVE GRADE LINUX

Mats Tage Axelsson shows how open source frameworks and Linux can help navigate you safely to your coding destination.

10+ mins read
Linux Format
December 2021

Atari VCS

Monetising nostalgia should be an easy win for Atari so Matt Safford can‘t believe it’s created another E.T.

3 mins read
Linux Format
December 2021

How To Create Efficient Backups

Backups aren’t just a safety net for Trekkies such as Shashank Sharma, but a way of life. But they can take up quite a lot of space if not done right…

6 mins read
Linux Format
November 2021
RELATED STORIES

Farm-Raised

From Steer to Blueberries and Citrus, Lausanne Walter’s Family Knows Agriculture

3 mins read
Central Florida Ag News
May 2021

El reloj que fue a la luna

Desde su lanzamiento en 1957, el Speedmaster ha pasado por algunos cambios, pero ha logrado mantenerse como uno de los modelos más emblemáticos de Omega y como el reloj oficial de las misiones espaciales.

4 mins read
Esquire Latinoamérica
Junio - 2019

SADDLE SOAR

BMX fan Rydz is riding a high and breaking now bones about it now...

2 mins read
Irish Daily Mirror
December 31, 2021

TUNNEL VISION

The brilliant planning that made World War Two’s Great Escape possible

2 mins read
TV & Satellite Week
November 20, 2021

83 years on, Germany remembers Kristallnacht

GERMAN President Frank-Walter Steinmeier marked the 83rd anniversary of the anti-Jewish pogrom that was labelled Kristallnacht, the Night Of Broken Glass, when Nazis, among them many ordinary Germans, terrorised Jews in Germany and Austria.

1 min read
The Herald
November 10, 2021

Grandsons visit Walter's shrine

THE grieving family of former Rangers manager Walter Smith have visited a shrine outside Ibrox dedicated to him.

1 min read
Daily Record
November 05, 2021

Presidents go for walkies..

EUROPE after Covid and the global vaccination programme were topics discussed between Ireland's President and his German counterpart yesterday.

1 min read
Irish Daily Mirror
October 28, 2021

Eat More - MEDJOOL DATES

You always remember your first good date. One nibble, and you’re courted by a deep caramel flavour, soft texture and delightfully sweet taste. For me, it was love at first bite.

4 mins read
Best Health
August/September 2021

GAEL FORCE

GAEL GARCÍA BERNAL returns to Hollywood for M. Night Shyamalan’s high-concept thriller Old, in which his character starts to age rapidly. It’s got him thinking about his two decades as a globally celebrated actor, and how he’s always done it his way…

8 mins read
Total Film
August 2021

Europe flood toll rises to 170 as searches for missing on

143 people died in the flooding in Germany’s worst natural disaster in more than half a century.

1 min read
The Times of India Hyderabad
July 18, 2021