Hi ! My trying to control the stepper motor with ISL29125 RGB light sensor. When the light sensor detect black color, the motor will rotate but when light sensor detect other color, the motor will stop.
The materials that I used are ISL29125 RGB light sensor, stepper motor, esp32, and l9110s h-bridge stepper motor dual dc driver controller board.
BUT I try this code but it didn't work. Moreover, when I run this it appear nothing on serial monitor. After that Arduino program is stop working and cannot do anything.
Code by itself tells us little. We need a schematic (not a Fritzing thing) to see how it is wired up.
Also what Arduino are you using and have you tried printing something in the setup function to see if that works on your monitor, which must be set to the same speed as your software.
Hi,
Look at the examples for the Sparkfun Library.
You are missing some lines in the void setup() function
Also this line in the description of the stepper.h library.
This library is compatible with all architectures so you should be able to use it on all the Arduino boards.
ESP32 is not Arduino board.
I found the code did not like this line.
myStepper.setSpeed(0);
But if I changed it to;
myStepper.setSpeed(1);
It stopped resetting, butr with no hardware connected I could not deduce if the code was actually reading the sensor, or controlling the stepper.
Did you read the three points in post#3 ?
Have you got code for each of the sensor and stepper onn their own to prove the ESP can read/write to them.
First, before I combine sensor and motor, I write the code and it work.
Code for sensor
#include <Wire.h>
#include "SparkFunISL29125.h"
SFE_ISL29125 RGB_sensor;
void setup()
{
Serial.begin(115200);
if (!RGB_sensor.init())
{
Serial.println("Error");
}
}
void loop()
{
//Read light intensity of blue channel
unsigned int blue = RGB_sensor.readBlue();
if((unsigned int) blue < 10000){
Serial.println("black");
delay(2000);
}
else
{
Serial.print(blue,DEC);
Serial.println();
}
delay(2000);
}
The result: when RGB light sensor detect light intensity below 10000, it will show black in serial monitor.
Code for stepper motor
#include <Stepper.h>
const int stepsPerRevolution = 18;
Stepper myStepper(stepsPerRevolution, 14, 12, 13, 15);
int stepCount = 0; // number of steps the motor has taken
void setup() {
myStepper.setSpeed(30);
Serial.begin(115200);
}
void loop() {
Serial.println("channel1");
myStepper.step(stepsPerRevolution);
delay(1500);
}
The motor wil rotate and stop for a sec that I set.
BUT. After I combine all of this, the motor start rotate but the RGB light sensor cannot detect anythings in serial monitor.
Seriously? It is very odd how you are getting output to the monitor that is not in your code. How is that happening?
Are you sure you only have 18 steps per revolution, this seems a very low number for a motor.
Finally your physical layout diagram (I actually asked for a schematic) shows no pull up resistors on the two I2C signal lines. You should fit at least a 3K3 resistors.
Hi ! My problem is almost solve. The motor can rotate when RGB light sensor detect the light intensity below 10000 and the motor will stop when the RGB light sensor detect light intensity above the 10000.
You seem to have missed the set speed call in your setup. You had it in in previous codes you posted.
myStepper.setSpeed(30);
The bigger the number the faster it will go. There is a limit to this however, if you try and go too fast then it will not move at all, so see what the biggest number you can use and still have it move.