This week our labs were wonderfully relevant to Sana and my midterm. Using an h-bridge, or in this case the sparkfun motor drive made firing a motor dead easy. The lab using a transistor with the potentiometer to control the motor did not work despite a good amount of trouble shooting. We are wondering if it had to do with our choice of transistor becuase the one used in the lab was not stocked on the floor. Unfortunately I did not think to record which transistor we used. I will post some photos below.

Here is the motor driver lab:
Sana and I have made some really solid progress on our midterm. Initially we tried the proximity sensor available in the ER. I had chatGPT write code for it because I am not familiar with i2c communication yet and I wanted to test sensors this week. We were able to get a proximity readout but we were not able to get it to work with helping differentiating a black line on white paper. We also ordered the Grove Line Finding sensor which outputs “black” when the sensor is reading low, and “white” when it is reading high. The sensor is a reflective IR sensor. I like this sensor a lot because it outputs an analog signal, rather than i2c communication. From there we genreated some code with ChatGPT so we could quickly test its output. After that we were able to integrate it with a motor and motor driver, and now we have the beginning of our line following robot project.
#define LINE_FINDER_PIN A0 // Grove Line Finder is connected to analog pin A0
#define AIN1 7 // AIN1 pin of TB6612FNG motor controller (Digital Pin 7 on Arduino Nano 33 IoT)
#define AIN2 8 // AIN2 pin of TB6612FNG motor controller (Digital Pin 8 on Arduino Nano 33 IoT)
#define PWMA 9 // PWMA control pin for motor A (Digital Pin 9 on Arduino Nano 33 IoT)
#define BIN1 10 // BIN1 pin of TB6612FNG motor controller (Digital Pin 10 on Arduino Nano 33 IoT)
#define BIN2 11 // BIN2 pin of TB6612FNG motor controller (Digital Pin 11 on Arduino Nano 33 IoT)
#define PWMB 12 // PWMB control pin for motor B (Digital Pin 12 on Arduino Nano 33 IoT)
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(LINE_FINDER_PIN, INPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
}
void loop() {
int lineValue = digitalRead(LINE_FINDER_PIN); // Read the digital value from the line finder
if (lineValue == HIGH) { // Black line detected
Serial.println("Black"); // Print 'Black' to the serial monitor
// Motor A control
digitalWrite(AIN1, HIGH); // Set motor A direction
digitalWrite(AIN2, LOW);
analogWrite(PWMA, 255); // Spin motor A at full speed
// Motor B control
digitalWrite(BIN1, HIGH); // Set motor B direction
digitalWrite(BIN2, LOW);
analogWrite(PWMB, 255); // Spin motor B at full speed
} else {
Serial.println("White"); // Print 'White' to the serial monitor (White line detected)
analogWrite(PWMA, 0); // Stop motor A
analogWrite(PWMB, 0); // Stop motor B
}
delay(10); // Short delay for stability
}
#include <Wire.h>
#include <Adafruit_VCNL4010.h>
// Create an instance of the sensor
Adafruit_VCNL4010 vcnl;
void setup() {
// Start the serial communication
Serial.begin(9600);
while (!Serial) {
; // Wait for the serial port to be available
}
// Initialize I2C communication
Wire.begin();
// Initialize the VCNL4010 sensor
if (!vcnl.begin()) {
Serial.println("Couldn't find VCNL4010 sensor, check wiring!");
while (1);
}
Serial.println("VCNL4010 sensor found!");
// Set LED current to adjust sensitivity (0 to 20)
vcnl.setLEDCurrent(20); // Default is 20, reduce for lower sensitivity
// Set proximity integration time to adjust sensitivity
vcnl.setProximityIntegrationTime(VCNL4010_64MS); // Options: VCNL4010_1T to VCNL4010_128MS
// Wiring Diagram Details:
// VCNL4010 Pin Details:
// 1. VIN -> Arduino Nano 33 IoT 5V or 3.3V
// 2. 3VO -> Not used (3.3V output from regulator)
// 3. GND -> Arduino Nano 33 IoT GND
// 4. SCL -> Arduino Nano 33 IoT SCL (A5)
// 5. SDA -> Arduino Nano 33 IoT SDA (A4)
// 6. INT -> Interrupt pin (optional, can be left unconnected if not used)
}
void loop() {
// Read proximity value
uint16_t proximity = vcnl.readProximity();
// Print the proximity value to the Serial Monitor
Serial.print("Proximity: ");
Serial.println(proximity);
// Read ambient light value
uint16_t ambientLight = vcnl.readAmbient();
// Print the ambient light value to the Serial Monitor
Serial.print("Ambient Light: ");
Serial.println(ambientLight);
// Optional: Add a delay for readability
delay(500);
}
#include <Wire.h>
#include <SparkFun_APDS9960.h>
// Create an instance of the sensor
SparkFun_APDS9960 apds;
void setup() {
// Start the serial communication
Serial.begin(9600);
while (!Serial) {
; // Wait for the serial port to be available
}
// Initialize I2C communication
Wire.begin();
// Initialize the APDS-9960 sensor
if (!apds.init()) {
Serial.println("APDS-9960 initialization failed. Please check your wiring.");
while (1);
}
Serial.println("APDS-9960 sensor initialized!");
// Enable different sensors
if (!apds.enableProximitySensor()) {
Serial.println("Proximity sensor setup failed.");
while (1);
}
Serial.println("Proximity sensor enabled!");
if (!apds.enableLightSensor()) {
Serial.println("Light sensor setup failed.");
while (1);
}
Serial.println("Ambient light sensor enabled!");
}
void loop() {
// Read proximity value
uint8_t proximity = 0;
if (apds.readProximity(proximity)) {
Serial.print("Proximity: ");
Serial.println(proximity);
}
// Read ambient light value
uint16_t ambientLight = 0;
uint16_t red, green, blue;
if (apds.readAmbientLight(ambientLight)) {
Serial.print("Ambient Light: ");
Serial.println(ambientLight);
}
// Read RGB color values
if (apds.readRedLight(red) && apds.readGreenLight(green) && apds.readBlueLight(blue)) {
Serial.print("Red: ");
Serial.print(red);
Serial.print(" Green: ");
Serial.print(green);
Serial.print(" Blue: ");
Serial.println(blue);
}
// Optional: Add a delay for readability
delay(500);
}
#define LINE_FINDER_PIN A0 // Grove Line Finder is connected to analog pin A0
#define AIN1 7 // AIN1 pin of TB6612FNG motor controller (Digital Pin 7 on Arduino Nano 33 IoT) // AIN1 pin of TB6612FNG motor controller (Digital Pin 7 on Arduino Nano 33 IoT) // AIN1 pin of TB6612FNG motor controller
#define AIN2 8 // AIN2 pin of TB6612FNG motor controller (Digital Pin 8 on Arduino Nano 33 IoT) // AIN2 pin of TB6612FNG motor controller (Digital Pin 8 on Arduino Nano 33 IoT) // AIN2 pin of TB6612FNG motor controller // IN2 pin of TB6612FNG motor controller // AIN2 pin of TB6612FNG motor controller
#define PWMA 9 // PWMA control pin for motor A (Digital Pin 9 on Arduino Nano 33 IoT) // PWMA control pin for motor A (Digital Pin 9 on Arduino Nano 33 IoT) // PWM control for motor A
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(LINE_FINDER_PIN, INPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMA, OUTPUT);
}
void loop() {
int lineValue = digitalRead(LINE_FINDER_PIN); // Read the digital value from the line finder
if (lineValue == HIGH) { // Black line detected
Serial.println("Black"); // Print 'Black' to the serial monitor
digitalWrite(AIN1, HIGH); // Set motor direction
digitalWrite(AIN2, LOW);
analogWrite(PWMA, 255); // Spin the motor at full speed
} else {
Serial.println("White"); // Print 'White' to the serial monitor (White line detected)
analogWrite(PWMA, 0); // Stop the motor
}
delay(10); // Short delay for stability
}
/*
Wiring Guide for Arduino Nano 33 IoT:
Components:
- Arduino Nano 33 IoT
- Grove Line Finder Sensor
- TB6612FNG Motor Driver
- DC Motor
- Power Supply (e.g., battery pack for motor)
Wiring Connections:
Grove Line Finder Sensor:
- Signal Pin to A0 on Arduino Nano 33 IoT.
- VCC Pin to 3.3V on Arduino Nano 33 IoT.
- GND Pin to GND on Arduino Nano 33 IoT.
TB6612FNG Motor Controller:
- Motor A Pins:
- AIN1 to Digital Pin 7 on Arduino Nano 33 IoT.
- AIN2 to Digital Pin 8 on Arduino Nano 33 IoT.
- PWMA to Digital Pin 9 on Arduino Nano 33 IoT (for PWM control).
- Motor B Pins (not used in this setup, leave unconnected or connect to additional motor).
Motor Output Pins:
- AO1 and AO2 connected to DC Motor Terminals.
Power and Ground:
- VM to Motor Power Supply (e.g., 6-12V battery pack, depending on motor requirements).
- VCC to 3.3V on Arduino Nano 33 IoT.
- GND to GND on Arduino Nano 33 IoT and Motor Power Supply Ground.
STBY (Standby) Pin:
- Connect STBY to 3.3V or to an Arduino pin configured as HIGH to enable the motor driver.
Power Considerations:
- Make sure to connect the GND of the motor power supply to the GND of the Arduino for a common reference.
- The VM pin should be connected to a power source that matches the requirements of your motor.
*/