Motor shield not moving as expected - arduino

Motor shield is not working as expected when connected to battery. When Arduino is connected to USB, motor is moving both FORWARD and BACKWARD, but when connected to battery, it moving only in FORWARD direction. I don't think so it's battery issue, because motor speed is good even it moves only in FORWARD direction.
Below is the code,
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
void setup() {
Serial.begin(9600);
Serial.println("Motor");
motor1.setSpeed(254);
motor2.setSpeed(254);
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void loop() {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
delay(500);
motor1.run(FORWARD);
motor2.run(FORWARD);
delay(500);
}

Well, it should work with your above code. But note that there is a jumper on the shield that you have to remove in order to power it through the battery.

Requires a little power trigger or if we wait for around 2-3 minutes the motor works good. Motor shield drains the battery often. Seems to be it requires more power supply. Power supply from USB cable works perfectly rather than batteries

Related

Particle Photon, controlling a PCF8574 via I2C- works on Arduino

I'm trying to read and control some buttons and LEDs on a Bang & Olufsen infrared eye. It uses a pcf8574 microcontroller to control 2 LEDs and 4 buttons. First of all I just want to get the LEDs to blink. I have successfully done that with an Arduino Uno.
But I want to use it with an Particle Photon so I can connected to the internet. Here I have the code that worked on the Arduino:
#include <Wire.h>
#define beolink (B0100000)
void setup() {
Wire.begin();
}
void loop() {
Wire.beginTransmission(beolink);
Wire.write(0b11111111);
Wire.endTransmission();
delay(1000);
Wire.beginTransmission(beolink);
Wire.write(0b00111111);
Wire.endTransmission();
delay(1000);
}
I have no errors on the Particle Photon. I have also tried switching cables and tried 5v instead of the 3.3v. I have connected the pins on the Particle Photon to the same as on the Arduino [SCL(D1) & SDA(D0)].
Thanks to this guy: https://community.particle.io/u/scruffr/summary
It now works. It was not a problem with the code. Apparently you need 2 pull-up resistors on the I2C pins on a Particle Photon. thank you

Arduino LED not blinking

I am a beginner to ARDUINO. My connections i guess is fine. But LED does not blink. Green and Orange light is blinking on ARDUINO. Anode to pin 13 with 320K resistor and Cathode to ground
Code is as follows
const int LED=13;
void setup()
{
// put your setup code here, to run once:
pinMode(LED,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
delay(1000);
}
Looks like you plugged one of the legs in ground and one in Another slot.
Check your connections and if it doesn't work, try using another led, and switching the polarities.
The problem here in that you haven't connected anything to pin 13!
Also, a 320K ohm resistor is a little overkill. Usualy, a 220 ohm resistor is enough.
Also, the flat side of the led is the negative side. It is more reliable then if you are following the pins size which isn't always constant.
You need a resistor even if using pin13.
The led in the shield has it's own resistor but if you plug your own you need a resistor.
Take a look at this post:
https://electronics.stackexchange.com/questions/66992/pin-13-do-i-need-a-resistor
hello you can try removing the 320K resistor and replacing it with 220 ohms resistor or directly connec t LED to pin 13 because the onboard resistor is on

Arduino Uno DC Motor not working with simple test. Can not get Arduino to spin the motor

I am using the V2.3 motorsheild on the arduino uno r3.
I no almost nothing about ardunio excpet from what ive read about the past week.
I have been trying to simply turn the motor with the code below and it wont work. I have the arduino plugged into my computer and 12v going to the blue power box thing.
I am using this motor https://www.servocity.com/html/900_rpm_micro_gearmotorblocks.html#.VyELIFaDFBc
I cannot get the dang thing to spin, motor works fine if i wire it straight to the 5v/grnd but not when its in the M1 connection
wiring: https://i.groupme.com/747x1328.png.54a01e30433241d4a99905bd0e8ede2b let meknow if this link doesnt work
Heres an Imgur link for the wiring http://imgur.com/J92ewnu
#include
AF_DCMotor motor(1);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
// turn on motor
motor.setSpeed(200);
motor.run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
motor.run(FORWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
motor.setSpeed(i);
delay(10);
}
Serial.print("tock");
motor.run(BACKWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
motor.setSpeed(i);
delay(10);
}
Serial.print("tech");
motor.run(RELEASE);
delay(1000);
}
I am not expert in current particular shield and its library. But what i see when first time look at your sketch and motor connection image is that you are trying to run dc motor at a certain speed with commands, which seems to be for servo or stepper motors.
You should know that running DC motor at some speed is possible if you have speed calculation based on its current and voltage or when a speed sensor is located at motor's shaft. This motor doesn't have the sensor (i know it for sure, because used same in my projects) and i think the shield can't calculate speed. What you can is only switch it on and off and maybe change its direction.
So, first of all you should look (and use) at the library for such functions.
Looking for what the function you called "AF_DCMotor" does I see how you were confused. There is also this product, which is another adafruit motor sheild.
But it's actually a very different motor driver. Both shields have a power stage which takes pulses and amplifies them to drive a motor. The V2 apparently has a chip which generates these pulses, and you send it serial data to command it using I2C. The V1 just gets these pulses directly from the Arduino.
For yours, a V2 motor shield, try the guide Adafruit provides.
Here's the link - Adafruit Motor Sheild V2 DC motor control
And here's the code
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
AFMS.begin();
myMotor->setSpeed(100);
myMotor->run(FORWARD);
It mentions the use of I2C on the introductory page
Instead of using a latch and the Arduino's PWM pins, we have a fully-dedicated PWM driver chip onboard. This chip handles all the motor and speed controls over I2C
That's why it includes the Wire library. You could make your own code to run this, but it would have to use I2C to send commands to the PWM driver chip they are using.

Arduino 16x2 LCD Stays Blank

I am using an Arduino Mega with a 16x2 LCD. When I start the Arduino the LCD flashes white and sometimes random lines will show up and gradually fade out. The backlight is on, however, so the LCD is not inverted. At first I thought the Arduino was not getting enough power because I am using a Raspberry Pi to program it, but plugging in a 6V battery pack did not change the result. I tried plugging in a different 16x2 LCD to check if the one I was using is broken, but again, the result was the same. I have triple-checked my connections, adjusted the potentiometer, and fiddled around with where the LCD was connected on the breadboard in case some of the pins were broken, but to no avail.
Does the LCD have a problem with Arduino Mega boards? Or am I just unfortunate enough to have two broken LCDs?
Code:
#include <LiquidCrystal.h>
#define led_pin 22
#define buzzer_pin 7
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(buzzer_pin, OUTPUT);
lcd.begin(16,2);
digitalWrite(led_pin, HIGH);
tone(buzzer_pin, 1000, 500);
delay(500);
digitalWrite(led_pin, LOW);
lcd.print("LCD Test");
}
void loop() {
}
EDIT
I moved the LCD and wiring back to the other side of the breadboard and it did not change the output. I'm starting the think that the LCDs are just simply broken because the LCDs will randomly flash and fade unevenly. I found that these LCDs can be easily fried by incorrectly adjusting the potentiometer.
Make sure that you solder headers to the lcd, then press the headers into your breadboard and connect to arduino with jumper wires. Just resting the LCD on the headers without solder or jabbing the lcd pin holes with jumper wires don't make reliable connections. You WILL see random stuff
Make sure you connect the LCD correctly. If you did, you wouldn't have got any problems. Post a picture.
Make sure the pins you used in the code match pins you connected to the LCD.
Best way to get arduino help is on arduino forum.
Specifically which LCD are you using?
Do you have datasheets for the exact LCD you are using so you can confirm you have the correct wiring and supply voltages?
If you still have no luck, you may want to try a LCD module that has a serial, i2c, or spi interface.
They are much easier to use than HD44780 parallel modules (im assuming this is what you have).
An example source of such modules is https://www.crystalfontz.com/c/character-lcd-displays/interface/24

