Início›Módulos›Sensor de Obstáculos
⬤ Intermédio

🚧 Sensor de Obstáculos

⏱️ 20 min🧩 Sensor obstáculos · Digital

Nesta página

📌 Pinagem e Ligações

Sinal móduloArduinoRPi GPIO (BCM)TipoNotas
SIGD4GPIO17Digital INLOW = obstáculo a 2–30 cm
VCC5V3.3V—
GNDGNDGND—
ℹ️
Alcance ajustável por potenciómetro (2–30 cm). O sensor pode ter dificuldade com superfícies muito escuras (absorvem IR) ou muito brilhantes (luz ambiente interferente). Combina com o seguidor de linha para robótica autónoma completa.

Robô de Evitamento com LED

LED verde = livre · vermelho = obstáculo.

ex1_obs.ino
#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);
}
ex1_obs.py
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()

🏆 Para ir mais longe

PR.FT6_15 · Kit B 37 · Arduino · Raspberry Pi · Início · led.dge.medu.pt