Hello all,
Project explanation
Using an Rboard (atmega328) I am trying to use a reflective sensor that turns on reverse motor relay and second reflective sensor would turn on forward relay.
project progress
I have sucessfully written a program that turned on the reverse relay when I ran my finger in front of tcrt1sensor. Then modified this program to add the second sensor and relay that does not work.
The reverse sensor still works as it did but the other relay will not come on. I have tested the sensor, if I swap the two sensors it will operate the rev. relay. So the mechanical aspect has been proofed. I have included code below Thanks for your help
const int tcrt1Pin = A4; // connected to the TCRT5000 C pin
const int forward = 4; // operates on board relay #4
const int tcrt2Pin = A5; // connected to the TCRT5000 C pin
const int Reverse = 5; // operates on board relay #3
// variables will change:
int tcrt1State = 0; // variable for reading the TCRT5000 status
int tcrt2State = 1;
void setup() {
// initialize the LED pin as an output:
pinMode(forward, OUTPUT);
pinMode(Reverse, OUTPUT);
// initialize the tcrt5000 pin as an input, and turn on the internal pullup resistors:
pinMode(tcrt1Pin, INPUT);
digitalWrite(tcrt1Pin, HIGH);
pinMode(tcrt2Pin, INPUT);
digitalWrite(tcrt2Pin, HIGH);
}
void loop(){
// read the state of the tcrt5000:
tcrt1State = digitalRead(tcrt1Pin);
// check if the tcrt5000 sensor detects something.
// if it is, the tcrtState is high:
if (tcrt1State == LOW) {
// turn motor off:
digitalWrite(forward, LOW);
}
else {
// turn forward relay on:
digitalWrite(forward, HIGH);
}
{
// read the state of the tcrt5000:
tcrt2State = digitalRead(tcrt2Pin);
// check if the tcrt5000 sensor detects something.
// if it is, the tcrtState is high:
if (tcrt2State == LOW) {
// turn motor off:
digitalWrite(Reverse, LOW);
}
else {
// turn forward relay on:
digitalWrite(Reverse, HIGH);
}
}
}