Compliments of the season & Happy New Year!

”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:

    • A few other settings to be changed:
      • BluetoothClient1 – Leave ‘Secure’ checkbox unchecked
      • Clock1 – set ‘TimerInterval’ value to 1
      • AccelerometerSensor1 – set ‘MinimumInterval’ value to 1000 and set ‘Sensitivity’ option to weak.
    • Code:
  • 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:

Servo motor red – Arduino 5v
Servo motor black/brown – Arduino GND
Servo motor yellow/white (PWM input) – Arduino Digital Pin 9 (PWM)
HC05 VCC – Arduino 3.3v
HC05 GND – Arduino GND
HC05 Tx – Arduino Rx
HC05 Rx – Arduino Tx

Have a great year ahead!

Leave a Reply