/*___________________________________________________________________________________________________ * * 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 with Transistor and Relay * Ron Kessler * Created 5/16/2021 * * * PURPOSE: * DEMO HOW TO DETECT SONY REMOTE IR KEY CODES AND RUN DC MOTOR FROM YOUR KIT * Codes from 12 bits 1 byte (These coincide with my IR decode report * Channel Up = 144 16 * Channel Dn = 145 17 * Volume Up = 146 18 * Volume Dn = 147 19 We will expand your previous project to include the transistor but also a relay. 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. 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 byte IR_RECEIVE_PIN = 11; //---3. define our MOTOR output pin as D9 as a constant (it will not change in this app) const int motorPin = 9; //---4. define a variable to hold IR code which is detected int codeReceived = 0; void setup() { //---3. Define our motor pin as output to engage relay through the transistor. 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(115200); //---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() { while(!(IrReceiver.decode())); //---if data is being received then decode it, print to the monitor, and keep listening for more! if (IrReceiver.decode()) { codeReceived = IrReceiver.decodedIRData.command; //.decodedRawData; Serial.println(codeReceived); //*******NEW STUFF 5/15/2021*********** //Check for our Channel Up signal switch (codeReceived) { case 16: digitalWrite(motorPin,HIGH); break; case 17: digitalWrite(motorPin,LOW); break; } //******END OF NEW STUFF******* } IrReceiver.resume(); // Receive the next value } //************* END OF CODE ************