omfgpwnftw
Published © LGPL

Overly Complicated Bubble Machine

Bubble machine utilizing three servos and a DC motor.

IntermediateShowcase (no instructions)4,143
Overly Complicated Bubble Machine

Things used in this project

Hardware components

Arduino UNO Wifi Rev.2
Arduino UNO Wifi Rev.2
I used a regular Arduino Uno
×1
Breadboard (generic)
Breadboard (generic)
×1
DC Motor, 12 V
DC Motor, 12 V
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
Servo Module (Generic)
×3
Push button, two pin
×1
4xAA battery holder
4xAA battery holder
×1

Story

Read more

Schematics

Bubble Machine Picture 1

Bubble Machine Picture 2

Bubble Machine Picture 3

Bubble Machine Picture 4

Bubble Machine Picture 5

Bubble Machine Wiring JPG

Bubble Machine Wiring

Music for bubble machine

mp3 file if you want to use it

Bubble Machine Code

Python code

This is the python code for playing the music

Code

Bubble Machine Code Arduino

C/C++
#include <VarSpeedServo.h>  //Gives you control of servo speed

//IMPORTANT NOTE: With VarSpeedServo, you can control the degree and speed of the servo. Example: "servo1(76,60,true)" calls servo1, tells it to go to 76 degrees, at a speed of 60 (1=slowest, 255=fastest).

VarSpeedServo servoH; //Base servo for horizontal sweeping motion
VarSpeedServo servoV; //Vertical servo connected to base servo
VarSpeedServo servoW; //Wand servo connected to Vertical servo, controls vertical motion of bubble wand

int in3 = 3;     //IN3 on L298 connected to pin 3
int in4 = 4;     //IN4 on L298 connected to pin4
int pos = 0;     //I think this is left over code from previous trials, but never removed it. Have not tried to run code without this
int button = 11; //Button is connected pin 11
int buttonstate = 0;  
void setup() 
{
 Serial.begin(9600);
 Serial.println("Hi! It's Arduino!");
 pinMode(in3, OUTPUT);
 pinMode(in4, OUTPUT);
 servoH.attach(6);    //Attaches Horizontal Servo to pin 6
 servoV.attach(7);    //Attaches Vertical Servo to pin 7
 servoW.attach(8);    //Attaches Wand Servo to pin 8
 servoH.write(0,255,true); //Initializes Horizontal Servo, 0 degrees, 255 speed (same with next two)
 servoV.write(0,255,true);
 servoW.write(0,255,true); 
 pinMode(button, INPUT);   
 digitalWrite(button, HIGH);

}


void on() //Motor on
{
 digitalWrite(in3, HIGH);
 digitalWrite(in4, LOW);
}


void off() //Motor off
{
 digitalWrite(in3, LOW);
 digitalWrite(in4, LOW);
}


void center() //You will need to adjust the degrees in these settings. This centers the machine according to servo orientation and where my bubble liquid bowl is
{
  servoH.write(76,60,true);
  servoV.write(80,60,true);
  servoW.write(50,60,true);
}


void sweep() //This turns the fan on, sweeps the machine, and turns the fan off. Servo degrees may need adjustment depending on servo orientation
{
 on();
 servoH.write(120,15,true);
 servoH.write(50,15,true);
 servoH.write(90,15,true);
 off();
}


void dip() //You will need to adjust the degrees in these settings. This uses the Vertical servo to raise the Wand servo, 
           //then the wand servo turns the wand downward, Vertical Servo lowers wand servo, raises it up,
           //pauses to let excess fluid drip off, Wand servo raises the wand, Vertical servo lowers. 
{
 servoV.write(80,60,true);
 delay(200);
 delay(1000);
 servoW.write(120,40,true);
 delay(200);
 servoV.write(150,60,true);
 delay(1000);
 servoV.write(100,60,true);
 delay(200);
 servoV.write(150,60,true);
 delay(200);
 servoV.write(80,40,true);
 delay(3000);
 servoW.write(40,60,true);
 delay(200);
 servoV.write(100,60,true);
 delay(200);
}




void loop() 
{
 buttonstate = digitalRead(button);    
 buttonstate == HIGH; 
 center();
 if (buttonstate == LOW) //when button is pushed, it causes a ground, moving the buttonstate to LOW, triggering the loop
 {
  Serial.print('1'); //This is done three times, because otherwise the python program will only play the music every other button press
  Serial.print('1');
  Serial.print('1');
  dip();
  sweep();
  
 }
}

Bubble Machine Python Code for PC

Python
import time
from pygame import mixer #music player
import serial

mixer.init()
mixer.music.load("C:/Users/") #Set this to the directory of the mp3
ser = serial.Serial('COM5', 9600) # set to arduino COM and baud
ser.flushInput()

while True:
    print(ser.read().decode().strip()) #Decodes and prints what Arduino sends
    if str(ser.read().decode().strip()) == "1":  #When '1' is sent from Arduino when the button is pushed initiate loop
        print(ser.read().decode().strip())
        print("here we go!")
        mixer.music.play()
        mixer.music.play()
 

Credits

omfgpwnftw

omfgpwnftw

0 projects • 0 followers

Comments