GAME BALL

GAME BALL has game functions and can control lights, making it a part of home decoration. This versatility makes the GAME BALL an efficient device in any room while also adding a stylish and modern touch to the home. Whether in the living room, bedroom, or kitchen, GAME BALL can be a good decoration, making the whole room more comfortable and warm.
Martial


- Arduino ESP8266
- Breadboard
- Ultra Sonic sensor
- Button
- DC motor
- WS2812
- Servo motor
Google doc
https://docs.google.com/document/d/1O3jdkraO0rVTgM0tWL5ALO6hiw3Qn6Y_kGhfGyKp6Cc/edit?usp=sharing
Instructables
https://www.instructables.com/preview/ETASSVLLP8CJB1P/
WIP
Attempt 1:
Main Loop:
Continuously check the state of the button.
If the button is pressed:
Rotate the servo motor to 90 degrees.
Measure the distance using the ultrasonic sensor.
Output the distance to the Serial monitor.
If the distance is less than 20 cm:
Activate the DC motor.
Illuminate the NeoPixel LED strip with a yellow color.
If the distance is greater than or equal to 20 cm:
Deactivate the DC motor.
Turn off the NeoPixel LED strip
Distance Measurement Function:
Implement the measure distance function to measure the distance using the ultrasonic sensor.
This code creates an interactive system where pressing a button initiates actions based on the measured distance using an ultrasonic sensor. The servo motor controls physical movement, the DC motor reacts to proximity, and the NeoPixel LED strip provides visual feedback.
Q: DC motor not working
Attempt 2:
I try to control the movement of two servos (servo motors) using two buttons, while also detecting distance through an ultrasonic sensor and controlling the state of a NeoPixel LED strip. Here’s a textual description of the code:
Import the Servo and Adafruit_NeoPixel libraries and define various pins and constants.
Set up two Servo objects (and) and one Adafruit_NeoPixel object (strip).
In the setup function, initialize the program by setting the modes for the button, ultrasonic sensor, and NeoPixel pins, as well as initializing the Servo and NeoPixel objects.
In the loop function, first check the state of the buttons.
If a button is pressed, rotate servoButton to 45 degrees, delay for 500 milliseconds, and then return it to the original position.
Simultaneously, use a loop to rotate the servoUltrasonic from 90 degrees to 180 degrees and then back from 180 degrees to 90 degrees, finally returning it to the 90-degree position.
Measure the distance with the ultrasonic sensor; if the distance is less than 20 centimeters, illuminate the NeoPixel LED strip. Additionally, use a loop to rotate the servoUltrasonic from 0 degrees to 180 degrees and then back from 180 degrees to 0 degrees, finally returning it to the 90-degree position.
If the distance is not less than 20 centimeters, turn off the NeoPixel LED strip and return servoUltrasonic to the 90-degree position.After each loop, wait for 1 second before starting the next iteration.
Q; Connecting two servo motor buttons at the same time cannot make one of them work.
Attempt 3:
- Main Loop:
- In the
loop()
function, handles the logic for the button and ultrasonic sensor by callingbuttonLoop()
andultrasonicLoop()
.
- In the
- Button Operation:
- In the
buttonLoop()
function, checks the button state. If the button is pressed, it sets the servo angle for the button to 45 degrees.
- In the
- Ultrasonic Operation:
- In the
ultrasonicLoop()
function, uses themeasureDistance()
function to obtain the ultrasonic sensor’s distance reading. - Based on the distance, controls the color of the Neopixel LED strip. If the distance is less than 20cm, the LED strip is set to yellow.
- Simultaneously, sweeps the ultrasonic sensor by moving its servo to create a scanning motion.
- When the distance is greater than or equal to 20cm, the LED strip turns off, and the ultrasonic sensor’s servo returns to the initial position.
- In the
- Ultrasonic Ranging:
- The
measureDistance()
function triggers the ultrasonic sensor, measures the duration of the echo pulse, and converts it to a distance value, implementing ultrasonic ranging.
- The
Q; Connecting two servo motor buttons at the same time cannot make one of them work.