linear actuator with sonar sensor safety stop
Budget: $10 – $30 USD
I am using a linear actuator and need sonar sensor safety detection to reverse the actuator when activated. Currently, the code is controlling the actuator perfectly, so I only need to add the code integrating the sonar sensor. I need a medium range (1-5 meters) for the sonar, and would like the distance to be approximately 10-20 cm. I have the necessary sensor and board that needs to be integrated. Additionally, I require the code to function as it is with the added sonar which will cause the actuator to reverse its movement when it is activated. Below is current code..
void setup() {
pinMode(2,INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
void loop() {
if(digitalRead(2) == HIGH & digitalRead(3) == LOW){
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
if(digitalRead(2) == LOW & digitalRead(3) == HIGH){
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
}
Using ultrasonic module and sensor, JSN-SR04T.
void setup() {
pinMode(2,INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
void loop() {
if(digitalRead(2) == HIGH & digitalRead(3) == LOW){
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
if(digitalRead(2) == LOW & digitalRead(3) == HIGH){
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
}
Using ultrasonic module and sensor, JSN-SR04T.