Week 4

Mouse motor control

The Idea

During this week we developed a circuit which involved connecting a servo motor to an Arduino Nano 33 iot. This week’s project consisted of developing something which I had started working on last week,  to control something physical with some king of haptic or visual interaction through human input.

The Video

The Process

The system consists of using a mouse to control the position of a Servo motor (ref. HS-311). . For dealing with the mouse interaction, I used p5 to send the mouse’s position to Arduino, which translated this value into an angle the servo motor could move. I used serial communication to create a bridge between both software and send the values of the mouse’s position in the Y axis to the Arduino.

HS 311 Servo.
HS 311 Servo.

The connection between the servo motor and the Arduino was straightforward. The servo motor three female headers, one for power, one for GND and another for communicating with the arduino.

 

Arduino connected to servo motor. Digital output pin 9, GND and power are connected.
Arduino connected to servo motor. Digital output pin 9, GND and power are connected.

I wanted to make some kind of visual feedback on the screen, as well as to debug my serial connection. So I made a bullseye that tracks mouse movement, maps the value between 0 – 179, and sends the mapped value to the Arduino as a serial message. Since this had to be updated in real time, and since p5 and Arduino both communicate in an asynchronous manner at a 9600 baudrate, I would send this updated value every loop.

 

GIF showing mouse movement on p5 sketch
Mouse movement on p5 sketch controls servomotor.
Hand using mouse.
Hand using mouse

As seen on the image above, I am sending a value and receiving the angle in which the motor has rotated the object attached to it.  

The Code

Mouse function p5
Mouse function p5
Draw function p5
Draw function p5

Thanks for reading!