”Tis the season!’, or rather, ”Twas the season!’
I recently started tinkering around with a servo motor (my Christmas present) and decided to put it to use on our tree.
As you might have figured out, it’s a smartphone-tilt-sensitive star, sitting atop the tree on a servo motor.
When the phone is tilted to the right, the star turns left and vice-versa.
The signals from the phone’s internal accelerometer (only x-axis is used here) are sent via bluetooth to the HC05 bluetooth module, which in turn, sends it to the Arduino UNO. The Arduino then converts the raw data into PWM (pulse width modulation) signals and transmits it through digital pin 9 to the servo motor.
The project makes use of the following hardware:
- Arduino UNO
- HC05 (bluetooth module)
- Plastic geared servo motor
And software:
- Android app made using MIT App Inventor 2
- Components used:
- Arduino code:
#include <Servo.h>
Servo myservo;
void setup()
{
Serial.begin(9600);
myservo.attach(9);
delay(1000);
}
void loop()
{
int val=0;
int state=Serial.parseInt();
val = map(state,-22,0,0,180);
myservo.write(val);
Serial.println(val);
}
The pin connections are fairly straightforward:
Have a great year ahead!