Hi,
First time using Arduino Uno
I'm making a stair climber for the school project ( it's just a 4-wheel car climbs the stairs) and having problems about programming and sensor wiring
There is a photo eye sensor that sense the stair front of the vehicle
when sensor activated, count 1 (counter become odd number) and motor move forward to the top floor.
Once it reaches top, there is a wall trigger the sensor. So count 1 again ( counter become even number) then motor move reverse direction.
I used 4 DC motor and it worked with other program. but couldn't check the reverse
H-bridge is L298n multiwatt [u]https://www.sparkfun.com/datasheets/Robotics/L298_H_Bridge.pdf[/u]
My sensor is Omron E3S-LS3RC4
[u]https://www.fa.omron.com.cn/data_pdf/closed/cat/e3s-ls3c1d_-ls3rc4_ds_e_3_1_csm1307.pdf?id=1166[/u]
I connect like
blue-0V
Brown, Pink - 12V
Black - Arduino pin 13
Motor is not even starting with the sensor...
Can you tell me if my program or other thing is wrong?
save me... Thank you
//set pin number
int Sensor = 13;
int pwm1 = 5;
int pwm2 = 6;
int pwm3 = 9;
int pwm4 = 10;
const int i1 = 0;
const int i2 = 1;
const int i3 = 2;
const int i4 = 3;
const int i5 = 7;
const int i6 = 8;
const int i7 = 11;
const int i8 = 12;
// Variables
boolean state = LOW;
int Val = 0;
int Counter = 0;
void setup() {
//Set pin I/O
pinMode(Sensor, INPUT_PULLUP);
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
pinMode(pwm3, OUTPUT);
pinMode(pwm4, OUTPUT);
pinMode(i1, OUTPUT);
pinMode(i2, OUTPUT);
pinMode(i3, OUTPUT);
pinMode(i4, OUTPUT);
pinMode(i5, OUTPUT);
pinMode(i6, OUTPUT);
pinMode(i7, OUTPUT);
pinMode(i8, OUTPUT);
Serial.begin(9600);
}
void loop() {
state = digitalRead(Sensor);
if (state = HIGH){
Counter++;
Serial.println(Counter);
}
//Descend if counter is odd
if ( (Counter % 2) == 0) {
analogWrite(pwm1, 255);
analogWrite(pwm2, 255);
analogWrite(pwm3, 255);
analogWrite(pwm4, 255);
digitalWrite(i1,HIGH);
digitalWrite(i3,HIGH);
digitalWrite(i5,HIGH);
digitalWrite(i7,HIGH);
digitalWrite(i2,LOW);
digitalWrite(i4,LOW);
digitalWrite(i6,LOW);
digitalWrite(i8,LOW);
delay(400);
}
else {
// Climb when sensor activates and even
analogWrite(pwm1, 255);
analogWrite(pwm2, 255);
analogWrite(pwm3, 255);
analogWrite(pwm4, 255);
digitalWrite(i2,HIGH);
digitalWrite(i4,HIGH);
digitalWrite(i6,HIGH);
digitalWrite(i8,HIGH);
digitalWrite(i1,LOW);
digitalWrite(i3,LOW);
digitalWrite(i5,LOW);
digitalWrite(i7,LOW);
delay(400);