Hi Larry,
I don´t have a schematic available but it is pretty straight forward on the DC-Motors.
The overall project is getting more and more complex since I´m adding more and more functionality and sensors.
I´m using this Mega board here…
Arduino MEGA 2560 With WiFi Built-in - ESP8266 : 10 Steps - Instructables
I also use a second DC Motor Controller (IBT2) for a linear actuator but this one gives me no trouble.
I´ve also a joystick, 4 photo resistors, the compass module HMC5883L as well as one interrupt push button and an LED on the prototype board included.
So the code has grown a lot and has currently 400 lines, so I don´t want to post it all in the thread. Or is this not a problem?
The DC-Controller which gives me the problem is connected to the Pins 8 – 13 (4x digital + 2x PWM being 9-10)
This is the definition of pins and variables...
/ for switch control automatic vs manual mode
int mode = 0; //0 = manual, 1 = automatic
int modePin = 2; //input switch interrupt
int LEDPin = 5; //output LED with 330 Ohm resistor
int modeOld = 1; //1 = if switch is not pressed with 10K Ohm pull-up resistor, 0 = if switch is presssed
int modeNew; //will be read
// for compass modul HMC5883L
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
float headingDeg;
Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(777); //Assign a unique ID to this sensor in ()
// V5 = red
// GND = blue
//SDA pin = brown --> A4
//SCL pin = white --> A5
// for automatic mode with photo resistors
int PRs = A0; //Photorisitor South with 100K Ohm resistor
int PRsVal;
int PRn = A1; //Photorisitor North with 100K Ohm resistor
int PRnVal;
int PRe = A2; //Photorisitor East with 100K Ohm resistor
int PReVal;
int PRw = A3; //Photorisitor West with 100K Ohm resistor
int PRwVal;
int dv = 100; //delay 100
int dif = 50; //start adjusting when difference is greater than ...
int night = 300; // constant for night modus
int cloudy = 500; // constant for cloudy modus
int time = 10; // constant for time delay in automatic modus
int count = 0; // counter for time delay in automatic modus
String com = "Hello Day!";
String dir = "Lets chase the Sun";
String lev = "and Level up!";
// for manual mode with joystick
int xWert;
int yWert;
// for motor control via WSDC2412D (dual DC Motor Controler for driving wheels)
int enA = 9; //Motor speed left PWM
int in1 = 8; //Motor direction left
int in2 = 13; //Motor direction left
int enB = 10; //Motor speed right PWM
int in3 = 12; //Motor direction right
int in4 = 11; //Motor direction right
int motLSpeed, ml;
int motRSpeed, mr;
// for motor control via IBT2 (single DC Motor Controler for Linear Actuator)
int IBT2a = 6; //PWM up
int IBT2b = 7; //PWM down
// for PMW frequency change
int myEraser = 7; // this is 111 in binary and is used as an eraser
int myPrescaler = 2; // this could be a number in [1 , 6] [2] is equal to 4000Hz on Pins 2,3,5,6,7,8,9,10,11,12 and 7800Hz on Pins 4,13
This is the complete void setup ()...
void setup() {
Serial.begin (9600);
pinMode (modePin,INPUT); // for switch control automatic vs manual mode
pinMode (LEDPin,OUTPUT); // for switch control automatic vs manual mode
pinMode (PRs,INPUT); // for automatic mode with photo resistors top left
pinMode (PRn,INPUT); // for automatic mode with photo resistors top right
pinMode (PRe,INPUT); // for automatic mode with photo resistors bottom left
pinMode (PRw,INPUT); // for automatic mode with photo resistors bottom right
pinMode (enA, OUTPUT); // for motor control via WSDC2412D
pinMode (enB, OUTPUT); // for motor control via WSDC2412D
pinMode (in1, OUTPUT); // for motor control via WSDC2412D
pinMode (in2, OUTPUT); // for motor control via WSDC2412D
pinMode (in3, OUTPUT); // for motor control via WSDC2412D
pinMode (in4, OUTPUT); // for motor control via WSDC2412D
pinMode (IBT2a, OUTPUT); // for motor control via IBT2
pinMode (IBT2b, OUTPUT); // for motor control via IBT2
analogWrite(enA, 0); // Set 0 at start for safety
analogWrite(enB, 0); // Set 0 at start for safety
analogWrite(IBT2a, 0); // Set 0 at start for safety
analogWrite(IBT2b, 0); // Set 0 at start for safety
attachInterrupt(digitalPinToInterrupt(modePin),checkSwitch, CHANGE); // Attach Interrupt to Interrupt Service Routine
TCCR2B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR2B to 0 (timer 2 controls pin 10, 9);
TCCR4B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR4B to 0 (timer 4 controls pin 8, 7, 6);
TCCR2B |= myPrescaler; // this operation (OR), replaces the last three bits in TCCR2B with our new value
TCCR4B |= myPrescaler; // this operation (OR), replaces the last three bits in TCCR4B with our new value