I would like to modify attached code in a way to have 3 static Ultrasonic sensors (but i dont know how ), without servo motor which was used to rotate one sensor and ping surroundings in attached code. Can anybody help me to remove this and add 3 static sensors? End result should be maze solving robot with 3 ultrasonic sensors.
I'm using servo shield L239D and HC-SR04 and arduino uno.
#define TRIG_PIN A0 // Pin A0 on the Motor Drive Shield soldered to the ultrasonic sensor
#define ECHO_PIN A1 // Pin A1 on the Motor Drive Shield soldered to the ultrasonic sensor
#define TRIG_PIN A2 // Pin A2 on the Motor Drive Shield soldered to the ultrasonic sensor
#define ECHO_PIN A3 // Pin A3 on the Motor Drive Shield soldered to the ultrasonic sensor
#define TRIG_PIN A4 // Pin A4 on the Motor Drive Shield soldered to the ultrasonic sensor
#define ECHO_PIN A5 // Pin A5 on the Motor Drive Shield soldered to the ultrasonic sensor
The end result of this method is not three trigger pins and three echo pins. It is ONE of each, on pins A4 and A5.
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE); // sets up sensor library to use the correct pins to measure distance.
And, you have ONE sensor that you can use.
Servo myservo; // create servo object to control a servo
You don't have a servo. Why do you have an instance of the Servo class?
int readPing() { // read the ultrasonic sensor distance
delay(70);
The point of using NewPing is to eliminate blocking. Pretty stupid to then deliberately sit around with your thumb up your ass.
Hi markovs83,
First, how are you going to solve the maze? For instance, will you just follow, say, the right wall all the time? Will that work? Are you going to use the ultrasounds to make a map of the walls, and spaces that would be hallways, then go back and explore?
What method you use will determine the sensors and arrangement and ....
Big thanks for the reply's, i'm trying to learn programming, so big thanks for support.
Regarding code, my idea was to modify code to use 3 sensors and compare "cm" from sensors. E.g. If 1st and 2nd sensors are > than 3rd go to into 3rd direction ... and so on, compare all the values and choose the largest. Maybe this is dumb idea but in maze i expect to have always 2wals near and one gap ("doors")
Also i noticed that i have all Analog pins but not declared down ... in attach you can find modifications, also stupid and not good programming. but maybe some progress is visible.
Also this servo, hmm i need to figure how to remove it
I haven't looked at it yet but now you need a good flow chart. Step back, think of what you want done. How do you solve a maze?
Also, Look up what a "State Machine" is. It not a real machine but a way to code different conditions, like If... else if.. else if.. on Steroids. You robot goes from one state to another.
I'll look at it tomorrow and get back.