in

Arduino Volume Controller with Gestures | Media Player Controller

Introduction to Arduino Volume Controller

In this post, I will explain one of the coolest Arduino Projects of 2019. This gesture based media controller or Arduino Volume Controller that can be connected to any computer running any OS. You can connect it to PCs USB port and it will act as a HID or a Human Interface Device. In this video, I will explain this sensor, HID using Arduino and the Code. Using this You can start, play or pause the song, go to the next song, play previous song, increase, reduce and mute volume. Take a look at the demo video below.

Arduino Volume Controller Video Demo and Tutorial

Arduino Gesture Based Media Player Controller

Looks cool right? Guys. Before going further, if you find this video useful, consider supporting my channel by giving this video a like and subscribe to my channel by clicking the subscribe button below. I would really appreciate it.

This is a Hand Gesture Media Controller. Using this Gesture Controller, you can control the media player using simple hand gestures. You can start, play or pause the song, go to the next song, play previous song, increase, reduce and mute volume.  Let’s Get Started!!!

PAJ7620 Gesture Sensor

PAJ7620 Gesture Sensor is a quick and easy way to add gesture control to your Arduino or Raspberry Pi Project. This tiny little sensor can recognize various hand gestures such as moving your hands up, down, left, right, forward, backward, clockwise, anti-clockwise and  waving . It employs an in built proximity sensor which can sense approaching and departing objects.

In the previous Post, I explained everything about PAJ7620 gesture sensor, how to connect this sensor to Arduino and read hand gestures.

PAJ7620 Gesture Sensor

I have also added a post on making an awesome gesture controlled robot using this sensor. If you are interested, take a look at the video below.

PAJ7620 Gesture Controlled Robot

If you are not familiar with that, click the link below and watch that first.

Arduino as HID

Some Arduino Board can act as HID (Human Interface Device), as a keyboard or mouse and send keystroke through the USB like a real keyboard. When you connect the Arduino to the USB port of the PC, it will act as a keyboard and send keystrokes to it. 

In this project, we will be sending media control keystrokes to the PC using Arduino MKR1000. For that we will be using this NicoHood Library.

Components Needed

  • PAJ7620 Gesture Sensor
  • Arduino Board that can act as a HID

As I mentioned earlier. this is a simple project, connections are pretty easy and you wont need more than 1 minute to set this up. You can use any arduino board that can act as HID like MKR1000, pro micro, Leonardo to name a few. I will provide complete list in the description. Let us start connecting them together. 

Steps

Step 1 – Testing Components

For this project, you will need 2 libraries for your Arduino IDE.

The first thing to do is install these libraries and check the working individually.

PAJ7620 Library

To install this library, you can go to “library manager” and search for “PAJ7620” and install the library effortlessly. Or you can download it from here. Extract the file and paste it inside library folder.

Now restart Arduino IDE, navigate to File>Example>PAJ7620

There you will find 2 examples. You can try uploading the basic demo and once uploaded, start the serial monitor.

Then try moving your hand in front of it. The gesture sensor will detect and print the gesture in the serial monitor.

Learn more about PAJ7620 Gesture Sensor

PAJ7620 Tutorial

Nicohood – HID Library

You can download it from here. Extract the file and paste it inside library folder.

Now restart Arduino IDE, navigate to File>Example>HID-Project

Then try moving your hand in front of it. The gesture sensor will detect and print the gesture in the serial monitor. Check whether it is working.

If both these libraries are working, then you wont have any problem with the rest of the code. You can now start to make our Gesture based Arduino Volume Controller.

Step 2 – Connections

Connections are simple – Simply Connect

  • Vin to 5 V
  • Gnd to Gnd
  • SCL to SCL
  • SDA to SDA.

Step 3 – Coding

The code is exactly the same code we used in the PAJ7620 Tutorial. We are just adding HID library. When a particular gesture is detected, instead of just printing what it is, we will send keystroke using the HID Project library.

#include <Wire.h>
#include <HID-Project.h>
#include "paj7620.h"

#define GES_REACTION_TIME		300
#define GES_ENTRY_TIME			400	
#define GES_QUIT_TIME			400

void setup()
{
	uint8_t error = 0;

	Serial.begin(9600);
	error = paj7620Init();
	if (error) 
	{
		Serial.print("INIT ERROR,CODE:");
		Serial.println(error);
	}
	else
	{
		Serial.println("INIT OK");
	}
	Serial.println("Start Controlling Media with Gestures\n");
}

