« first day (1 day earlier)    last day (15 days later) » 

7:35 PM
@Anno I didn't modify the code. My teacher did (I think he had no idea what he was doing). So anyways, I asked around, and people told me to use the newping library. So I followed the instructions and I came up with the following, but it won't work. What did I do wrong?

#include <NewPing.h>
#define SensorN 2
#define max_dis 5
#define PING_INTERVAL 33
const int motor=9;
volatile int average_dis=0;

unsigned long pingTimer[SensorN];
unsigned int cm[SensorN];
uint8_t currentSensor = 0;

NewPing sonar[SensorN] = {
@Anno What was malfunctioning in your code? The motor didn't start no matter what object I put in front of the sensors.
I also played with the distance, but couldn't get the motor to start
@AnnonomusPerson so yeah, I followed the instructions of my teacher, and he came up with the above written "theory"
 
 
1 hour later…
8:59 PM
@MasterIvinChickenSheep First of all, you need to find your maximum distance that you want to sense. Also, most sensors like this have a limit on the length.
That code is pretty complex for a simple task... hmm... I rewrote mine with the new library....
That one is the adapted version of the one built for many sensors, in this case it's easier to code both manually:
 
I understand
 
#define maxdistance 20;   //TODO: replace this with the maximun CM your sensor can read; look at the specs
#define minspeed 120;      //TODO: replace this with the minimum speed of your motor
#define tolerance 8;     //TODO: replace this with the toleramce divided by 2; higher == small movements will be ignored
#include <NewPing.h>
int motorPin = 9, trigPin1 = 13, echoPin1 = 12, trigPin2 = 5, echoPin2 = 4, postdist1 = 112 postdist2 = 112;
NewPing sen1(trigPin1, echoPin1, maxdistance), sen2(trigPin2, echoPin2, maxdistance);
You'll have to change the top three values I put there......
 
I will test it
 
Okay
Wait one second....
 
okay
time's up
 
9:02 PM
Okay now :P
 
@MasterIvinChickenSheep lol
Edited code
> You are free to move around the cabin test my code
Tell me when you test it
 
I get the following:
ultrasonic:6: error: expected `)' before ';' token
ultrasonic:6: error: expected unqualified-id before ')' token
ultrasonic:6: error: expected unqualified-id before ')' token
ultrasonic.ino: In function 'void loop()':
ultrasonic:13: error: 'sen2' was not declared in this scope
ultrasonic:21: error: 'distance' was not declared in this scope
ultrasonic:27: error: expected `)' before ';' token
ultrasonic:27: error: expected primary-expression before ',' token
ultrasonic:27: error: expected `;' before ')' token
@AnnonomusPerson thanks by the way :)
 
Hmm let me take a look
@MasterIvinChickenSheep It looks like you didn't copy all the code..............
 
oh? lol let me try again
@AnnonomusPerson yes I did
 
9:10 PM
I don't know for sure. Make sure to click the expand button to see all of the code.
@MasterIvinChickenSheep Did you download the library you mentioned?
 
@AnnonomusPerson yes I did, and I got it installed as well
 
@MasterIvinChickenSheep I'm getting the same errors without the library....
 
well I got the library installed
and just to be sure, I went to Sketch > Import Library > New Ping
and I got the following on top of the code: #include <NewPing.h>
I think you forgot to add # in front of include <NewPing.h>
 
@MasterIvinChickenSheep Oops!
Yeah I did
 
I also added a comma in between bothpostdist
both postdist*
 
9:19 PM
Oh, do I have any other mistakes?
 
so I chaned the top of my code a bit, and this is how it currently looks like:
#include <NewPing.h>
#define maxdistance 10 //TODO: replace this with the maximun CM your sensor can read; look at the specs
#define minspeed 120 //TODO: replace this with the minimum speed of your motor
#define tolerance 8 //TODO: replace this with the toleramce divided by 2; higher == small movements will be ignored
please note that I took out the ;
 
Should be distance1 in first if statement
and distance1 = postdist1;
Yeah... haven't written a full sketch in ages
 
haha its okay
 
#define maxdistance 20 //TODO: replace this with the maximun CM your sensor can read; look at the specs
#define minspeed 60 //TODO: replace this with the minimum speed of your motor
#define tolerance 8 //TODO: replace this with the toleramce divided by 2; higher == small movements will be ignored
#include <NewPing.h>
int motorPin = 9, trigPin1 = 13, echoPin1 = 12, trigPin2 = 5, echoPin2 = 4, postdist1 = 112, postdist2 = 112;
NewPing sen1(trigPin1, echoPin1, maxdistance), sen2(trigPin2, echoPin2, maxdistance);
Finished code ^^^
 
so right now, this is what I got: #include <NewPing.h>
#define maxdistance 10 //TODO: replace this with the maximun CM your sensor can read; look at the specs
#define minspeed 120 //TODO: replace this with the minimum speed of your motor
#define tolerance 8 //TODO: replace this with the toleramce divided by 2; higher == small movements will be ignored

int motorPin = 9, trigPin1 = 13, echoPin1 = 12, trigPin2 = 5, echoPin2 = 4, postdist1 = 112, postdist2 = 112;
NewPing sen1(trigPin1, echoPin1, maxdistance), sen2(trigPin2, echoPin2, maxdistance);
 
9:21 PM
I made some other fixes, see if it compiles
 
lol you're fast..
yes it did!
Im going to test it now
 
@MasterIvinChickenSheep Yay!!! :P
 
the motor just keeps on spanning
spinning
 
@MasterIvinChickenSheep Even with adjustments?
 
i placed an object in front of both sensrs, but the speed didnt change
 
9:24 PM
To the objects
 
even with adjustments
 
are they the same distance away from the sensors?
 
[status-by-design]
Because you said one would increase and the other would decrease: they cancel each other out.....
I must have not understood what exactly you want to do @Mas
 
yes I did say that, I want one sensor to increase the speed, and the other one to decrease the speed. Do you want to see my setup?
 
9:30 PM
No I have a picture in my mind. I'm saying that if you have one increasing 5 units and the other decreasing 5 units, they'll cancel out.
 
ohh okay, i understand that
 
So you will have to move them differently, or change the code.
Does that make sense @MasterIvinChickenSheep now?
@MasterIvinChickenSheep I was confused at first, too :)
 
what do you mean by move them differently
 
Like have one 10 cm away and the other 5 cm
 
I understand lol. well I basically failed this module oh well
I can resit it next year, and I'll come up with a better concept lol
thank you for your time and patience :D
 
9:38 PM
Yep :D
If you want any more help, let me know. Otherwise, I'll edit my answer to your question.
 
it's fine right now
just have to wait another year :D
 
So were you trying to do some sort of robot?
 
no basically we had to come up with a concept for a product that doesn't exist yet. sensors had to be involved and we had to design the prototype with the Arduino. I'm a fitness coach and whenever I'm in the gym, I see people having a difficult when they have to change the speed of the treadmill whenever they're sprinting.
They could lose their balance and the buttons are sooo small. So my idea was to include two sensors in the treadmill that could be used to easily change the speed of the treadmill
a difficult time*
Sirry, it's almost 12PM here
sorry*
 
Ahh great idea!
I have an idea to solve this if you stick around
Yes:
 
9:45 PM
use only one sensor and then map() the distance between 0-20 cm (or whatever) and regulate the speed with
 
I'll stick along. I'll ask my teacher if he can extend the deadline lol
 
Or you could hmm let me work out the code I got it maybe....
 
okay, yes please
Ill send him an email just to make sure
 
Give me ten minutes to figure this out if you have time
 
9:52 PM
Almost done with it
Making it smoother
 
One more change
#define maxdistance 20 //TODO: replace this with the maximun CM your sensor can read; look at the specs
#define minspeed 60 //TODO: replace this with the minimum speed of your motor
#define maxswipe 50 //TODO: replace this with the maximum speed change per swipe out of 256
#include <NewPing.h>
int motorPin = 9, trigPin1 = 13, echoPin1 = 12, trigPin2 = 5, echoPin2 = 4, postspeed = 0;
NewPing sen1(trigPin1, echoPin1, maxdistance), sen2(trigPin2, echoPin2, maxdistance);

void setup() {}
@MasterIvinChickenSheep Try that
Use only one fist at a time.... first one is speed up, second one is slow down
Does that do what you want?
I'm coding safety measures now....
 
ultrasonic_control2.ino: In function 'void loop()':
ultrasonic_control2:20: error: 'speed' was not declared in this scope
ultrasonic_control2:28: error: 'speed' was not declared in this scope
 
Change speed to _speed
 
I really admire people who can code
wished i had to brains to do this lol
okay I will
 
10:02 PM
@MasterIvinChickenSheep I've been doing this for a bit
If that works, this code will add some safety measures if both are activated at the same time
#define maxdistance 20 //TODO: replace this with the maximun CM your sensor can read; look at the specs
#define minspeed 60 //TODO: replace this with the minimum speed of your motor
#define maxswipe 50 //TODO: replace this with the maximum speed change per swipe out of 256
#include <NewPing.h>
int motorPin = 9, trigPin1 = 13, echoPin1 = 12, trigPin2 = 5, echoPin2 = 4, postspeed = 0;
NewPing sen1(trigPin1, echoPin1, maxdistance), sen2(trigPin2, echoPin2, maxdistance);

void setup() {}
@MasterIvinChickenSheep ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
well it kinda worked when I placed an object in front of both sensors but after a while they just stopped
after a while the motor just stopped spinning
 
@MasterIvinChickenSheep You use only one fist at a time
And you move it slowly forward/backward to adjust it.
 
12AM sleepy. so please excuse the typos
okay I wil ltry to do it like that
doesnt seem to do the trick. but thanks for your patience. I really appreciate everything you have done
but I'll just resit next year
 
Okay I'm sorry that I couldn't have helped more. It's hard to code for something you can't see
 
I understand
but hey, you helped me alot
so that's a good thing
I even tried to get some help on fiverr, but no luck lol
its 12 am here, so I'm going to hit the sheets
good night ^^
 
10:14 PM
Night!
 

« first day (1 day earlier)    last day (15 days later) »