Hello,
I just bought my first arduino board and I'm very excited to make my first project!
Unfortunately, I have never done anything with electronics and programing and
therefore I would really appreciate any help!
The project is very simple: using a supersonic sensor, I want to adjust the speed
of the motor dependingon the distance from an object.
I bought this but it feels like I forgot about something:

I would really appreciate any help!
Thank you in advance!
PS. I found some topics with a similar project but only about programming.
If you know any similar topics that you think I should read, please share!
Best regards,
Tom
Can you give the specs of the motor (a link will do as well); you might require a dedicated power supply for it and you might (more than likely will) also need transistors / fets. You will also need a flyback diode.
What you might have forgotton is a means to wire the motor to the Arduino or breadboard.
Have a look at the pictures
A breadboard holder can be useful; alternatively stick the breadboard to a piece of wood and screw the Arduino to that same piece of wood (use small screws). This is to prevent possible shorts when you accidentally place the Arduino on e.g. a pair of pliers.
Thank you for such a fast reply!
That's the motor I have:

I will explore the shops for all the missing parts!
Thank you again for the help and advice!
The Arduino Start Kit comes with more material and a projects book, describing several projects in small steps, easy to follow by beginners. The material includes switches, LEDs, resistors, motor drivers and more parts, which are required in almost every project. Eventually the Arduino Projects Book is available separately?
You'll need some motor driver module or FET to drive the motor, because the Arduino outputs can't supply that much current.
Thank you!
I will check out the Started Kit and the Projects Book!
Thank you so much!
Reading everything now!
Hello again everyone!
Thanks again for all the earlier advice! I bought all the missing things (I hope)!
I uploaded a simple code to check if the motor works and everything was great!
I managed to control the speed and everything! However the dc motor is not that strong,
it slows down even with the slightest touch of my finger.
I tried the ultrasonic sensor too and it seems to be working good!
There is one problem though. After a while the sensor stops showing the proper distance,
the RX diode blinks slowly and regularly and the distance shown is 0 inch, 0 cm.

Anybody has any idea what is wrong?
I followed this tutorial:
Thanks in advance!
Show us your code in a proper way
By using code tags
type
** **[code]** **
paste your code after that
type
** **[/code]** **
after that
So the result in a post looks like
your pasted code here
Sorry for not posting the code
/* HC-SR04 Sensor
https://www.dealextreme.com/p/hc-sr04-ultrasonic-sensor-distance-measuring-module-133696
This sketch reads a HC-SR04 ultrasonic rangefinder and returns the
distance to the closest object in range. To do this, it sends a pulse
to the sensor to initiate a reading, then listens for a pulse
to return. The length of the returning pulse is proportional to
the distance of the object from the sensor.
The circuit:
* VCC connection of the sensor attached to +5V
* GND connection of the sensor attached to ground
* TRIG connection of the sensor attached to digital pin 2
* ECHO connection of the sensor attached to digital pin 4
Original code for Ping))) example was created by David A. Mellis
Adapted for HC-SR04 by Tautvidas Sipavicius
This example code is in the public domain.
*/
const int trigPin = 12;
const int echoPin = 11;
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a HIGH pulse whose
// duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
I've read in the "NewPing" thread that there are a lot of bad HC-SR04 sensors on the market, that do exactly what you describe.
See this post and Tim's follow-up reply:- NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7
You might need to try buying another sensor, from a different seller. (And cross your fingers - there are a lot of those bad modules about.)
Perhaps change to a SRF05 or SRF06 as Tim suggests.
kumantech:
Hope you make it well.
Info here might be useful for you: http://kumantech.com/help/documents-and-recources_h0037.html
And? Any info about OP's problem?
Clicking a link results in
An error occurred while loading MEGA.
Filename: https://mega.nz/secureboot.js?r=1471390601
Exception: :
Please try again later. We apologize for the inconvenience.
If the problem persist, please try disabling all third-party browser extensions and reload your browser. If that doesn't help, contact support@mega.nz
BrowserID: mozilla/5.0 (windows nt 6.2; wow64; rv:48.0) gecko/20100101 firefox/48.0
Maybe because I don't allow javascript by default.
Thanks!
I'll buy another sensor somewhere else
and check if the problem is gone.
In the meantime, any tips or useful info
on how I can combine those two codes (control dc motor speed with a sensor)?
sterretje:
kumantech:
Hope you make it well.
Info here might be useful for you: http://kumantech.com/help/documents-and-recources_h0037.html
And? Any info about OP's problem?
...
I think it's spam. kumantech has two posts, both promoting their business.
ChrisTenone:
And? Any info about OP's problem?
...
I think it's spam. kumantech has two posts, both promoting their business.
Yeah, I reported it earlier as spam, but it might stay now that there are a number of comments on it, so that they remain relevant.
OldSteve:
Yeah, I reported it earlier as spam, but it might stay now that there are a number of comments on it, so that they remain relevant.
Meanwhile I see the advertising posts have been multiplying. 4 last time I looked, with the main purpose of the post being a link the the website.
Now granted, this is very targeted advertising. They have researched this site and have goods that are in demand here available. It seems though that arduino.cc is being denied revenue by allowing this poster to continue. You have reported it, so the ball is now in the forum owner's hands.
ChrisTenone:
Meanwhile I see the advertising posts have been multiplying. 4 last time I looked, with the main purpose of the post being a link the the website.
Now granted, this is very targeted advertising. They have researched this site and have goods that are in demand here available. It seems though that arduino.cc is being denied revenue by allowing this poster to continue. You have reported it, so the ball is now in the forum owner's hands.
Yep. I just had a look at the other posts. One is definitely in the right place, "Products and Services", and I can see the usefulness of the post in "Starter Kit", but the ones in this thread and the RFID thread are blatant spam, unrelated to the subject at hand.
There is absolutely nothing in the post in this thread that could possibly help fruitbooter with his problem.
fruitbooter:
In the meantime, any tips or useful info
on how I can combine those two codes (control dc motor speed with a sensor)?
What two sketches? You only posted one, for ultrasonic ranging.
And exactly how do you want an ultrasonic sensor to control motor speed? Do you mean that you want the motor to go slower as the range reduces, and faster as it increases, or vice versa.
You need to work out what exact PWM values you want for varying ranges. ie Do you want the motor to stop at 15cm, hit full speed at 60cm, or what?
You really need to get a working 'ping' sensor, then have a go at writing the code and post questions if you run into trouble.