Arduino UNO + Ethernet Shield + Ultrasonic Sensor = Fail

With my Arduino Uno I measure the distance using HC-SR04 ultrasonic sensor with no problems at all using the wiring below.
When I attach ethernet shield, my ultrasonic sensor does not measure distance any more, it constantly says 0cm no matter what. I have tried different digital pin pairs such as 5-7, 6-8, 5-9, 3-5, 2-8 but no luck.
I suspect that HC-SR04 is not compatible with my Ethernet shield but I haven't seen such warning anywhere on the net.
There are no components attached to arduino besides ethernet shield and the ultrasonic sensor itself.
There is no SD Card in SD Card slot.
My ethernet shield works fine while running a web server or web client script.
Digital pins of ethernet shield works fine with all other components such as temperature sensor, motion sensor etc.
Here is the ethernet shield I have;
http://www.ezshopfun.com/product_info.php?products_id=169
Here is my actual circuit;
http://s7.postimg.org/vyi2z36qz/20140826_001130.jpg
http://s7.postimg.org/6eb7ewvzf/20140826_001150.jpg
http://s7.postimg.org/6psnrocff/20140826_001156.jpg
http://s7.postimg.org/y6ro2ooh7/20140826_001229.jpg
http://s7.postimg.org/71a44fsvf/20140826_001247.jpg
Here is my code;
#define trigPin 6
#define echoPin 7
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH) / 2;
distance = duration / 29.1;
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
Today I bought a multimeter and tested my circuit. Here are the results;
When my circuit directly attached to Arduino itself;
4.80V & 5.7mA
When my circuit attached to ethernet shield;
3.06V & 3.8mA
I think the problem is that 3.06V is not enough for my HC-SR04 to operate.
Yeah based on this photo
you're not grounding your sensor. You have two power supplies going into it. This, needless to say, is bad for a number of reasons. First and foremost because it wont work ungrounded lol
As others have said, it looks like the main issue is that you need this connected to 5V and check your wiring generally.
However, there is another potential issue:
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
You only need to set the trigger pin high for 10 microseconds, not 1000 microseconds. I don't know if this is an issue or not but there is no need to wait this long. You could potentially be missing some or all of the incoming pulse by waiting that long.
You might want to checkout out some HC-SR04 tutorials too, like this one:
http://superawesomerobots.com/tutorials/hc-sr04-tutorial-for-arduino/
Hope that helps.
I had a similar problem with a wifi shield + ultrasonic sensor. I found switching from pins 13(trig) and 11(echo) to 8(trig) and 3(echo) fixed it.
See here: http://forum.arduino.cc/index.php?topic=201827.0

Resources