How to Bluetooth Control ARDUINO PWM Pins (pulse with modulation)

This tutorial will show you how to make a simple Android app to Bluetooth control PWM pins on a ARDUINO.

Click on video below for full tutorial.

Mit app Inventor Blocks:

 

ARDUINO Code:

#define fan 9
#define led 3
int ledval = 0;
void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(fan,OUTPUT);
}

void loop() {

if (Serial.available() >= 2 )
{
unsigned int a = Serial.read();
unsigned int b = Serial.read();
unsigned int val = (b * 256) + a;

if (val >=0 && val <=255)
{
analogWrite(fan,val);
}

if (val >=1000 && val <=1255)
{
ledval = val – 1000;
analogWrite(led,ledval);
}

}
}