/*___________________________________________________________________________________________________ * * U C I C R I T T E R S T U D Y G R O U P * L E S S O N 4 * IR Remote Motor Control * Ron Kessler * Created 5/14/2021 * * * PURPOSE: * DEMO HOW TO DETECT SONY REMOTE IR KEY CODES AND RUN DC MOTOR FROM YOUR KIT * Channel Up = 144 * Channel Dn = 145 * Volume Up = 146 * Volume Dn = 147 We will expand your previous project to include our transistor motor circuit. Using the IR receiver in your study group kit: In case you need a review of setting up the IR part: 1. Place the IR module in a breadboard with the sensor facing you. 2. Connect a green wire from the leftmost pin to GND on Arduino. 3. Connect a RED wire from the center pin of the sensor to 5V on Arduino. 4. Connect another wire from the right pin to pin 2 of the Arduino. This is the signal pin. 5. Make sure you have the IRRemote library installed on your computer. I use ver 3.3 as of this writing. 6. Re-create your DC motor controller using a transistor circuit (Lesson 2). We will use pin 9 to send PWM signals to the motor. 7. Code as shown below. 8. Save & upload your code 9. Open the serial monitor window. TOOLS | SERIAL MONITOR. Make sure to set baud rate to 9600. 10. Point your Sony remote towards the sensor and push the buttons. The button code should appear in the monitor window. When you push Channel UP the motor should turn. Any other key stops it. 11. This version turns motor on full speed. You could use analogWrite(9,150) instead to choose a speed like we did in the lesson 2 PWM demo. OPERATION: As long as you hold the remote button down, the motor will turn. When you release it the motor stops. Try other buttons to verify the motor does not respond. TOO COOL!!! ___________________________________________________________________________________________________ */ //************* START CODE HERE ************ //---1. now add the library #include //ver 3.3 As of 5/15/2021 //---2. define our sensor data pin as a constant(const). const int IR_RECEIVE_PIN = 11; //---define our MOTOR output pin as D9 as a constant (it will not change in this app) const int motorPin = 9; void setup() { //---3. Define our motor pin as output pinMode(motorPin,OUTPUT); //tell duino we want it to send a signal, not receive //---4. open the serial port and monitor at 9600 baud rate. Serial.begin(9600); //---4. Start our IR receiver on the arduino. We pass in two arguments: pin# and system command // to ignore blinking the onboard LED when a message is received. IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK); } void loop() { //---if data is being received then decode it, print to the monitor, and keeping listening for more! if (IrReceiver.decode()) { Serial.println(IrReceiver.decodedIRData.decodedRawData); //*******NEW STUFF 5/15/2021*********** //Check for our Channel Up signal if(IrReceiver.decodedIRData.decodedRawData == 144) digitalWrite(motorPin,HIGH); else digitalWrite(motorPin,LOW); //******END OF NEW STUFF******* IrReceiver.resume(); // Receive the next value } } //************* END OF CODE ************