element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
EZ-EV Challenge
  • Challenges & Projects
  • Design Challenges
  • EZ-EV Challenge
  • More
  • Cancel
EZ-EV Challenge
Forum SmartAssist EV - Wireless Command and H-Bridge Direct Drive - Part 3
  • News
  • Projects
  • Forum
  • DC
  • Leaderboard
  • Files
  • Members
  • More
  • Cancel
  • New
Join EZ-EV Challenge to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 0 replies
  • Subscribers 60 subscribers
  • Views 25 views
  • Users 0 members are here
Related

SmartAssist EV - Wireless Command and H-Bridge Direct Drive - Part 3

jelektro
jelektro 4 hours ago
Every robotic vehicle requires a foundation for movement and communication. We begin with an Infrared (IR) receiver based on the standard IRremote library alongside a continuous PWM-controlled H-Bridge system.
By mapping explicit hex codes from a handheld remote, the car acts on standard movement directions. Because a single button press should not trigger indefinite movement, an optional timeout sequence safely cuts power to the motors when the transmitter goes quiet.
This sketch boots the vehicle into manual mode, giving you directional control via your handheld remote. When a key is released, a built-in safety timeout automatically halts the motors to prevent runaway scenarios.
On the Arduino UNO Q board, the analogWrite() function might not work correctly if you explicitly define the pin mode using pinMode(pin, OUTPUT).
Due to its architecture and a known issue in the underlying Zephyr core, removing the pinMode statement from your setup() function allows the PWM signal to generate properly.
How to use analogWrite on UNO Q?
  • Do not call pinMode(pin, OUTPUT) for your chosen PWM pin.
  • Call analogWrite(pin, value) directly in your code.
  • The value ranges from 0 (always off) to 255 (always on).
#include <Arduino.h>
#include <IRremote.hpp> // Requires installing the IRremote library in Arduino IDE

// L9110S Motor Driver Pins (All support hardware PWM)
const int motorPinA_1A = 5; 
const int motorPinA_1B = 6; 
const int motorPinB_1A = 9; 
const int motorPinB_1B = 10;

// Infrared Receiver Pin (Requires interrupt-capable pin)
const int IR_RECEIVE_PIN = 2; 

// Base motor speed (Scale 0-255)
const int motorSpeed = 200; 

// Safety timeout tracking to stop the robot when button is released
unsigned long lastCommandTime = 0;
const unsigned long commandTimeout = 250; // milliseconds

void motor(int A1, int A2, int B1, int B2) {
  analogWrite(motorPinA_1A, A1);
  analogWrite(motorPinA_1B, A2);
  analogWrite(motorPinB_1A, B1);
  analogWrite(motorPinB_1B, B2);
}

void exec_cmd(byte key_val) {
  switch (key_val) {
    case 0x18: // Up Arrow - Drive Forward
      motor(0, motorSpeed, 0, motorSpeed);
      break;
    case 0x08: // Left Arrow - Spin Left
      motor(motorSpeed, 0, 0, motorSpeed);
      break;
    case 0x5A: // Right Arrow - Spin Right
      motor(0, motorSpeed, motorSpeed, 0);
      break;
    case 0x52: // Down Arrow - Reverse Backward
      motor(motorSpeed, 0, motorSpeed, 0);
      break;
    default:
      motor(0, 0, 0, 0); // Any unassigned key dead-stops the robot
      break;
  }
}

void setup() {
  Serial.begin(9600);
  
//  pinMode(motorPinA_1A, OUTPUT);
//  pinMode(motorPinA_1B, OUTPUT);
//  pinMode(motorPinB_1A, OUTPUT);
//  pinMode(motorPinB_1B, OUTPUT);
  
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); 
  Serial.println("Code 1: IR Remote Control Ready.");
}

void loop() {
  if (IrReceiver.decode()) {
    byte command = IrReceiver.decodedIRData.command;
    Serial.print("Received IR Hex: 0x");
    Serial.println(command, HEX);
    
    exec_cmd(command);
    lastCommandTime = millis(); // Refresh command timestamp
    IrReceiver.resume(); 
  }
  
  // If the timeout window expires without a repeat command, cut power to motors
  if (millis() - lastCommandTime > commandTimeout) {
    motor(0, 0, 0, 0);
  }
}
  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube