Adafruit Motor Hat not connecting to Ardiuno Uno

I am trying to connect my Adafruit MotorHat to my Ardiuno Uno, but it won't locate a i2c address and it wont run my motors. Here is my code:
`#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *motor2 = AFMS.getMotor(2);
Adafruit_DCMotor *motor3 = AFMS.getMotor(3);
Adafruit_DCMotor *motor4 = AFMS.getMotor(4);

int photocellPin = A0; // Mini photocell connected to analog pin A0
int threshold1 = 90; // Threshold value for trash
int threshold2 = 270; // Threshold value for opaque

const int led1 = 4; // LED pin for threshold 1
const int led2 = 3; // LED pin for threshold 2
const int led3 = 2; // LED pin for threshold 3
const int sensor_pin = A0; // Sensor pin
int sensor; // Sensor reading

void setup() {
Serial.begin(9600); // Initialize Serial communication
AFMS.begin(); // Create motor shield object

motor2->setSpeed(255); // Set initial speed for motors
motor3->setSpeed(255);
motor4->setSpeed(255);

pinMode(led1, OUTPUT); // Set LED pins as output
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}

void loop() {
int photocellValue = analogRead(photocellPin); // Read photocell value
Serial.print("Photocell Value: ");
Serial.println(photocellValue);

sensor = analogRead(sensor_pin); // Read sensor value
Serial.print("Sensor Value: ");
Serial.println(sensor);

// Control the linear actuators based on photocell value
if (photocellValue > threshold2) {
Serial.println("Object is Translucent - Extending First Actuator");
motor2->run(FORWARD); // Extend first actuator
motor3->run(BACKWARD); // Keep second actuator forward
motor4->run(BACKWARD); // Keep third actuator forward
} else if (photocellValue > threshold1) {
Serial.println("Object is Opaque - Extending Second Actuator");
motor2->run(BACKWARD); // Keep first actuator forward
motor3->run(FORWARD); // Retract second actuator
motor4->run(BACKWARD); // Keep third actuator forward
} else {
Serial.println("Object is Trash - Extending Third Actuator");
motor2->run(BACKWARD); // Keep first actuator forward
motor3->run(BACKWARD); // Keep second actuator forward
motor4->run(FORWARD); // Retract third actuator
}

// Control LEDs based on sensor values
if (sensor < threshold1) {
Serial.println("RED LED");
digitalWrite(led1, HIGH); // Turn on LED 1 if light levels drop too low
digitalWrite(led2, LOW); // Turn off LED 2
digitalWrite(led3, LOW); // Turn off LED 3
} else if (sensor >= threshold1 && sensor < threshold2) {
Serial.println("CLEAR LED");
digitalWrite(led1, LOW); // Turn off LED 1
digitalWrite(led2, HIGH); // Turn on LED 2
digitalWrite(led3, LOW); // Turn off LED 3
} else {
Serial.println("GREEN LED");
digitalWrite(led1, LOW); // Turn off LED 1
digitalWrite(led2, LOW); // Turn off LED 2
digitalWrite(led3, HIGH); // Turn on LED 3
}

delay(350); // Delay for stability
}`

Hi, @vdusty
Welcome to the forum.

Can you please post your code in code tags?
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Also a link to the motor hat?

Is it supposed to work on a UNO?
The Hat term is used with Rasp Pi peripherals.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.