Motors not working with Nunchuk

I'm building a Nerf Rival Plasmacaster and I've got the servo motors and a laser module working from a Wii Nunchuk interface (Joystick moves servo motors, button c activates laser).

However, when I try to use the flywheels, (button z), it won't work.

At first I thought it might be an issue with power, so I used a L298 board to try and drive it and while the lights came on the L298, nothing else happened.

The only other thing that might be causing a problem is that I'm using a Nano and it worked successfully on an Uno in the past.

Any help would be appreciated.

#include <Servo.h>
#include <Wire.h>
#include "Nunchuk.h"

Servo myservo1;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo

int pos1 = 0;    // variable to store the servo position
int pos2 = 0;    // variable to store the servo position
int laserPin = 11;
int enA = 6;
int in1 = 7;
int in2 = 8;

void setup() {

  Wire.begin();
  nunchuk_init_power(); // A1 and A2 is power supply
  nunchuk_init();
  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(10);  // attaches the servo on pin 9 to the servo object
  pinMode (laserPin, OUTPUT);
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
}

void loop() {
  if (nunchuk_read()) {
    pos1 = map(nunchuk_joystickX(), -128, 128, 180, 0);
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos'
    // pos2 = constrain(nunchuk_accelY(),-150, 150);
    //pos2 = map(pos2,-150, 150, 180, 100);
    //myservo2.write(pos1);              // tell servo to go to position in variable 'pos'
    pos2 = map(nunchuk_joystickY(), -128, 128, 45, 170);
    myservo2.write(pos2);              // tell servo to go to position in variable 'pos'

    if (nunchuk_buttonC() == HIGH) {
      // turn laser on:
      digitalWrite (laserPin, HIGH);
    } else {
      // turn laser off:
      digitalWrite(laserPin, LOW);
    }

    if (nunchuk_buttonZ() == HIGH) {
      // turn flywheels on:
        digitalWrite(in1, HIGH);
        digitalWrite(in2, LOW);
    } else {
      // turn flywheels off:
      digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);;
    }
  }
  delay(20);
}

Can you show a diagram of how you have this connected?

How are you powering the project?

How are you powering the motor driver?

The Uno and the classic Nano both have exactly the same chip. The only thing that could be different is that on the classic Nano, there is a link that allows it to run off 3V3 and not 5V, How have you set that link?

I've connected 5v from the L298 to the 5v on the Nano. The L298 is drawing power from a 9v battery.

The circuit and L298 are being powered by a 9v battery.

I'll post a picture when I get a chance

I could have guessed.

The 9V can't provide the current for the motor. You need more battery. 4 AA or 2 18650's should do. Less voltage but way more power.

The small rectangular batteries?
These are useless for driving motors because:-

  1. They have a high ESR (Effective Serial Resistance) so the current available through them is limited.

  2. They have very little current capacity and discharge quite quickly when driving motors.

A schematic would be much better than words.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.