Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*************************************************************************
- // Name : Prac_64A_IR_Rem_dig_variable_5v_dc *
- // Author : Tarilayefa Edward *
- // Notice : Tari Electronics & Embedded Systems (TEES), 2018. *
- // : tarielectronics@yahoo.com *
- // : tarielect.edward@gmail.com *
- // : +23408184754883,+23408062251186, Nigeria. *
- // : https//:web.facebook.com/groups/teestraining/ *
- // : https//:web.facebook.com/groups/picarduino/ *
- // Date : 15/07/2018 *
- // Version : 1.1 *
- // Notes : A program to digitally control a variable 5v dc supply *
- // : using an RC5 (Philips infrared) remote control. Arrow up *
- // : button increases the pwm while arrow down button decreases *
- // : the volum using IRLib and SoftPWM libraries. *
- // Reference: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *
- // Compiler : avrgcc *
- // IDE : Arduino 1.8.5 *
- // Target : Atmega 328, Arduino Uno, Nano. *
- //*************************************************************************
- # include <IRLib.h> //include the ir remote control library
- #include <SoftPWM.h> //add the software pwm library
- #include <LiquidCrystal.h> //add the lcd library
- LiquidCrystal lcd (7, 6, 5, 4, 3, 2); //(rs,en,d4,d5,d6,d7)
- int feedBackPin = A0; //feedback input pin
- int spwmVal = 2; //initialize soft pwm value to 2
- float voltsCheck = 0; //voltage check variable
- float volts; //output voltage variable
- int spwmPin = 11; //software pwm output pin
- int spwmBtnUp = 8; //push button to increase (pwm) voltage
- int spwmBtnDwn = 9; //push button to decrease (pwm) voltage
- int irsigled = 13; //ir signal led
- //........................................................................
- SOFTPWM_DEFINE_CHANNEL(11, DDRB, PORTB, PORTB3);//soft pwm on Arduino pin 11
- SOFTPWM_DEFINE_OBJECT_WITH_PWM_LEVELS(20, 100);//100 pwm levels
- //........................................................................
- //put these commands before setup for ir remote to work
- IRrecv My_Receiver(12); //ir remote sensor on arduino pin 12
- IRdecode My_Decoder;
- IRdecodeHash My_Hash_Decoder;
- //---------------------------------------------------------------------
- void setup() //setup function
- {
- pinMode(spwmPin, 1);//PWM output pin
- pinMode(spwmBtnUp, INPUT_PULLUP);//button 1
- pinMode(spwmBtnDwn, INPUT_PULLUP);//button 2
- pinMode(irsigled, 1);
- digitalWrite(irsigled, 1); //turn on irsigled
- //-----------------------------------------------------------------
- lcd.begin(16, 2);//initialize a 16x2 char lcd
- lcd.clear(); //clear lcd
- delay(100); //wait for 100ms
- lcd.print(" IR Dig Voltage ");
- //----------- ---------------------------------------------------
- My_Receiver.enableIRIn(); // Start the receiver
- //--------------------------------------------------------------
- Palatis::SoftPWM.begin(1000); // begin with 1000hz pwm frequency
- //--------------------------------------------------------------
- Serial.begin(9600); //initialize serial communication
- Serial.println("IR Remote Controlled Dig Variable 5v dc");
- delay (2000);
- }
- //---------------------------------------------------------------------
- //---------------------------------------------------------------------
- void loop() //main loop function
- {
- volts = (analogRead(feedBackPin));//read ADC value at A0
- volts = (volts * 5) / 1024;//converting to 5v range
- int upVal = digitalRead(spwmBtnUp); //read voltage up push button
- int dwnVal = digitalRead(spwmBtnDwn); //read voltage down push button
- //-------------------------------------------------------------------
- if ((voltsCheck > (volts + 0.05))|(voltsCheck < (volts - 0.05)))
- //check if voltage change is higher or lower than 0.5 of previous
- //value to avoid fluctuations
- {
- voltsCheck = volts;//store previous value
- }
- //--------------------------------------------------------------
- Palatis::SoftPWM.set(spwmPin, spwmVal);
- //--------------------------------------------------------------
- if (upVal == LOW)//if voltage up button is pressed
- {
- delay(30); //short button debounce delay
- spwmUp(); //increase pwm
- }
- if (dwnVal == LOW)//if voltage down button is pressed
- {
- delay(30);
- spwmDown(); //decrease pwm
- }
- //--------------------------------------------------------------
- ir_remote_dec();
- //--------------------------------------------------------------
- lcd.setCursor(0,1);
- lcd.print("V=");
- lcd.print(volts); //print out voltage value
- lcd.print("v");
- lcd.print(" PWM=");
- lcd.print(spwmVal); //print out pwm value
- lcd.print("%");
- lcd.print(" ");
- lcd.setCursor(9, 0);
- //--------------------------------------------------------------
- Serial.print("pwmVal: ");
- Serial.print(spwmVal); //print out pwm value
- Serial.print("%; ");
- Serial.print("voltage: ");
- Serial.print(volts); //print voltage value
- Serial.println("v");
- delay(200);
- }
- //......................................................................
- void spwmUp(){ //function to increase pwm
- spwmVal++; //increase pwm
- if (spwmVal > 99){
- spwmVal = 99; //make sure spwmVal does not go above 99
- }
- }
- //......................................................................
- //......................................................................
- void spwmDown(){ //function to decrease pwm
- spwmVal--; //decrease pwm
- if (spwmVal < 0){
- spwmVal = 0; //make sure spwmVal does not go below 0
- }
- }
- //......................................................................
- //......................................................................
- void ir_remote_dec() { //ir remote decoding function
- if (My_Receiver.GetResults(&My_Decoder)) {//Puts results in My_Decoder
- My_Hash_Decoder.copyBuf(&My_Decoder);//copy the results to the hash decoder
- My_Decoder.decode();
- sigled(); //call signal led function
- My_Hash_Decoder.decode();
- ir_rem_btn_control(); //call ir rem button control function
- //....................................................................
- Serial.print("Prot: ");
- Serial.print(Pnames(My_Decoder.decode_type)); //remote control type
- Serial.print("; Value: ");
- Serial.println(My_Hash_Decoder.hash, DEC); //value of remote control button pressed in decimal
- //....................................................................
- My_Receiver.resume(); //resume the ir decoding
- }
- }
- //..........................................................................
- //..........................................................................
- void ir_rem_btn_control() { //ir rem button control function
- switch (My_Hash_Decoder.hash) { //value remote control button pressed
- //----------------------------------------------------------------
- case 2891014758:; //arrow up button PHILIPS RC7940 REMOTE CONTROL
- delay(50); //short button debounce delay
- spwmUp(); //increase pwm
- break; //exit after execution of command
- case 3843267751:;
- delay(50);
- spwmUp();
- break;
- //-------------------------------------------------------------------
- case 2907792379:; //arrow down button PHILIPS RC7940 REMOTE CONTROL
- delay(50);
- spwmDown(); //decrease pwm
- break;
- case 3826490130:;
- delay(50);
- spwmDown();
- break;
- //-------------------------------------------------------------------
- }
- }
- //.........................................................................
- //.........................................................................
- void sigled() { //signal led function
- //blink led when noise or ir signal is recieved
- digitalWrite(irsigled, 0); //turn off signal led
- delay(100); //delay for 100ms
- digitalWrite(irsigled, 1); //turn on signal led
- }
- //........................................................................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement