Greetings all,
I am stumped with my recent project design. I am using arduino uno, with a 3vdc motor, MG90 servo motor.
I understand that the dc motor needs a driver, and I already had an L298n (which i've read is extremely inefficient, and very old tech, so i would be willing to switch it out of the design) so Ive used that, and supplied 12v (8xAA) to the driver. I also have another 12v in the project to supply power for the arduino, and the servo.
I am attaching the current schematic created on tinker cad. (which was missing the L298n)
I am also pasting the code for this project, compiled from a few other examples.
This project works Exactly as desired when plugged into usb power supply from computer. however the dc motor does not operate when working only off of battery.
I have also created and added a voltage meter with i2c display to read the current voltages of the batteries while the project operates.
Any help or advice would be greatly appreciated.
#include <ezButton.h>
#include <Servo.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int enA = 9;
int in1 = 8;
int in2 = 7;
float v_in1 = 0.0; // sets the value of the variable v_in to 0.0
float v_in2 = 0.0;
float VRead1 = 0.0; // sets the value of VRead to 0.0
float VRead2 = 0.0;
float const factor = 11.03;
ezButton limitSwitch(6);
Servo servo_1;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
0b00000001, 0b11000000,
0b00000001, 0b11000000,
0b00000011, 0b11100000,
0b11110011, 0b11100000,
0b11111110, 0b11111000,
0b01111110, 0b11111111,
0b00110011, 0b10011111,
0b00011111, 0b11111100,
0b00001101, 0b01110000,
0b00011011, 0b10100000,
0b00111111, 0b11100000,
0b00111111, 0b11110000,
0b01111100, 0b11110000,
0b01110000, 0b01110000,
0b00000000, 0b00110000 };
void setup() {
Serial.begin(9600);
servo_1.attach(10);
limitSwitch.setDebounceTime(50);
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
servo_1.write(0);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(3000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(25,0);
display.print("Are you");
display.setCursor(15,15);
display.print("Ready For");
display.display();
delay(5000);
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("GLITTER");
display.startscrollleft(0x00, 0x0F);
display.display();
delay(5000);
display.stopscroll();
/* delay(1000);
display.startscrollleft(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrolldiagright(0x00, 0x07);
delay(2000);
display.startscrolldiagleft(0x00, 0x07);
delay(2000);
display.stopscroll();
delay(1000);
*/
}
void loop() {
limitSwitch.loop();
if(limitSwitch.isReleased())
{
delay(2000);
servo_1.write(245);
delay(2000);
analogWrite(enA, 255);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(2000);
analogWrite(enA, 0);
delay(2000);
servo_1.write(0);
}
else if (limitSwitch.isPressed())
{ analogWrite(enA, 0);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
int analogIn1=analogRead(A0);
int analogIn2=analogRead(A1);
Serial.println(analogIn1);
Serial.println(analogIn2);
VRead1= (analogIn1*5/1024.0);
VRead2 = (analogIn2*5/1024.0);
Serial.println(VRead1);
Serial.println(VRead2);
v_in1 = VRead1*factor;
v_in2 = VRead2*factor;
Serial.print("Input Voltage");
Serial.println(v_in1);
Serial.println(v_in2);
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner
display.println(F("B 1"));
display.setCursor(55,0);
if (v_in2 <=10) display.print('0');
display.print(v_in1);
display.print("V");
display.setCursor(0, 16); // Start at top-left corner
display.println(("B 2"));
display.setCursor(55,16);
if (v_in2 <= 10) display.print('0');
display.print(v_in2);
display.print("V");
display.display();
delay(2000);
}