Hello, im making a project for school were im making a trasnport board that has 2 motors that activate depending on an objects color, i have tried programming it and the TCS color sensor fully works but the dc motors i have arent working, none of the 3 move.
Heres the code, i would thank you a lot if somoene helped figure this out, im not very good with programming stuff.
void setup() {
#include <Wire.h>
#include "Adafruit_TCS34725.h"
#define MOTOR1_IN1 9
#define MOTOR1_IN2 10
#define MOTOR2_IN1 11
#define MOTOR2_IN2 12
#define MOTOR3_IN1 7
#define MOTOR3_IN2 8
Serial.begin(9600);
pinMode(MOTOR1_IN1, OUTPUT);
pinMode(MOTOR1_IN2, OUTPUT);
pinMode(MOTOR2_IN1, OUTPUT);
pinMode(MOTOR2_IN2, OUTPUT);
pinMode(MOTOR3_IN1, OUTPUT);
pinMode(MOTOR3_IN2, OUTPUT);
digitalWrite(MOTOR3_IN1, HIGH);
digitalWrite(MOTOR3_IN2, LOW);
if (tcs.begin()) {
Serial.println("Color sensor initialized.");
} else { Serial.println("Failed to initialize color sensor!");
while (1);
}
void loop()
float Red, Green, Blue;
tcs.getRGB(&Red, &Green, &Blue);
int R = int(Red);
int G = int(Green);
int B = int(Blue);
String color = "";
if ((R - G > 50) && (R - B > 50)) {
color = "Rojo";
digitalWrite(MOTOR1_IN1, HIGH);
digitalWrite(MOTOR1_IN2, LOW);
digitalWrite(MOTOR2_IN1, LOW);
digitalWrite(MOTOR2_IN2, LOW);
} else if ((G - B > 15) && (G - R > 30)) {
color = "Verde";
digitalWrite(MOTOR2_IN1, HIGH);
digitalWrite(MOTOR2_IN2, LOW);
digitalWrite(MOTOR1_IN1, LOW);
digitalWrite(MOTOR1_IN2, LOW);
} else {
digitalWrite(MOTOR1_IN1, LOW);
digitalWrite(MOTOR1_IN2, LOW);
digitalWrite(MOTOR2_IN1, LOW);
digitalWrite(MOTOR2_IN2, LOW);
}
Serial.print("R: "); Serial.print(R);
Serial.print(" G: "); Serial.print(G);
Serial.print(" B: "); Serial.print(B);
Serial.print(" Color: "); Serial.println(color);
delay(500);
Since your sketch doesn't even compile, no the DC motors won't move. Neither will anything else work.
First step: get the code to compile. Turn the warning level up to ALL. The compiler will give you lots of informative error and warning messages. Use them to fix your mistakes.
...or closed off the opening { in setup or used either { or } for loop, or put the #include directives in the proper place... it's like most of the right notes, but not in the right order. If it was a COBOL program I'd wonder if someone dropped the deck...
thanks :), the tcs34725 its detecting the color of item but i dont know why none of the 3 motors are reacting to it. its compiling but idk if it needs something else as someone else mentioned a tcs object lacking but the tcs is detecting color.
What model Arduino are you using and what motor driver?
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.