Skip to content
International Shipping
Wish Lists Cart
0 items

Carnival Swing Ride Project

13 Nov 2023
Carnival Swing Ride Project

Do you remember the carnival swing ride sets that used to eagerly await us at the school gates after classes? Those swings, where a group could hop on simultaneously and enjoy the exhilarating ride, were also a common sight in amusement parks or tucked away in neighborhood corners. Chances are, you've taken a spin on one at least once. Now, we are bringing this traditional playground favorite back to life in an electronic form. Using PicoBricks, a DC motor, and a buzzer, we're inviting you to recreate this classic amusement—whether as a decorative piece, a toy, or creative project ideas tailored to your imagination. Would you like to try this project out and decide where it fits best in your world?

Details and Algorithm​

This code forms the foundation of a Raspberry Pi-supported swing carnival ride project, blending the nostalgia of traditional amusement with modern electronic control. To regulate the swing's speed, it introduces essential variables such as 'motorState' and 'motorSpeed.' The initial motor speed is set to zero as a starting point.

The code consists of two fundamental functions: 'runMotor' and 'stopMotor.' The 'runMotor' function reads the potentiometer's value, converts it into a percentage, and determines the motor's speed. Simultaneously, it displays the carnival swing's speed on an OLED screen. On the other hand, the 'stopMotor' function sets the motor speed to zero, displaying a 'Carnival Stopped' message on the screen. In essence, this code allows for the real-time adjustment of the swing's rotation speed using a potentiometer and provides immediate feedback on the screen.

Initially, the user is greeted with a message instructing them to press a button to start the project swing park. The code then waits for the user to press the button, and when pressed, it toggles the motor's state. Subsequently, based on the motor's state, either the 'runMotor' or 'stopMotor' function is invoked.

In summary, this code employs a button and a potentiometer to control the project swing park, blending a touch of nostalgia with modern electronics. It offers an engaging and interactive experience, allowing users to fine-tune the swing's speed in real-time while enjoying the charm of a classic carnival swing ride.


  • 1xPicoBricks
  • 1xDC Motor
  • Jumper Cables
  • Cardboard
  • Colored Papers
  • 8xRope
  • 1xScissors
  • Caulking Gun

Wiring Diagram​

carnival swing ride diagram

MicroBlocks Codes of PicoBricks​

swing ride microblocks

PicoBlockly Codes of PicoBricks​

carnival swing ride microblocks

MicroPython Codes of PicoBricks​

from time import sleep
import machine
from machine import Pin
from machine import I2C
from picobricks import SSD1306_I2C
import time
import math
from machine import PWM
from machine import ADC

pin_button = machine.Pin(10, machine.Pin.IN)
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)
import math
pot = machine.ADC(26)
motor_1 = PWM(Pin(21))

def runMotor():
    global motorState, motorSpeed
    motorSpeed = round(round( pot.read_u16() - 0 ) * ( 100 - 0 ) / ( 65535 - 0 ) + 0)
    motor_1.duty_u16(motorSpeed * 650)
    oled.text("{}".format("Carnival "), 26, 20)
    oled.text("{}".format("Speed "), 38, 30)
    oled.text("{}".format("%"), 44, 45)
    oled.text("{}".format(motorSpeed), 54, 45)

def stopMotor():
    global motorState, motorSpeed
    motor_1.duty_u16(0 * 650)
    oled.text("{}".format("Carnival"), 32, 15)
    oled.text("{}".format("was"), 50, 30)
    oled.text("{}".format("Stopped"), 35, 45)

motorState = 0
motorSpeed = 0
while (pin_button.value()) == (0):
    oled.text("{}".format("Carnaval Ride"), 10, 5)
    oled.text("{}".format("Press Button"), 15, 45)
    oled.text("{}".format("to Start"), 35, 55)

while True:
    if (pin_button.value()) == (1):
        if motorState == (0):
            motorState = 1
            motorState = 0
    if motorState == (1):

Arduino C Codes of PicoBricks​

#include "ACROBOTIC_SSD1306.h"

#define BUTTON_PIN 10

const int motorPin = 21;
const int potPin = 26;

bool motorState = false;

void stopMotor() {
  analogWrite(motorPin, 0);
  oled.setTextXY(1, 3);
  oled.setTextXY(3, 6);
  oled.setTextXY(5, 4);

void setup() {
  pinMode(motorPin, OUTPUT);
  oled.setTextXY(1, 4);
  oled.setTextXY(2, 6);
  oled.putString("Press Button");
  oled.putString("to Start");

void loop() {
  if (digitalRead(BUTTON_PIN) == HIGH) {
    motorState = true;

  while(motorState == true) {
    int motorSpeed = map(analogRead(potPin), 0, 1023, 0, 99);
    analogWrite(motorPin, motorSpeed * 2.5);
    oled.setTextXY(1, 4);
    oled.setTextXY(3, 5);
    oled.setTextXY(5, 5);
    oled.setTextXY(5, 7);
    if (digitalRead(BUTTON_PIN) == HIGH) {
      motorState = false;


With these creative project ideas that you can easily do on your own with PicoBricks, seize the opportunity to improve yourself a little more in the field of coding every day!

Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Have Questions?

Back In Stock Notification


Product SKUDescription Collection Availability Product Type Other Details

Terms & Conditions

What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
this is just a warning
Shopping Cart
0 items