Introduction: LED Brightness Control Using Arduino's Serial Monitor

HIGHLIGHTS:

  • Controlling LED's brightness without using potentiometer.
  • Allowing float values in map function.

There are variety of applications that was used in this project such as controlling the speed of a motor, proportional valves, and solenoid valves with a more precise speed due to the usage of float values for mapping. Using float values can maximize the use of PWM signal to have more precise control.

Step 1: Circuit

Anode D3( If you are using different Arduino board, PWM pins might differ. Check the PWM pins for the Arduino board you are going to use )

Cathode GND

Step 2: Code

NOTE: Download and add the "MapFloat" library before uploading the code. This library will allow you to enter float values for mapping. Download link

#include "MapFloat.h" //Library Source: https://github.com/radishlogic/MapFloat
float PWMVal = 0;        
const int pinOut = 3; // PWM Pin of Arduino Nano         


void setup() {
  Serial.begin(9600);
}


void loop() {
  while (Serial.available()>0){
  String myString = Serial.readString(); // Read as String
  float myFloat = myString.toFloat();   // Convert it to float
  float PWMVal = mapFloat (myFloat, 0,10.0,0,255); // 0->0 , 10->255
  analogWrite(pinOut, PWMVal);        // Output
  Serial.print("LEVEL = ");
  Serial.println(myFloat);           
  Serial.print ("PMW VALUE = ");
  Serial.println (PWMVal);
  Serial.println("----------------------------");
  }
}

Step 3: Testing