Overview description!
This page is dedicated to documenting the circuit connection and the code for the Baskphobia!
Baskphobia is an autonomous moving basketball hop that operates independently, changing its movements randomly at predefined intervals. Equipped with an IR sensor, it dynamically counts the balls entering the hop during its movements. The count is visibly updated in real-time on the LCD, providing an interactive and engaging experience.
TinkerCad: to simulate the circuit.
Visio: to draw the pseudocode.
Arduino IDE: to write the code.
Fritzing: to create the circuit diagram
We decided on the components we're going to use, which are:
Screwdriver
Power management:
Connect the positive terminal of the power source (the battery) to the breadboard to form a 9-volt rail with yellow wires.
Connect the negative terminal of the power source to the breadboard to form a GND rail with black wires.
Connect the 5V of the Arduino to the breadboard to form a 5V rail with a red wire.
Connect the GND of the Arduino to the breadboard and make a common ground with a black wire.
Power the Arduino through the Vin with the 9 volts with a yellow wire.
Building the circuit
IR connection on TinkerCAD:
Since there is no IR sensor on TinkerCAD, we used a PIR sensor instead. It has the same pinout.
PIR sensor pinout:
GND is a ground pin.
VCC (power) is the power supply pin.
Signal is the 3.3V TTL logic output. It goes HIGH when motion is detected and goes LOW when idle (no motion detected).
Connections between Arduino and PIR sensor:
VCC pin to the 5V rail on the breadboard.
GND pin to the common ground on the breadboard.
Signal pin to the Arduino pin 10.
LCD (Liquid Crystal Display) connection on TinkerCAD:
We used an LCD with an I2C module, so we only will use its four pins to connect the LCD with Arduino.
The connection will be the same as the real LCD.
I2C Serial Interface Adapter (I2C Module) Pinout:
GND is a ground pin.
VCC is the power supply pin.
SDA is the I2C data pin.
SCL is the I2C clock pin.
Connections between Arduino and I2C Module:
VCC pin to the 5V rail on the breadboard.
GND pin to the common ground on the breadboard.
SDA pin to the Arduino Analog pin A4.
SCL pin to the Arduino Analog pin A5.
L298N Motor Driver Module connection on TinkerCAD:
There is no L298N Motor Driver Module on TinkerCAD. But we can simulate it using the L293D Motor Driver IC.
L293D Motor Driver IC pinout
Enable (1&2) and Enable (3&4) are the ENA and ENB pins respectively. we can control the speed of the DC motor.
Inputs (1 and 2) control the spinning direction of motor A.
Inputs (3 and 4) control the spinning direction of motor B.
Outputs (1 and 2) is for the motor A.
Outputs (3 and 4) is for the motor B.
GND are the ground pins.
VCC1 connect the internal logic circuit of the IC; you need to connect 5V to this pin.
VCC2 provides power to the internal motor driver of the IC, and can be connected to 4.5V to 36V of supply.
Connections between Arduino and L293D Motor Driver IC:
VCC1 pin to the 5V rail on the breadboard.
VCC2 pin to the 9V rail on the breadboard.
Two GND pins to the common ground on the breadboard.
To control motor A
Enable (1&2) to the Arduino Analog pin 9.
Input 1 to the Arduino pin 8.
Input 2 to the Arduino pin 7.
Outputs (1 and 2) to the two terminals of motor A.
To control motor B
Enable (3&4) to the Arduino Analog pin 5.
Input 3 to the Arduino pin 4.
Input 4 to the Arduino pin 3.
Outputs (3 and 4) to the wo terminals of motor B.
The final circuit
To implement the circuit with the real components. There are some differences. So, we use fritzing to make the circuit diagram.
Also we brought all of our components and make it ready to use.
Power management:
In order to connect battery, we will need to use DC jack.
The DC jack has two terminals positive and negative.
Connect the positive terminal with a yellow wire and the negative terminal with a black wire.
Connect the positive terminal of the DC Jack ( the yellow wire) to the breadboard to form a 9-volt rail.
Connect the negative terminal of the DC Jack (the black wire) to the breadboard to form a GND rail.
Connect the 5V of the Arduino to the breadboard to form a 5V rail with a red wire.
Connect the GND of the Arduino to the breadboard and make a common ground with a black wire.
Power the Arduino through the Vin at 9 volts with a yellow wire.
Building the circuit
IR connection:
IR sensor pinout:
GND is a ground pin.
VCC (power) is the power supply pin.
OUT is the 3.3V TTL logic output. It goes LOW when motion is detected and goes HIGH when idle (no motion detected).
Connections between Arduino and IR sensor:
VCC pin to the 5V rail on the breadboard.
GND pin to the common ground on the breadboard.
Out pin to the Arduino pin 10.
LCD (Liquid Crystal Display) connection:
The connection is the same as TinkerCAD
I2C Serial Interface Adapter (I2C Module) Pinout:
GND is a ground pin.
VCC is the power supply pin.
SDA is the I2C data pin.
SCL is the I2C clock pin.
Connections between Arduino and the I2C Module:
VCC pin to the 5V rail on the breadboard.
GND pin to the common ground on the breadboard.
SDA pin to the Arduino Analog pin A4.
SCL pin to the Arduino Analog pin A5.
L298N Motor Driver Module connection:
L298N Motor Driver Module pinout:
Power Pins
VS pin powers the IC’s internal H-Bridge, which drives the motors.
This pin accepts input voltages ranging from 5 to 12V.
GND is the common ground pin.
Output Pins:
OUT1 and OUT2 for motor A
OUT3 and OUT4 for motor B,
3. Direction Control Pins:
IN1 and IN2 pins control the spinning direction of motor A
IN3 and IN4 control the spinning direction of motor B.
4. Speed Control Pins:
ENA and ENB are used to turn on/off the motors and control their speed.
check this site for more info.
L298N Motor Driver Module connection with Arduino:
Power Pins
VS pin to the 9V rail on the breadboard.
GND to the common ground on the breadboard.
Output Pins:
OUT1 and OUT2 to motor A
OUT3 and OUT4 to motor B,
Direction Control Pins:
IN1 pin to the Arduino digital pin 8.
IN2 pin to the Arduino digital pin 7
IN3 pin to the Arduino digital pin 5.
IN4 pin to the Arduino digital pin 4.
Speed Control Pins:
ENA to the Arduino analogue (PWM) pin 9.
ENB to the Arduino analogue (PWM) pin 3.
The final circuit connection
The pseudocode
we started to write the pseudocode, as shown on the left.
Follow this link for more clearer fpicture.
The code on TinkerCAD and the simulation
The code is described in detail below, there are a few differences between the real code and the TinkerCAD code.
The lines to initialize and communicate with LCD Display are different.
Since we used PIR sensor instead of IR sensor, the logic will be reversed.
Also, the connection of the motor driver pins has changed a little bit.
The code with the real components
Description: Arduino code for an IR sensor-based interactive counter displayed on an I2C LCD.
Functionality:
The code periodically checks the state of the IR sensor at defined intervals.
When the IR sensor detects an object (output is LOW), the counter increments.
The count is displayed on the LCD, and it resets to zero when reaching 10.
The code uses millis() for timing to avoid blocking delays.
initializing the LCD display for use in the Arduino sketch.
Timing variables manage the interval for reading the IR sensor.
variable to define the pin for the IR sensor.
The setup initializes IR pin and the communication with the LCD and turn on that backlight.
The loop periodically reads the IR sensor at defined intervals.
ReadIRSensorFunction reads the IR sensor and update the count on the LCD.
Description: Description: Arduino code for controlling a two-wheeled robot with random movements using an H-bridge motor driver.
Functionality:
The code periodically changes the movement direction of the robot at defined intervals.
The timing for changing movements is managed by the 'movementChangeInterval' variable.
The 'randomMovement' function selects a movement direction randomly (forward, backward, right, left).
Motor control functions ('moveForward', 'moveBackward', 'moveRight', 'moveLeft') define specific motor actions.
The 'stopMotors' function is called when no specific movement is selected to halt the robot.
The code uses millis() for timing to avoid blocking delays.
Motor control variables define the pins for the motor driver (enA, in1, in2, enB, in3, in4)
Timing variables manage the interval for changing movement directions randomly.
The setup initializes motor control pins and turns off the motors.
The loop periodically changes the movement direction at defined intervals.
The 'randomMovement' function selects a random number between 1 and 4.
Different movements are assigned to each number: 1 for forward, 2 for backward, 3 for right, and 4 for left.
The selected movement is then executed using the corresponding motor control functions.
Motor control functions moveForward, moveBackward, moveRight, and moveLeft define the specific motor actions. The stopMotors function stops all motors.
Combine the two codes together.