Servo Motor Browser

Experiments & prototyping with the Arduino.
Site Admin
Posts: 220
Joined: 07 Oct 2017, 12:16

Servo Motor Browser

Postby rwblinn » 08 Oct 2017, 18:28

This experiment moves a Little Crane arm (used some Lego parts) up and down via browser connected to a B4J websocket server.
When the arm moves, the Red LED is turned on else the Green LED is on (waiting for the servo to move).

The servo moves the arm between 30 and 90 degrees angle (defined in the server settings file located in the dirapp folder littlecrane.set [a map]).
Depending on the servo used, pressing multiple times on a move button might be required to move the crane arm (ToDo: test with another servo type).
If the servo is not moving, its starts to jitter. To avoid jittering, the servo motor is detached and attached again when pressing a move button.
There are various threads in the Arduino forums about this problem; tried several solutions where as detach and attach works best.

The B4J server is running on a Raspberry Pi, which has an Arduino connected via USB port (/dev/ttyACM0).
The server sends array of bytes to the Arduino: byte 0 = servoid (in case more then one servo = future thinking), 1 = angle position, 2 = 0 to set new angle or 1 to request angle position.
The Arduino receives the data via Asyncstream, acts accordingly and sends the update position (in JSON format) back to the server which updates the connected browser (Crane Position, this was a tricky one to solve = ConnectedBrowsers.Keys and CallSubDelayed).
Instead of JSON format, it is also possible to use array of bytes instead.

Run the solution via Raspberry Pi
• Upload the B4R program to the Arduino
• Connect the Arduino to the Raspberry Pi
• Get the USB port - most cases ttyACM0
• Create a folder /home/pi/b4x/littlecrane
• Copy from the PC B4J project folder the files littlecrane.jar, littlecrane.set and the www folder to /home/pi/b4x/littlecrane
• Open littlecrane.set and set the comport to f.e. comport=/dev/ttyACM0
• Start littlecrane.jar from the folder /home/pi/b4x/littlecrane: sudo -jar littlecrane.jar
• Open the webbrowser and enter as URL: RasPi-IP-Address:51042, like
• Play with the crane

This experiment open for any creative enhancements (like additional servos, use slider to move arm) esp. using Lego Technic.

Parts Needed
• 1x Arduino MEGA
• 1x Mini-Servo Motor MC1811
• 1x LED red
• 1x LED green
• 2x Resitors 220 Ohm
• 1x Raspberry Pi 2B or 3

Arduino = MC1811
GND = GND (Black)
5v = VCC (Red)
10 = Signal (Brown)

Arduino = LED GREEN
GND = GND (Black
6 = Signal (Green)
Note: 220Ohm resistor between the LED and Arduino

Arduino = LED RED
GND = GND (Black)
5 = Signal (Orange)
Note: 220Ohm resistor between the LED and Arduino





Download Source Code

• ESP8266 based instead of Arduino+Raspberry Pi, multiple servos, MQTT to control.


Return to “Arduino”

Who is online

Users browsing this forum: No registered users and 1 guest