Arduino Uno in Science Fair Project

My son is using the Arduino Uno software for his science fair project. He downloaded the Arduino software. The sensors do not move. He has doublechecked to make sure that the senor and pins were installed correctly. Can someone provide us with some guidance please? Thank you.

Here 'ya go:

We cannot see your project from here and my crystal ball is out for alignment.

We need to see the code.

We need to see a wiring diagram.

Clear photos of the wiring is helpful.

We need to see technical data for the sensors and/or actuators.

Talking with technical people, you often need to be anal about context and accuracy.

Many are willing to help without any obligation from you, few are going to give anything away… they want you to learn so you can help others in the future.

Example… ‘sensors’ don’t typically move under their own motive.
Those might be actuators or motors… we don’t know what you have, or how they’re connected together.

What type of sensors are you talking about?

For people to help.... they usually need:

  • code you are trying to run
  • a view of how everything is connected (a diagram, or clear photo)
  • details of the components (model number of the sensor for example)
                                             /*
  • Starter code for making an autonomous Arduino car with the Science Buddies Bluebot kit
  • For circuit diagram and instructions see: Build a Miniature Self-Driving Car | Science Project
  • Important: this code assumes you use the Arduino pins from the circuit diagram on the Science Buddies website.
  • If you wire your circuit differently, you will need to adjust your code accordingly.
  • This code is intended to help you get started building a self-driving car with the Science Buddies Bluebot kit.
  • It assumes you are using the Bluebot chassis along with the two included infrared (IR) sensors, as well as
  • an Arduino UNO and a PING ultrasonic distance sensor (purchased separately).
  • The code will read the sensors and is set up to control the speed and direction of the robot's two motors
  • using an H-bridge integrated circuit (the L293D, included in your Bluebot kit). However, you must write
  • an algorithm that determines what the robot will do based on the sensor readings.
    */

// define pins for H bridge
// to make a motor spin forward, set the forward pin high and the backward pin low
// to make a motor spin backward, set the backward pin high and the forward pin low
// to stop a motor, set both pins low OR set both pins high, OR set the speed to zero (regardless of direction)
// to control motor speed, use the analogWrite() function for a speed control pin
const int Lmotor_forward_pin = 5; // left motor forward pin is Arduino pin 5
const int Lmotor_backward_pin = 4; // left motor backward pin is Arduino pin 4
const int Rmotor_forward_pin = 3; // right motor forward pin is Arduino pin 3
const int Rmotor_backward_pin = 2; // right motor backward pin is Arduino pin 2
const int Lmotor_speed_pin = 9; // left motor speed control pin is Arduino pin 9
const int Rmotor_speed_pin = 10; // right motor speed control pin is Arduino pin 10

// define pin for the ultrasonic sensor
const int pingPin = 7;

// define pins for LEDs
const int leftLEDpin = 6;
const int rightLEDpin = 8;

// define constants for comparing sensor readings
// you will need to calibrate these values for your setup - the sensors can be affected by ambient light
// the Arduino's analog input will read a value between 0-1023. Higher values mean less IR light is reflected (dark surface)
const int leftIRthreshold = 200; // threshold for left IR sensor to detect line
const int rightIRthreshold = 200; // threshold for right IR sensor to detect line
const int brakingDistance = 8; // desired automatic stopping distance in centimeters

// define other non-constant variables used in program
// all speeds must be valus between 0 (stopped) to 255 (full speed)
// tweak the speed values to change how fast your robot drives and turns straight (decrease them if it is overshooting turns)
int speedL = 0; // left motor speed
int speedR = 0; // right motor speed
int turnspeed1 = 140; // speed of outer wheel when turning
int turnspeed2 = 25; // speed of inner wheel when turning
int straightspeed = 130; // speed of both motors when driving straight
int leftIR = 0; // left IR sensor reading
int rightIR = 0; // right IR sensor reading
long distance = 0; // distance measured by the ultrasonic sensor in centimeters

