Controlling PWM with Your Phone
Controlling PWM with Phone
Motion based projects are fun. There are a few gyro and accelerometer that works with Arduino, but they are not free. However most phones comes with those sensors and we are going to take advantage of that - making a remotely controlled PWM pin with your phone.
System Environments
Hardware list:
- Mac OS 10.11.5
- Arduino Uno board of your choice, I am using one from DFRobot
- LED or motor
Software setup
Flash Firmata into Your Uno Board
There is a nice tutorial for you.
Download & Install node.js [optional]
Please nodejs.org for instructions.
Clone or download example project
Please follow the github example project.
Wire the PWM device
In the example project we are using Pin 11.
You can change the pin number as long as
it is still a PWM pin. Remember to match the code and your wiring if you decide to modify the pin number.
Build and Run
npm install && npm start
There is a video showing the result.
How It Works
Server side
- The server script starts a tiny web server to host the html and scripts.
- It also generates a QR code for you to scan to link created.
- Then it starts the Johnny-five instance.
- Finally it starts a socket.io server to listen to phone events.
Mobile side
- Once the QR code is scanned, the QR code app ( or you can use whatsapp ) opens the browser
- HTML5 code starts to sense phone orientation events and forward that information to our socket.io server
Interaction
- Server gets orientation info from mobile device, translate raw data and map to PWM output
- Johnny-five instance channels that info into the board
- Firmata firmware on the board decodes the info and outputs corresponding PWM wave on the pin
VoilĂ .