i want to press "unu" button of the remote, and the motor to rotate continuously, and when i press "sound" i want the motor to rotate untill the hall sensor detects a magnetic field. any ideas please? in this configuration, even if i press "unu" or "sound", the motor rotates untill the hall sensor detects a magnetic field.

#include <TLE94112.h>
#include <Tle94112Motor.h>
#include <IRremote.h>

#define unu 0x1
#define sound 0x55

int RECV_PIN = 2;
int hallSensorPin1 = 3;
int state1;
int oldState1 = 1;

Tle94112 controller = Tle94112();
Tle94112Motor motor1(controller);

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{ irrecv.enableIRIn();

  motor1.connect(motor1.HIGHSIDE, controller.TLE_HB1);
  motor1.connect(motor1.LOWSIDE, controller.TLE_HB2);
  motor1.setPwm(motor1.HIGHSIDE, controller.TLE_PWM2);
  motor1.setPwmFreq(motor1.HIGHSIDE, controller.TLE_FREQ200HZ);


void loop()
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
  }//add bracket here

  if (results.value == unu || results.value == 0x801 || results.value == 0x2049) {

  if (results.value == sound || results.value == 0x55 || results.value == 0x2103 || results.value == 0x837 || results.value == 0x37) {

    oldState1 = 1;
    state1 = digitalRead(hallSensorPin1);

    if (state1 == LOW && oldState1 == 1) {


  • thanks for your observation. i fixed this.
    – Tincu Ioan
    Jul 11, 2020 at 18:58
  • the two if (results.value == statements execute the same code
    – jsotola
    Jul 11, 2020 at 19:06
  • yes, and i tried the configuration that you can see now in the initial post (i updated it) and this one works fine for continuous rotation, but when the magnetic field is detected, the motor receives small pulses without pressing any button, and again when its not detecting a magnetic field, rotates normally till it finds again the magnetic field.
    – Tincu Ioan
    Jul 11, 2020 at 19:11
  • introduce a layer of separation between if (results.value == and motor1.start(63); .... the if statement should only set two flags, motorOn and motorMode (you pick names) .... there should be only one code line that turns on the motor if (motorOn) { .... the hall sensor code should be wrapped in if (motorMode) {
    – jsotola
    Jul 11, 2020 at 19:20
  • you provided incomplete information ... i see nothing in your post about the serial monitor output
    – jsotola
    Jul 11, 2020 at 19:23


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.