void loop()
{
	uint8_t data = 0, data1 = 0, error;
	
	error = paj7620ReadReg(0x43, 1, &data);	
	if (!error) 
	{
		switch (data) 	
		{
			case GES_RIGHT_FLAG:
				delay(GES_ENTRY_TIME);
				paj7620ReadReg(0x43, 1, &data);
				if(data == GES_FORWARD_FLAG) 
				{
					Serial.println("Mute/No Mute");
          Consumer.write(MEDIA_VOLUME_MUTE);
					delay(GES_QUIT_TIME);
				}
				else if(data == GES_BACKWARD_FLAG) 
				{
					Serial.println("Mute/No Mute");
          Consumer.write(MEDIA_VOLUME_MUTE);
					delay(GES_QUIT_TIME);
				}
				else
				{

					Serial.println("Previous");
          Consumer.write(MEDIA_PREVIOUS);
          delay(500);
				}          
				break;
			case GES_LEFT_FLAG: 
				delay(GES_ENTRY_TIME);
				paj7620ReadReg(0x43, 1, &data);
				if(data == GES_FORWARD_FLAG) 
				{
					Serial.println("Mute/No Mute");
          Consumer.write(MEDIA_VOLUME_MUTE);
					delay(GES_QUIT_TIME);
				}
				else if(data == GES_BACKWARD_FLAG) 
				{
					Serial.println("Mute/No Mute");
         Consumer.write(MEDIA_VOLUME_MUTE);
					delay(GES_QUIT_TIME);
				}
				else
				{
				 Serial.println("Next");
         Consumer.write(MEDIA_NEXT);
         delay(500);
				}          
				break;
			case GES_UP_FLAG:
				delay(GES_ENTRY_TIME);
				paj7620ReadReg(0x43, 1, &data);
				if(data == GES_FORWARD_FLAG) 
				{
					Serial.println("Mute/No Mute");
          Consumer.write(MEDIA_VOLUME_MUTE);
					delay(GES_QUIT_TIME);
				}
				else if(data == GES_BACKWARD_FLAG) 
				{
				Serial.println("Mute/No Mute");
        Consumer.write(MEDIA_VOLUME_MUTE);
				delay(GES_QUIT_TIME);
				}
				else
				{
					Serial.println("Nothing Assigned");
				}          
				break;
			case GES_DOWN_FLAG:
				delay(GES_ENTRY_TIME);
				paj7620ReadReg(0x43, 1, &data);
				if(data == GES_FORWARD_FLAG) 
				{
					Serial.println("Mute/No Mute");
          Consumer.write(MEDIA_VOLUME_MUTE);
					delay(GES_QUIT_TIME);
				}
				else if(data == GES_BACKWARD_FLAG) 
				{
					Serial.println("Mute/No Mute");
         Consumer.write(MEDIA_VOLUME_MUTE);
					delay(GES_QUIT_TIME);
				}
				else
				{
					Serial.println("Nothing Assigned");
				}          
				break;
			case GES_FORWARD_FLAG:
				Serial.println("Mute/No Mute");
        Consumer.write(MEDIA_VOLUME_MUTE);
				delay(GES_QUIT_TIME);
				break;
			case GES_BACKWARD_FLAG:		  
				Serial.println("Mute/No Mute");
       Consumer.write(MEDIA_VOLUME_MUTE);
				delay(GES_QUIT_TIME);
				break;
			case GES_CLOCKWISE_FLAG:
				Serial.println("Volume Up");
        Consumer.write(MEDIA_VOLUME_UP);
        delay(100);
				break;
			case GES_COUNT_CLOCKWISE_FLAG:
				Serial.println("Volume Down");
       Consumer.write(MEDIA_VOLUME_DOWN);
       delay(100);

				break;  
			default:
				paj7620ReadReg(0x44, 1, &data1);
				if (data1 == GES_WAVE_FLAG) 
				{
					Serial.println("Nothing Assigned");
				}
				break;
		}
	}
	delay(100);
}

Step 4 – Fixing the Controller

Once the connections are completed, you can use a double sided tape to fix your Arduino board and the gesture sensor somewhere. I fixed the Arduino board behind the speaker and the gesture sensor on top of it like this.

Step 5 – Start the Player

Now start your media player and try various hand gestures. Move your hand towards the sensor to Mute. Right to play next song, Left to play previous song, clockwise to increase volume, anti clockwise to reduce volume and top to down to play the song.

That was easy right? In our channel, you will find lots of Arduino and Raspberry Pi projects and tutorials, using the latest boards and sensors. Our main focus is on DIY Hobby projects, Robotics and Home automation using simple and cheap components in a fun and easy way. Make sure you subscribe and click on the bell icon so that you wont miss our fun videos.

New to Robotics?

We have a beginners guide on “Getting Started with Robotics” which will give you a kick start in this field. Check out our free video tutorial below for a brief introduction.

Robotics for Beginners and Kids

Top Arduino Projects You can Try this Summer Vacation


Top Robotics Projects You can Try this Summer Vacation

Did you find this page useful? Help us to improve by rating this page.

[RICH_REVIEWS_FORM]

[RICH_REVIEWS_SNIPPET stars_only=”true”]

Written by Jithin

Leave a Reply

Your email address will not be published. Required fields are marked *

Long Range WiFi Antenna | High Gain External WiFi Antennas

Industrial PCB Manufacture

PCB Manufacturing Process Step By Step | JLC PCB Fabrication