| Sinal módulo | Arduino | RPi GPIO (BCM) | Tipo | Notas |
|---|---|---|---|---|
| SIG | D4 | GPIO17 | Digital IN | LOW = obstáculo a 2–30 cm |
| VCC | 5V | 3.3V | — | |
| GND | GND | GND | — |
LED verde = livre · vermelho = obstáculo.
#define OBS 4
#define LED_R 9
#define LED_G 10
void setup(){
pinMode(OBS,INPUT); pinMode(LED_R,OUTPUT); pinMode(LED_G,OUTPUT);
}
void loop(){
bool det=(digitalRead(OBS)==LOW);
digitalWrite(LED_R,det); digitalWrite(LED_G,!det);
Serial.println(det?"OBSTÁCULO":"Livre");
delay(100);
}import RPi.GPIO as GPIO, time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN); GPIO.setup(27,GPIO.OUT); GPIO.setup(22,GPIO.OUT)
try:
while True:
det=(GPIO.input(17)==GPIO.LOW)
GPIO.output(27,det); GPIO.output(22,not det)
print("OBSTÁCULO" if det else "Livre")
time.sleep(0.1)
finally: GPIO.cleanup()