Improved Matilda
For this project you will build and assemble a 3D car that will have light sensitive headlights, siren sound in response to being shaken, and rotate 120 degrees when button A is pressed.
Supplies
1) 3D Printer and Filament (any printer and filament that works for you will work)
3) Servo Motor
5) 4 Wheels 3D Printed
6) Body of Car
7) Hood/Roof of Car
8) Hot Glue Gun
3D Design Download
Using these files, download them and import them into MakerBot as separate projects to print. Ensure that the body and roof of car are printed upside down (wheel inserts facing up for the body and the arms of the roof facing up) The wheels also should be printed on their sides. Printing like this will avoid using supports.
Circuit Python Code
The following codes should be copied and pasted into Mu Editor to upload the functions of the CPX. For the following there are more instructions on Adafruits Instructions on Circuit Python.
import time
from adafruit_circuitplayground import cp
# Set the brightness of the NeoPixels
cp.pixels.brightness = 0.5
while True:
# Read light sensor value (0 is dark, 100 is bright roughly)
light_level = cp.light
# Adjust this threshold for what you consider "dark"
if light_level < 10:
# Turn all pixels white
cp.pixels.fill((255, 255, 255))
else:
# Turn all pixels off when it's not dark
cp.pixels.fill((0, 0, 0))
import time
from math import sqrt
from adafruit_circuitplayground import cp
# Siren settings
siren_frequencies = [440, 880] # Low and high tones
siren_delay = 0.1 # Delay between frequency changes
shake_threshold = 20 # Adjust for sensitivity
while True:
# Get x, y, z acceleration
x, y, z = cp.acceleration
total_accel = sqrt(x**2 + y**2 + z**2)
# Play siren while shaken
if total_accel > shake_threshold:
while total_accel > shake_threshold:
for freq in siren_frequencies:
cp.start_tone(freq)
time.sleep(siren_delay)
# Update acceleration to check if still shaking
x, y, z = cp.acceleration
total_accel = sqrt(x**2 + y**2 + z**2)
cp.stop_tone() # Stop when shaking stops
else:
time.sleep(0.05)
import time
import board
import pwmio
from adafruit_motor import servo
from adafruit_circuitplayground import cp
# Setup PWM for servo on pin A1
pwm = pwmio.PWMOut(board.A1, frequency=50)
my_servo = servo.Servo(pwm)
# Start at 0 degrees
my_servo.angle = 0
while True:
if cp.button_a:
my_servo.angle = 180 # Move servo to 180° when button A is pressed
time.sleep(0.3) # Small delay to debounce
elif cp.button_b:
my_servo.angle = 0 # Move servo back to 0° when button B is pressed
time.sleep(0.3) # Small delay to debounce
time.sleep(0.01) # Short delay to avoid excessive CPU usage
Using these codes, copy and past them into one page on the Mu Editor (make sure the page is labeled code.py). Once these codes are in a code.py page and your CPX is plugged into your computer, you can click the save button and then the load button to upload the functions to the CPX.
Servo Motor
To set up the servo motor, you should grab 3 alligator clips, your CPX, and a servo motor. Use the 3 alligator clips and put the coordinated color wires as so: Ground wire --> GND, Power wire --> VOUT, and the Signal wire --> A2
You can also plug the black cord into the CPX and your computer instead of using a battery.
Final Assembly
For the final assembly, glue the 4 wheels into their specified part of the body of the car. Then glue to hood of the car according to the attached photo. The CPX can be glued under the hood of the car, and the servo motor should be attached to the car by the arm to the underside of the car. The servo motor (the side thats not attached to the car) can also be attached to a platform to provide stability for the car.