Devices & Components
ARDUINO UNO WiFi REV2
4xAA battery holder
Dual H-Bridge motor drivers L298
Servo Module (Generic)
Breadboard (generic)
DC Motor, 12 V
Push button, two pin
Project description
Code
Bubble Machine Python Code for PC
python
1import time 2from pygame import mixer #music player 3import serial 4 5mixer.init() 6mixer.music.load("C:/Users/") #Set this to the directory of the mp3 7ser = serial.Serial('COM5', 9600) # set to arduino COM and baud 8ser.flushInput() 9 10while True: 11 print(ser.read().decode().strip()) #Decodes and prints what Arduino sends 12 if str(ser.read().decode().strip()) == "1": #When '1' is sent from Arduino when the button is pushed initiate loop 13 print(ser.read().decode().strip()) 14 print("here we go!") 15 mixer.music.play() 16 mixer.music.play() 17 18
Bubble Machine Python Code for PC
python
1import time 2from pygame import mixer #music player 3import serial 4 5mixer.init() 6mixer.music.load("C:/Users/") 7 #Set this to the directory of the mp3 8ser = serial.Serial('COM5', 9600) # set 9 to arduino COM and baud 10ser.flushInput() 11 12while True: 13 print(ser.read().decode().strip()) 14 #Decodes and prints what Arduino sends 15 if str(ser.read().decode().strip()) 16 == "1": #When '1' is sent from Arduino when the button is pushed initiate loop 17 18 print(ser.read().decode().strip()) 19 print("here we go!") 20 21 mixer.music.play() 22 mixer.music.play() 23 24
Bubble Machine Code Arduino
c_cpp
1#include <VarSpeedServo.h> //Gives you control of servo speed 2 3//IMPORTANT 4 NOTE: With VarSpeedServo, you can control the degree and speed of the servo. Example: 5 "servo1(76,60,true)" calls servo1, tells it to go to 76 degrees, at a speed of 6 60 (1=slowest, 255=fastest). 7 8VarSpeedServo servoH; //Base servo for horizontal 9 sweeping motion 10VarSpeedServo servoV; //Vertical servo connected to base servo 11VarSpeedServo 12 servoW; //Wand servo connected to Vertical servo, controls vertical motion of bubble 13 wand 14 15int in3 = 3; //IN3 on L298 connected to pin 3 16int in4 = 4; //IN4 17 on L298 connected to pin4 18int pos = 0; //I think this is left over code from 19 previous trials, but never removed it. Have not tried to run code without this 20int 21 button = 11; //Button is connected pin 11 22int buttonstate = 0; 23void setup() 24 25{ 26 Serial.begin(9600); 27 Serial.println("Hi! It's Arduino!"); 28 pinMode(in3, 29 OUTPUT); 30 pinMode(in4, OUTPUT); 31 servoH.attach(6); //Attaches Horizontal 32 Servo to pin 6 33 servoV.attach(7); //Attaches Vertical Servo to pin 7 34 servoW.attach(8); 35 //Attaches Wand Servo to pin 8 36 servoH.write(0,255,true); //Initializes Horizontal 37 Servo, 0 degrees, 255 speed (same with next two) 38 servoV.write(0,255,true); 39 40 servoW.write(0,255,true); 41 pinMode(button, INPUT); 42 digitalWrite(button, 43 HIGH); 44 45} 46 47 48void on() //Motor on 49{ 50 digitalWrite(in3, HIGH); 51 52 digitalWrite(in4, LOW); 53} 54 55 56void off() //Motor off 57{ 58 digitalWrite(in3, 59 LOW); 60 digitalWrite(in4, LOW); 61} 62 63 64void center() //You will need 65 to adjust the degrees in these settings. This centers the machine according to servo 66 orientation and where my bubble liquid bowl is 67{ 68 servoH.write(76,60,true); 69 70 servoV.write(80,60,true); 71 servoW.write(50,60,true); 72} 73 74 75void 76 sweep() //This turns the fan on, sweeps the machine, and turns the fan off. Servo 77 degrees may need adjustment depending on servo orientation 78{ 79 on(); 80 servoH.write(120,15,true); 81 82 servoH.write(50,15,true); 83 servoH.write(90,15,true); 84 off(); 85} 86 87 88void 89 dip() //You will need to adjust the degrees in these settings. This uses the Vertical 90 servo to raise the Wand servo, 91 //then the wand servo turns the wand 92 downward, Vertical Servo lowers wand servo, raises it up, 93 //pauses 94 to let excess fluid drip off, Wand servo raises the wand, Vertical servo lowers. 95 96{ 97 servoV.write(80,60,true); 98 delay(200); 99 delay(1000); 100 servoW.write(120,40,true); 101 102 delay(200); 103 servoV.write(150,60,true); 104 delay(1000); 105 servoV.write(100,60,true); 106 107 delay(200); 108 servoV.write(150,60,true); 109 delay(200); 110 servoV.write(80,40,true); 111 112 delay(3000); 113 servoW.write(40,60,true); 114 delay(200); 115 servoV.write(100,60,true); 116 117 delay(200); 118} 119 120 121 122 123void loop() 124{ 125 buttonstate = digitalRead(button); 126 127 buttonstate == HIGH; 128 center(); 129 if (buttonstate == LOW) //when 130 button is pushed, it causes a ground, moving the buttonstate to LOW, triggering 131 the loop 132 { 133 Serial.print('1'); //This is done three times, because otherwise 134 the python program will only play the music every other button press 135 Serial.print('1'); 136 137 Serial.print('1'); 138 dip(); 139 sweep(); 140 141 } 142}
Bubble Machine Code Arduino
c_cpp
1#include <VarSpeedServo.h> //Gives you control of servo speed 2 3//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). 4 5VarSpeedServo servoH; //Base servo for horizontal sweeping motion 6VarSpeedServo servoV; //Vertical servo connected to base servo 7VarSpeedServo servoW; //Wand servo connected to Vertical servo, controls vertical motion of bubble wand 8 9int in3 = 3; //IN3 on L298 connected to pin 3 10int in4 = 4; //IN4 on L298 connected to pin4 11int pos = 0; //I think this is left over code from previous trials, but never removed it. Have not tried to run code without this 12int button = 11; //Button is connected pin 11 13int buttonstate = 0; 14void setup() 15{ 16 Serial.begin(9600); 17 Serial.println("Hi! It's Arduino!"); 18 pinMode(in3, OUTPUT); 19 pinMode(in4, OUTPUT); 20 servoH.attach(6); //Attaches Horizontal Servo to pin 6 21 servoV.attach(7); //Attaches Vertical Servo to pin 7 22 servoW.attach(8); //Attaches Wand Servo to pin 8 23 servoH.write(0,255,true); //Initializes Horizontal Servo, 0 degrees, 255 speed (same with next two) 24 servoV.write(0,255,true); 25 servoW.write(0,255,true); 26 pinMode(button, INPUT); 27 digitalWrite(button, HIGH); 28 29} 30 31 32void on() //Motor on 33{ 34 digitalWrite(in3, HIGH); 35 digitalWrite(in4, LOW); 36} 37 38 39void off() //Motor off 40{ 41 digitalWrite(in3, LOW); 42 digitalWrite(in4, LOW); 43} 44 45 46void 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 47{ 48 servoH.write(76,60,true); 49 servoV.write(80,60,true); 50 servoW.write(50,60,true); 51} 52 53 54void sweep() //This turns the fan on, sweeps the machine, and turns the fan off. Servo degrees may need adjustment depending on servo orientation 55{ 56 on(); 57 servoH.write(120,15,true); 58 servoH.write(50,15,true); 59 servoH.write(90,15,true); 60 off(); 61} 62 63 64void dip() //You will need to adjust the degrees in these settings. This uses the Vertical servo to raise the Wand servo, 65 //then the wand servo turns the wand downward, Vertical Servo lowers wand servo, raises it up, 66 //pauses to let excess fluid drip off, Wand servo raises the wand, Vertical servo lowers. 67{ 68 servoV.write(80,60,true); 69 delay(200); 70 delay(1000); 71 servoW.write(120,40,true); 72 delay(200); 73 servoV.write(150,60,true); 74 delay(1000); 75 servoV.write(100,60,true); 76 delay(200); 77 servoV.write(150,60,true); 78 delay(200); 79 servoV.write(80,40,true); 80 delay(3000); 81 servoW.write(40,60,true); 82 delay(200); 83 servoV.write(100,60,true); 84 delay(200); 85} 86 87 88 89 90void loop() 91{ 92 buttonstate = digitalRead(button); 93 buttonstate == HIGH; 94 center(); 95 if (buttonstate == LOW) //when button is pushed, it causes a ground, moving the buttonstate to LOW, triggering the loop 96 { 97 Serial.print('1'); //This is done three times, because otherwise the python program will only play the music every other button press 98 Serial.print('1'); 99 Serial.print('1'); 100 dip(); 101 sweep(); 102 103 } 104}
Downloadable files
Bubble Machine Picture 2
Bubble Machine Picture 2

Bubble Machine Picture 4
Bubble Machine Picture 4

Python code
This is the python code for playing the music
Python code
Bubble Machine Picture 3
Bubble Machine Picture 3

Bubble Machine Picture 1
Bubble Machine Picture 1

Bubble Machine Code
Bubble Machine Code
Music for bubble machine
mp3 file if you want to use it
Music for bubble machine
Bubble Machine Code
Bubble Machine Code
Music for bubble machine
mp3 file if you want to use it
Music for bubble machine
Bubble Machine Picture 5
Bubble Machine Picture 5

Bubble Machine Picture 3
Bubble Machine Picture 3

Bubble Machine Picture 4
Bubble Machine Picture 4

Bubble Machine Picture 2
Bubble Machine Picture 2

Python code
This is the python code for playing the music
Python code
Bubble Machine Wiring JPG
Bubble Machine Wiring JPG

Bubble Machine Picture 1
Bubble Machine Picture 1

Bubble Machine Wiring
Bubble Machine Wiring
Bubble Machine Picture 5
Bubble Machine Picture 5

Bubble Machine Wiring
Bubble Machine Wiring
Comments
Only logged in users can leave comments