Robot car following sensor readings.

Hi!

I'm currently trying to make a robot car that detects gas and moves towards its source.
I have programmed a bunch of macros for movement (they just turn motors on and off, so for turning right it would turn the right motors on and left motors off) and installed an MQ2 sensor that takes the gas readings.

I have managed to make the car start and stop when it detects certain thresholds of the gas/smoke however, as I have mentioned before, I would like the car to save old readings and keep comparing them with new readings so, if it starts driving towards a direction where the gas density is smaller, it should turn some other way to head towards spaces with higher density. Ultimately I want it to be able to find the spot with the highest density and stop/start making noise.

I'm not really sure how feasible it really is; I have some ideas on how I could possible accomplish this (EEPROM?) but I have no concrete plan on how to do it.

I'm sorry if it doesn't make much sense - I'm still a bit clueless when it comes to Arduino :disappointed_relieved: .

BottomKekz:
Hi!

I'm currently trying to make a robot car that detects gas and moves towards its source.
I have programmed a bunch of macros for movement (they just turn motors on and off, so for turning right it would turn the right motors on and left motors off) and installed an MQ2 sensor that takes the gas readings.

I have managed to make the car start and stop when it detects certain thresholds of the gas/smoke however, as I have mentioned before, I would like the car to save old readings and keep comparing them with new readings so, if it starts driving towards a direction where the gas density is smaller, it should turn some other way to head towards spaces with higher density. Ultimately I want it to be able to find the spot with the highest density and stop/start making noise.

I'm not really sure how feasible it really is; I have some ideas on how I could possible accomplish this (EEPROM?) but I have no concrete plan on how to do it.

I'm sorry if it doesn't make much sense - I'm still a bit clueless when it comes to Arduino :disappointed_relieved: .

Welcome to the Arduino forum. I m sure you can find help here. But first, I bet you have creates "functions" no "macros". At least I hope that is what you created.

Have you created functions to make your car turn left and right? Without that the rest is pointless.

Paul

I wonder how effective your plan will be.
Air tends to move around. Especially when there is a vehicle driving around it in. I would expect that the very act of moving the vehicle will move enough air that your history of density readings will no longer be valid.

Also, how will you know where each reading was taken? What will you use to track the vehicle location and navigate to a new desired location?

Also, I can see this process working along one line, where the vehicle moves forward and back until it finds a local maximum and triggers your alarm. But what if the source is not on the initial line created by moving your vehicle forward and backwards? How would your vehicle know to turn and try different areas?

I am not trying to shoot down your ideas. It would be a fun experiment even if it were limited. And it will likely illustrate the larger complexity of real world navigation.

I really appreciate your input! I have posted here partially because I wasn't sure if making this kind of project is possible. I wouldn't be surprised if my plan was way too advanced for a beginner project :sweat_smile:

Paul_KD7HB:
Welcome to the Arduino forum. I m sure you can find help here. But first, I bet you have creates "functions" no "macros". At least I hope that is what you created.

Have you created functions to make your car turn left and right? Without that the rest is pointless.

Paul

int ENA = 5;
int IN1 = 7;
int IN2 = 8;
//--------------------------------
int ENB = 6;
int IN3 = 12;
int IN4 = 13;
//---------------------------------
#define FORWARD {digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH);}
#define BACKWARD {digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW);}
#define RIGHT {digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW);}
#define LEFT {digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH);}
#define STOP {digitalWrite(IN1,LOW); digitalWrite(IN2,LOW); digitalWrite(IN3,LOW); digitalWrite(IN4,LOW);}
//------------------------------------------
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
//-----------Light sensor setup-------------
  pinMode(LDR, INPUT);
  Serial.begin (9600);
//-----------Left Motor setup----------------
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  digitalWrite(ENA, HIGH);
//-----------Right Motor setup---------------
  pinMode(ENB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  digitalWrite(ENB, HIGH);

}

I'm sorry if I wasn't clear about my code. I've stumbled upon somebody calling the #define lines as macros and it kind of stuck with me. The code above is what I use for moving the car; to move the car I just use the defined commands inside the loop function.