void setup() { // setup code that only runs once

// set pin modes
pinMode(Lmotor_forward_pin, OUTPUT);
pinMode(Lmotor_backward_pin, OUTPUT);
pinMode(Rmotor_forward_pin, OUTPUT);
pinMode(Rmotor_backward_pin, OUTPUT);
pinMode(Lmotor_speed_pin, OUTPUT);
pinMode(Rmotor_speed_pin, OUTPUT);
pinMode(leftLEDpin, OUTPUT);
pinMode(rightLEDpin, OUTPUT);

// set H bridge pins for robot to drive forward
digitalWrite(Lmotor_forward_pin, HIGH);
digitalWrite(Lmotor_backward_pin, LOW);
digitalWrite(Rmotor_forward_pin, HIGH);
digitalWrite(Rmotor_backward_pin, LOW);

// initialize serial communication for debugging
Serial.begin(9600);
}

void loop() { // code that loops forever

// get all three sensor readings
leftIR = analogRead(A0); // read left IR sensor
rightIR = analogRead(A1); // read right IR sensor
distance = readUltrasonic(pingPin); // read ultrasonic sensor and return distance in centimeters

/*

  • ********** YOUR ALGORITHM HERE! **********
  • Based on the sensor readings, write code to control the speed of the left and right motors (the speedL and speedR variables).
  • Your robot should drive straight when both motors spin the same speed. It will turn left when the right motor spins faster than
  • the left motor, and vice versa. It will stop when the speed of both motors is zero. For example, how can you make your robot:
  • Turn in the correct direction when only one sensor detects a line?
  • Stop if both sensors detect a line (e.g. a crosswalk)?
  • Stop if there is an obstacle too close to the front of the robot?
    */

// set motor speeds
analogWrite(Lmotor_speed_pin, speedL);
analogWrite(Rmotor_speed_pin, speedR);

// print variables for debugging purposes - useful for calibrating the IR sensors
Serial.print("Left IR sensor: ");
Serial.print(leftIR);
Serial.print(" Right IR sensor: ");
Serial.print(rightIR);
Serial.print(" Ultrasonic sensor (cm): ");
Serial.print(distance);
Serial.print(" Left motor ");
Serial.print(speedL);
Serial.print(" Right motor: ");
Serial.println(speedR);

}

long readUltrasonic(int pin){
// this code is based on the PING example code. File -> Examples --> 06.Sensors --> Ping
long duration;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): 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(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
//Serial.print(duration);

// 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 duration / 29 / 2;
}

IMG_4657

IMG_4656

Please see the post in reply #2 and reformat the comment with code so that it is readable.
Also, the "diagram" in that article is jumbled and very hard to follow. You may want to look for another source to find a better diagram.
Also, your provided images are way too small to be useful.

Does your manual maybe propose some stepwise approach?
Like install H bridge and motor. Upload h-bridge testing program. If working, go to next step?
Your may be difficult to tackle, as the problem may be in multiple places.
Is there any Serial.print in your sketch? So that you can follow where the program goes?
My first bet is on the wiring...
...but your picture is not good enough.
Edit: I see there is Serial.print there. So what does it show in the Serial monitor?

1 Like

What kind of power supply is used for the project.

Its no surprise the car does not move

int speedL = 0; // left motor speed
int speedR = 0; // right motor speed

However the "project guidance" is very poor, and for a starter project you should really use a stepwise approach, testing each stage before you progress.
From where you are now I'd suggest you start by trying this simpler code:

/*
 * Starter code for making an autonomous Arduino car with the Science Buddies Bluebot kit
 * For introductory video see https://youtu.be/qUo6hXSV1b8
 * For circuit diagram and instructions see: https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p042/robotics/arduino-self-driving-car
 * 
 * 
 * *Important*: this code assumes you use the Arduino pins from the circuit diagram on the Science Buddies website. 
 * If you wire your circuit differently, you will need to adjust your code accordingly. 
 * 
 * This code is intended to help you get started building a self-driving car with the Science Buddies Bluebot kit.
 * It assumes you are using the Bluebot chassis along with the two included infrared (IR) sensors, as well as 
 * an Arduino UNO and a PING ultrasonic distance sensor (purchased separately).
 * 
 * The code will read the sensors and is set up to control the speed and direction of the robot's two motors
 * using an H-bridge integrated circuit (the L293D, included in your Bluebot kit). However, *you* must write
 * an algorithm that determines what the robot will do based on the sensor readings. 

 * Adapted from original for testing purposes JLE Nov 2022
 */

