Offline
Newbie
Karma: 0
Posts: 14
|
 |
« on: July 26, 2011, 08:47:34 am » |
Hi I recently bought Arduino Mega 1280 and a HC-SR04 Ultrasonic Sensor(Hong Kong) for a project. I uploaded this code onto the chip: #include "Ultrasonic.h" Ultrasonic ultrasonic(12,13); void setup() { pinMode(11, OUTPUT); /* Additional pin setting */ digitalWrite(11, HIGH); /* Additional pin setting */ Serial.begin( 9600 ); } void loop() { Serial.print( ultrasonic.Ranging(CM) ); Serial.println( "cm" ); delay(1000); }
But for the output from the Serial Monitor, I just keep getting "0 CM...0 CM..0 CM...". Where am I going wrong? Thanks
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
God Member
Karma: 9
Posts: 895
Twitter: @simonmonk2
|
 |
« Reply #1 on: July 27, 2011, 07:19:27 am » |
Some suggestions:
* Check your hardware connections.
* Check the supply voltage is reaching the ranging module - with a multimeter.
* Disconnect everything (assuming breadboard) and build it all again.
* Try it on different pins (hardware and software)
|
|
|
|
|
Logged
|
|
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #3 on: August 04, 2011, 12:11:56 pm » |
Hi i'm working with this sensor, i'm making a car. When i connect the sensor and the motor, the distance from the sensor is not correct, i think the wheels make a lot of noise, maybe it's a problem? Because, if i disconnect the wheels, the distance is correct.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
God Member
Karma: 9
Posts: 895
Twitter: @simonmonk2
|
 |
« Reply #4 on: August 04, 2011, 12:19:58 pm » |
Put a 100nF non-polarised capacitor across each motor. This will suppress the interference.
|
|
|
|
|
Logged
|
|
|
|
|
Bristol, UK
Offline
Edison Member
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
|
 |
« Reply #5 on: August 04, 2011, 12:21:30 pm » |
That does sound like a noise problem. It may be electrical noise conducted through the power supply, or it may be acoustic noise (sound) generated by the motor(s). This may be a difficult one to fix! First of all, do you have any power supply decoupling capacitors? And are you using the same power supply (batteries, presumably) for both motors and the sensor/Arduino?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #6 on: August 04, 2011, 12:25:54 pm » |
That does sound like a noise problem. It may be electrical noise conducted through the power supply, or it may be acoustic noise (sound) generated by the motor(s). This may be a difficult one to fix! First of all, do you have any power supply decoupling capacitors? And are you using the same power supply (batteries, presumably) for both motors and the sensor/Arduino?
I supplying all circuit with the Arduino pin 5V, and i'm controling the motor's with a L298N Bridge. All ready, the motor's have a 100nf capacitor
|
|
|
|
|
Logged
|
|
|
|
|
Bristol, UK
Offline
Edison Member
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
|
 |
« Reply #7 on: August 04, 2011, 12:32:45 pm » |
If you're supplying the motors with power from the Arduino's 5V output, then that may be part of the problem. Can you try using a separate power supply for the motors, with just the grounds connected together. That is, power the Arduino and sensor as you have it now, but disconnect the power to the motors. Then, use a second battery to supply the motor power. Remember to leave the grounds connected.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #8 on: August 04, 2011, 12:39:56 pm » |
If you're supplying the motors with power from the Arduino's 5V output, then that may be part of the problem. Can you try using a separate power supply for the motors, with just the grounds connected together. That is, power the Arduino and sensor as you have it now, but disconnect the power to the motors. Then, use a second battery to supply the motor power. Remember to leave the grounds connected.
ok! it's for this!  But, how can i supply the motor and arduino? at same time? with only one batery?
|
|
|
|
|
Logged
|
|
|
|
|
Bristol, UK
Offline
Edison Member
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
|
 |
« Reply #9 on: August 04, 2011, 12:40:48 pm » |
You need two batteries. One battery for Arduino and sensor, the other battery for the motors.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #10 on: August 04, 2011, 12:45:00 pm » |
ok!! i'm going to use a 9V batery and a LM78L05 to supply the motors! Thank's you!
|
|
|
|
|
Logged
|
|
|
|
|
Bristol, UK
Offline
Edison Member
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
|
 |
« Reply #11 on: August 04, 2011, 12:46:56 pm » |
You may find that a 78L05 is too small to power the motors. It can only supply 100mA. The 9V battery will soon be used up, too. A 7805 regulator will be good for 1A. Do you know how much current your motors will draw?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #12 on: August 04, 2011, 12:52:38 pm » |
i just trying with a L7805, and the motors and the sensor it's ok, I dont know the caracteristics of the motor, it's from a toy 
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
God Member
Karma: 9
Posts: 895
Twitter: @simonmonk2
|
 |
« Reply #13 on: August 04, 2011, 01:10:59 pm » |
If the motor is ok with 5V it is probably also fine with 6V, so you could make up a battery pack with 4 rechargeable AA cells. They will last a lot longer than a small 9V battery and you will not need the voltage regulator.
|
|
|
|
|
Logged
|
|
|
|
|
|