LED Brightness Control Using Arduino's Serial Monitor

by hedaselish in Circuits > Arduino

1788 Views, 0 Favorites, 0 Comments

LED Brightness Control Using Arduino's Serial Monitor

IMG_4554.JPG

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.

Circuit

Circuit Diagram.png
PWM Pins.png

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

Code

Code.png

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("----------------------------");
  }
}

Testing

Testing.png