// define pins for H bridge
// to make a motor spin forward, set the forward pin high and the backward pin low
// to make a motor spin backward, set the backward pin high and the forward pin low
// to stop a motor, set both pins low OR set both pins high, OR set the speed to zero (regardless of direction)
// to control motor speed, use the analogWrite() function for a speed control pin
const int Lmotor_forward_pin = 5;    // left motor forward pin is Arduino pin 5
const int Lmotor_backward_pin = 4;   // left motor backward pin is Arduino pin 4
const int Rmotor_forward_pin = 3;    // right motor forward pin is Arduino pin 3
const int Rmotor_backward_pin = 2;   // right motor backward pin is Arduino pin 2
const int Lmotor_speed_pin = 9;      // left motor speed control pin is Arduino pin 9
const int Rmotor_speed_pin = 10;     // right motor speed control pin is Arduino pin 10

// define pins for LEDs
const int leftLEDpin = 6;
const int rightLEDpin = 8;

// define other non-constant variables used in program
// all speeds must be valus between 0 (stopped) to 255 (full speed)
// tweak the speed values to change how fast your robot drives and turns straight (decrease them if it is overshooting turns)
int speedL = 64;            // left motor speed -CHANGED TO GIVE FORWARD MOTION
int speedR = 64;            // right motor speed -CHANGED TO GIVE FORWARD MOTION

int leftIR = 0;            // left IR sensor reading
int rightIR = 0;           // right IR sensor reading


void setup() { // setup code that only runs once

  // set pin modes
  pinMode(Lmotor_forward_pin, OUTPUT); 
  pinMode(Lmotor_backward_pin, OUTPUT); 
  pinMode(Rmotor_forward_pin, OUTPUT); 
  pinMode(Rmotor_backward_pin, OUTPUT); 
  pinMode(Lmotor_speed_pin, OUTPUT);
  pinMode(Rmotor_speed_pin, OUTPUT); 
  pinMode(leftLEDpin, OUTPUT);
  pinMode(rightLEDpin, OUTPUT);

  // set H bridge pins for robot to drive forward
  digitalWrite(Lmotor_forward_pin, HIGH);
  digitalWrite(Lmotor_backward_pin, LOW);
  digitalWrite(Rmotor_forward_pin, HIGH);
  digitalWrite(Rmotor_backward_pin, LOW);

  // initialize serial communication for debugging
  Serial.begin(9600);
}

void loop() { // code that loops forever

  // get all three sensor readings
  leftIR = analogRead(A0);            // read left IR sensor
  rightIR = analogRead(A1);           // read right IR sensor
  
  // set motor speeds  
  analogWrite(Lmotor_speed_pin, speedL);
  analogWrite(Rmotor_speed_pin, speedR);

  // print variables for debugging purposes - useful for calibrating the IR sensors
  Serial.print("Left IR sensor: ");
  Serial.print(leftIR);
  Serial.print("  Right IR sensor: ");
  Serial.print(rightIR);
  Serial.print("  Left motor ");
  Serial.print(speedL);
  Serial.print("  Right motor: ");
  Serial.println(speedR);
  
}


1 Like

Did he upload the code to the Arduino?

In the serial monitor, I can see the Ultrasonic sensor values changing but the right and
left sensors display but don’t change.

Monica A. Ponder, Esq.

Thank you. This helped a bit but the code for the robot is still essentially not showing the left and right Infrared sensor values changing as they are stuck at 1023.

Ok, so the code is running ok.
To check your wiring, a better picture is needed.
Also a schematic from your manual would be nice to have here in the app. Many helpers work from their phone. It really helps if all info is readily available.

" a bit" was the intention - its a stepwise approach, get one bit working then go on to the next.

As we dont have a circuit diagram or part number for the sensor we are working in the dark.
I'm guessing there will be an emitter and a detector - a bit like this

If you cover the receiver the reading may change; if not shine a light on it and see if that makes a difference?

1 Like

1 Like

Corrected Photos