- Fri Jun 30, 2017 11:45 am
#195415
I bought a kit from a local company in India and list of components available with me is attached below. I'll be powering arduino with standard 9v battery. So I want to drive two motors from a Canon printer with 4*4v-1Ah batteries (pic attached) which obviously can't run with a H-bridge so I found the alternate which is Motor Shield, but I can't afford the arduino rev3 as I'll have to import that and other s use up all the pins which is not good so I found this(link below).
Also for using it with WiFi I either can use Ethernet shield (with a Pocket router and custom made webpage) or WiFi card (Idk which)(links below).
Amazon links- https://www.amazon.in/gp/aw/d/B00AXVX5D ... UIOPHJ56Y3
https://www.amazon.in/gp/aw/d/B01M6U29U ... 9VL3TSHL8J
https://www.amazon.in/gp/aw/d/B019IJ8EC ... F6BJA0G125
Will these work together?
Also attached below is the GPIO extension IDK how to use it.
Code to my current progress is below, where I've used PS2 stick, LCD, H bridge and servo (wired connection).
Link to pics - https://goo.gl/photos/pBL4ruVn5tkFrHASA https://goo.gl/photos/5aQgxZqmF2WaV1749
Avail stuff with me - https://goo.gl/photos/1fuQdE4SyeYEZSu16
Code -
include <Servo.h>
Servo myservo;
include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); int JoyStick_X = 0; int JoyStick_Y = 1; int JoyStick_Z = 1;
int dir1PinA = 2; int dir2PinA = 3; int speedPinA = 6;
int dir1PinB = 4; int dir2PinB = 5; int speedPinB = 7;
int LowSpeed = 100; int MedSpeed = 170; int HighSpeed = 255;
void setup(void) { myservo.attach(17);
lcd.begin(16, 2); lcd.clear(); pinMode(JoyStick_Z, INPUT_PULLUP);
Serial.begin(9600);
pinMode(dir1PinA, OUTPUT); pinMode(dir2PinA, OUTPUT); pinMode(speedPinA, OUTPUT); pinMode(dir1PinB, OUTPUT); pinMode(dir2PinB, OUTPUT); pinMode(speedPinB, OUTPUT); }
void loop(void) {
int x, y, z; x = analogRead(JoyStick_X); y = analogRead(JoyStick_Y); z = digitalRead(JoyStick_Z);
lcd.setCursor(0, 0); lcd.print("Car Status");
lcd.setCursor(0, 1); lcd.print("Spd:"); if (z == 0) { lcd.print("High"); } else if (x > 510 && x < 530) { lcd.print("No "); } else if (x > 530 && x < 730) { lcd.print("Low "); } else if (x > 730) { lcd.print("Med "); } else if (x < 510 && x > 250) { lcd.print("RLow"); } else if (x < 250) { lcd.print("RMed"); }
lcd.print(" "); lcd.setCursor(10, 1); lcd.print("Trn:"); if (y < 500) { lcd.print("L "); } else if (525 > y && y > 500) { lcd.print("-"); } else if (y > 525) { lcd.print("R "); } lcd.setCursor(11, 0); lcd.print("Bst:"); if (z == 0) { lcd.print("Y"); } else { lcd.print("N"); }
//________________Motor 1________________________ if (z == 0 && x > 10) { // Motor Forward High analogWrite(speedPinA, HighSpeed); digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); analogWrite(speedPinB, HighSpeed); digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); } else if (x > 530 && x < 730) {// Motor Forward Low analogWrite(speedPinA, LowSpeed);//Sets speed variable via PWM digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); analogWrite(speedPinB, LowSpeed);//Sets speed variable via PWM digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); }
else if (x > 730) {// Motor Forward Med analogWrite(speedPinA, MedSpeed); digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); analogWrite(speedPinB, MedSpeed); digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); }
else if (x > 510 && x < 530) {// Motor Stop analogWrite(speedPinA, 0); digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); analogWrite(speedPinB, 0); digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); }
else if (x < 510 && x > 250) { // Motor Reverse Low analogWrite(speedPinA, LowSpeed); digitalWrite(dir1PinA, HIGH); digitalWrite(dir2PinA, LOW); analogWrite(speedPinB, LowSpeed); digitalWrite(dir1PinB, HIGH); digitalWrite(dir2PinB, LOW); }
else if (x < 250 && x > 0) { // Motor Reverse Med analogWrite(speedPinA, MedSpeed); digitalWrite(dir1PinA, HIGH); digitalWrite(dir2PinA, LOW); analogWrite(speedPinB, MedSpeed); digitalWrite(dir1PinB, HIGH); digitalWrite(dir2PinB, LOW); }
myservo.write(40 + y * 8.7890625 / 100);
Also for using it with WiFi I either can use Ethernet shield (with a Pocket router and custom made webpage) or WiFi card (Idk which)(links below).
Amazon links- https://www.amazon.in/gp/aw/d/B00AXVX5D ... UIOPHJ56Y3
https://www.amazon.in/gp/aw/d/B01M6U29U ... 9VL3TSHL8J
https://www.amazon.in/gp/aw/d/B019IJ8EC ... F6BJA0G125
Will these work together?
Also attached below is the GPIO extension IDK how to use it.
Code to my current progress is below, where I've used PS2 stick, LCD, H bridge and servo (wired connection).
Link to pics - https://goo.gl/photos/pBL4ruVn5tkFrHASA https://goo.gl/photos/5aQgxZqmF2WaV1749
Avail stuff with me - https://goo.gl/photos/1fuQdE4SyeYEZSu16
Code -
include <Servo.h>
Servo myservo;
include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); int JoyStick_X = 0; int JoyStick_Y = 1; int JoyStick_Z = 1;
int dir1PinA = 2; int dir2PinA = 3; int speedPinA = 6;
int dir1PinB = 4; int dir2PinB = 5; int speedPinB = 7;
int LowSpeed = 100; int MedSpeed = 170; int HighSpeed = 255;
void setup(void) { myservo.attach(17);
lcd.begin(16, 2); lcd.clear(); pinMode(JoyStick_Z, INPUT_PULLUP);
Serial.begin(9600);
pinMode(dir1PinA, OUTPUT); pinMode(dir2PinA, OUTPUT); pinMode(speedPinA, OUTPUT); pinMode(dir1PinB, OUTPUT); pinMode(dir2PinB, OUTPUT); pinMode(speedPinB, OUTPUT); }
void loop(void) {
int x, y, z; x = analogRead(JoyStick_X); y = analogRead(JoyStick_Y); z = digitalRead(JoyStick_Z);
lcd.setCursor(0, 0); lcd.print("Car Status");
lcd.setCursor(0, 1); lcd.print("Spd:"); if (z == 0) { lcd.print("High"); } else if (x > 510 && x < 530) { lcd.print("No "); } else if (x > 530 && x < 730) { lcd.print("Low "); } else if (x > 730) { lcd.print("Med "); } else if (x < 510 && x > 250) { lcd.print("RLow"); } else if (x < 250) { lcd.print("RMed"); }
lcd.print(" "); lcd.setCursor(10, 1); lcd.print("Trn:"); if (y < 500) { lcd.print("L "); } else if (525 > y && y > 500) { lcd.print("-"); } else if (y > 525) { lcd.print("R "); } lcd.setCursor(11, 0); lcd.print("Bst:"); if (z == 0) { lcd.print("Y"); } else { lcd.print("N"); }
//________________Motor 1________________________ if (z == 0 && x > 10) { // Motor Forward High analogWrite(speedPinA, HighSpeed); digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); analogWrite(speedPinB, HighSpeed); digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); } else if (x > 530 && x < 730) {// Motor Forward Low analogWrite(speedPinA, LowSpeed);//Sets speed variable via PWM digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); analogWrite(speedPinB, LowSpeed);//Sets speed variable via PWM digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); }
else if (x > 730) {// Motor Forward Med analogWrite(speedPinA, MedSpeed); digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); analogWrite(speedPinB, MedSpeed); digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); }
else if (x > 510 && x < 530) {// Motor Stop analogWrite(speedPinA, 0); digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); analogWrite(speedPinB, 0); digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); }
else if (x < 510 && x > 250) { // Motor Reverse Low analogWrite(speedPinA, LowSpeed); digitalWrite(dir1PinA, HIGH); digitalWrite(dir2PinA, LOW); analogWrite(speedPinB, LowSpeed); digitalWrite(dir1PinB, HIGH); digitalWrite(dir2PinB, LOW); }
else if (x < 250 && x > 0) { // Motor Reverse Med analogWrite(speedPinA, MedSpeed); digitalWrite(dir1PinA, HIGH); digitalWrite(dir2PinA, LOW); analogWrite(speedPinB, MedSpeed); digitalWrite(dir1PinB, HIGH); digitalWrite(dir2PinB, LOW); }
myservo.write(40 + y * 8.7890625 / 100);