H Bridge (293D) With 2 Hobby Motors and a Remote
by sister mariaM in Circuits > Microcontrollers
1270 Views, 2 Favorites, 0 Comments
H Bridge (293D) With 2 Hobby Motors and a Remote
This Instructables will show how you can use a remote control to control a H bridge (293) with 2 hobby motors .
This circuit could be used with a basic 2 wheel robot with a remote control.
The parts used are ;
remote control
IR receiver
4; 1.5 volt battteries
Hbridge (293D)
2 hobby motors
Arduino Uno
Code for Tinkercad remote ;updated
#define DECODE_NEC
#define IR_RECEIVE_PIN 3
#if !defined(RAW_BUFFER_LENGTH)
// Maximum length of raw duration buffer. Must be even. 100 supports up to 48 bit codings inclusive 1 start and
// 1 stop bit.
#define RAW_BUFFER_LENGTH 100 \
// #define RAW_BUFFER_LENGTH 112 // MagiQuest requires 112 bytes.
#endif
#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program space.
#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program space if all other protocols are active
#include <IRremote.hpp>
void setup()
{
Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) || defined(ARDUINO_attiny3217)
delay(1000);
#endif
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
Serial.println(F("Enabling IRin..."));
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
Serial.print(F("Ready to receive IR signals of protocols: "));
printActiveIRProtocols(&Serial);
Serial.print(F("at pin "));
Serial.println(IR_RECEIVE_PIN);
//L293D
//Motor A
const int motorPin1 = 5; // Pin 14 of L293
const int motorPin2 = 6; // Pin 10 of L293
//Motor B
const int motorPin3 = 10; // Pin 7 of L293
const int motorPin4 = 9; // Pin 2 of L293
//Set pins as outputs
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop(){
if (IrReceiver.decode()) {
//IrReceiver.printIRResultShort(&Serial);
switch(IrReceiver.decodedIRData.command) {
case 0x10: Serial.println("1"); // Button 1
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
break;
case 0x11: Serial.println("2"); // Button 2
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
break;
case 0x12: Serial.println("3"); // Button 3
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
break;
case 0x14: Serial.println("4"); // Button 4
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
break;
case 0x15: Serial.println("5"); // Button 5
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
break;
default: Serial.println(IrReceiver.decodedIRData.command);
}
IrReceiver.resume(); // Receive the next value
}
}
The Remote Control
The remote control is used in many circuit especially the TV remote we are aware of .
A remote consists of 2 parts .There is the handheld transmitter and receiver.
An IR remote control (the transmitter) sends out pulses of
infrared light.
These pulses are at a high frequency.
These pulses represent specific binary codes.
These binary codes correspond to commands on the remote, such as Power On/Off .
The IR receiver in the TV, or electronic device decodes the pulses of light into the binary data (ones and zeroes) which the electronic device's microprocessor can understand.
The microprocessor then carries out the command.
How to Find the Remote Numbers
Look at the third image .It shows a basic remote circuit .
If you open the serial monitor you will see letters and number appear on the serial monitor when a button is pressed on the remote control .Note these letters and numbers with the accompanying remote button .
It helps to make a table of these remote button and letters and numbers with each pressing of the remote .
Look at figure 4 .This is a table of the remote controls and serial numbers and remote button.
Then I Added Another Column
Then I added another column . If you click on the second address you can convert the serial numbers (Hex) to decimal numbers .See the second link rapid tables converts Hex to decimal
https://www.rapidtables.com/convert/number/hex-to-...
or better; https://www.binaryhexconverter.com/hex-to-decimal... (this on) After you open the link you will put in the serial number and the converter will change this to a decimal number .Note the decimal number and add it ti the table .We will use the decimal number in the Code for the remote and H bridge .
Hbridge and 2 Hobby Motors .
I will briefly talk about H bridges .
If you want to know more read the Instructable I wrote called "Using the Hbridge (293D) to drive 2 hobby motors ".
The Hbridge has an advantage over transistor or MOSFET because it can drive a motor forward and backward
The Circuit and the Codes
Next we will use the table and add the decimal numbers to the Hbridge Code .
The circuit is shown in the first diagram .
The First Button Is Pressed on the Remote
The first button is pressed on the remote(on ).The motors move to 149 rpms.
The Number 2 on the Remote Is Pressed
The number 2 on the remote is pressed.The one motor goes -160 rpms.
The Number 3 on He Remote Is Pressed
The number 3 on the remote is pressed. The one motor goes 160 rpms .
The Number 4 Is Pressed on the Remote.
The number 4 is pressed on the remote.and the motor goes -160 rpms.
The Number 5 Is Pressed on the Remote
the number 5 is pressed on the remote.the motors stop.
Summary
This Instructables shows how you can use a remote to control a H bridge 293D with 2 hobby motors .
The circuit and Code and table to do this is shown above .I made this circuit on Tinkercad .Each remote is different and the number serial and decimal will be different for each remote .
If you use your serial monitor and the link to convert the Hex code to decimal you will have your numbers for your remote . I enjoyed this project .I hope it helps you .Thank you