0% found this document useful (0 votes)
19 views5 pages

speed controller

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

speed controller

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

// include the library code:

#include <LiquidCrystal.h> // use the library for Display

#include <IRremote.h> // use the library for IR

const int receiver = 10; // pin of IR receiver to Arduino

const int bulb = 9; // To bulb or whatever you connect.

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int fadeValue;

int lastCounter = 1;

int counter;

#define code1 32895 // code received from button A

#define code2 36975 // code received from button B

IRrecv irrecv(receiver); // create instance of 'irrecv'

decode_results results;

void setup() {

Serial.begin(9600); // you can comment this line

//Set up the output pin

pinMode(bulb, OUTPUT);

//Ir
irrecv.enableIRIn();

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

lcd.setCursor(0, 0); // set cursor to top left & first colum

lcd.print("Hello");

delay(1000);

lcd.setCursor(0, 0);

lcd.print("Starting..");

delay(1000);

lcd.clear();

void loop() {

counter = lastCounter;

if (irrecv.decode(&results))

unsigned int value = results.value;

if (value == code1) {

counter ++;

lcd.clear();// clear lcd

if (value == code2) {

counter --;
lcd.clear(); // clear lcd

Serial.println("IR receive code"); Serial.println(value); // you can comment this line

irrecv.resume();

if (counter > 5) { //maximum for counter = 5

counter = 5;

if (counter < 2) { //minimum for counter = 1

counter = 1;

switch (counter) { //depending on the counter the fadevalue is sent to the led

case 1:

fadeValue = 00;

lcd.setCursor(0, 0); // set cursor to top right

lcd.print("Dimmer! - OFF"); // LCD print

lcd.setCursor(0, 1); // set cursor to bottom left & second colum

lcd.print("PRES VOL+"); // LCD print

break;
case 2:

fadeValue = 50;

lcd.setCursor(0, 0); // set cursor to top right

lcd.print("Dimmer! - ON "); // LCD print

lcd.setCursor(0, 1); // set cursor to bottom left & second colum

lcd.print("Speed 1"); // LCD print

break;

case 3:

fadeValue = 100;

lcd.setCursor(0, 0); // set cursor to top right

lcd.print("Dimmer! - ON "); // LCD print

lcd.setCursor(0, 1); // set cursor to bottom left & second colum

lcd.print("Speed 2"); // LCD print

break;

case 4:

fadeValue = 185;

lcd.setCursor(0, 0); // set cursor to top right

lcd.print("Dimmer! - ON "); // LCD print

lcd.setCursor(0, 1); // set cursor to bottom left & second colum

lcd.print("Speed 3"); // LCD print

break;
case 5:

fadeValue = 255;

lcd.setCursor(0, 0); // set cursor to top right

lcd.print("Dimmer! - MAX"); // LCD print

lcd.setCursor(0, 1); // set cursor to bottom left & second colum

lcd.print("PRES VOL-"); // LCD print

break;

analogWrite(bulb, fadeValue); //set led with PWM value

lastCounter = counter; //reset counter

You might also like