Python Tutorials – பாடம் 11 – Ultrasonic Sensor Module with OLED using Raspberry Pi Pico

Ultrasonic sensor distance ஐ OLED டிஸ்ப்ளேயில் பெறுதல்

Required Components

  1. OLED Display-1 no
  2. Raspberry Pi Pico board-1 no
  3. Ultrasonic Sensor-1 no
  4. USB Cable-1 no
  5. Connecting wires-1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Ultrasonic Sensor VCC மற்றும் Gnd சப்ளையை Raspberry Pi Pico VBus மற்றும் GND உடன் இணைக்க வேண்டும்.
  3. Ultrasonic sensorல் உள்ள ECHO மற்றும் TRIG பின்களை Raspberry Pi Pico வில் உள்ள GP2 மற்றும் GP3 பின்களுடன் இணைக்க வேண்டும்.
  4. OLED Display VCC, GND ஐ Raspberry Pi Pico Board 3V3 (OUT), GND உடன் இணைக்க வேண்டும்.
  5. Raspberry Pi Pico Board இன் GP16, GP17 ஐ OLED Display SCK, SDA உடன் இணைக்க வேண்டும்.
  6. Python program ஐ சரி பார்க்க வேண்டும்.
  7. மின்சுற்றை சரி பார்க்க வேண்டும்.
  8. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import utime
trigger = Pin(3, Pin.OUT)
echo = Pin(2, Pin.IN)
def ultrasonnic():
    timepassed=0
    trigger.low()
    utime.sleep_us(2)
    trigger.high()
    utime.sleep_us(5)
    trigger.low()
    while echo.value() == 0:
        signaloff = utime.ticks_us()
    while echo.value() == 1:
        signalon = utime.ticks_us()
    timepassed = signalon - signaloff
    return timepassed
WIDTH  = 128                                            # oled display width
HEIGHT = 64                                            # oled display height
i2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=200000)       # Init I2C using pins GP8 & GP9 (default I2C0 pins)
print("I2C Address      : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c))                   # Display I2C config
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)                  # Init oled display
 # Clear the oled display in case it has junk on it.
oled.fill(0)
# Add some text
oled.text("CIRCUIT DIGEST",5,8)
oled.text("INTERFACING THE",5,30)
oled.text("ULTRASONNIC",28,40)
oled.text("SENSOR",50,50)
# Finally update the oled display so the image & text is displayed
oled.show()
utime.sleep(4)
while True:
    oled.fill(0)
    measured_time = ultrasonnic()     
    distance_cm = (measured_time * 0.0343) / 2
    distance_cm = round(distance_cm,2)
    oled.text("<ObjectDistance>",0,8)
    oled.text(">> "+str(distance_cm)+" cm",2,25)
    oled.show()
    utime.sleep(1)   

Python Tutorials – பாடம் 9 – Ultrasonic Sensor Module using Raspberry Pi Pico

Ultrasonic sensor ஐ Raspberry Pi Pico உதவியுடன் கட்டுப்படுத்துவது

Required Components

  1. Raspberry Pi Pico board-1 no
  2. Ultrasonic sensor-1 no
  3. Data Cable-1 no
  4. Connecting wires-1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Ultrasonic sensorல் உள்ள ECHO மற்றும் TRIG பின்களை Raspberry Pi Pico வில் உள்ள GP15 மற்றும் GP14 பின்களுடன் இணைக்க வேண்டும்.
  3. Ultrasonic Sensor VCC மற்றும் Gnd சப்ளையை Raspberry Pi Pico VBus மற்றும் GND உடன் இணைக்க வேண்டும்.
  4. Python program ஐ சரி பார்க்க வேண்டும்.
  5. மின்சுற்றை சரி பார்க்க வேண்டும்.
  6. Python program ஐ ரன் செய்ய வேண்டும்.

Python Program

from machine import Pin
import utime
trigger = Pin(14, Pin.OUT)
echo = Pin(15, Pin.IN)
def ultra():
   trigger.low()
   utime.sleep_us(2)
   trigger.high()
   utime.sleep_us(5)
   trigger.low()
   while echo.value() == 0:
       signaloff = utime.ticks_us()
   while echo.value() == 1:
       signalon = utime.ticks_us()
   timepassed = signalon - signaloff
   distance = (timepassed * 0.0343) / 2
   print ('Distance:',"{:.0f}".format(distance),'cm')
while True:
   ultra()
   utime.sleep(1)

Arduino Tutorials – பாடம் 44 – Ultrasonic Sensor Module using Raspberry Pi Pico

Ultrasonic sensor ஐ Raspberry Pi Pico உதவியுடன் கட்டுப்படுத்துவது

Required Components

  1. Raspberry Pi Pico board-1 no
  2. Ultrasonic sensor-1 no
  3. Data Cable-1 no
  4. Connecting wires-1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Ultrasonic sensorல் உள்ள ECHO மற்றும் TRIG பின்களை Raspberry Pi Pico வில் உள்ள GP15 மற்றும் GP14 பின்களுடன் இணைக்க வேண்டும்.
  3. Ultrasonic Sensor VCC மற்றும் Gnd சப்ளையை Raspberry Pi Pico VBus மற்றும் GND உடன் இணைக்க வேண்டும்.
  4. Arduino program ஐ சரி பார்க்க வேண்டும்.
  5. மின்சுற்றை சரி பார்க்க வேண்டும்.
  6. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#define echoPin 15 
#define trigPin 14 
long duration; 
int distance; 

void setup() {
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  Serial.begin(9600); 
  Serial.println("Ultrasonic Sensor HC-SR04 Test");
  Serial.println("with Arduino UNO R3");
}
void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);
  
  distance = duration * 0.034 / 2; 
  
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  delay(500);
}

Python Tutorials – Lesson 11 – Ultrasonic Sensor Module with OLED using Raspberry Pi Pico

To control Ultrasonic sensor with OLED using Raspberry Pi Pico

Required Components

  1. Ultrasonic sensor board_1 no
  2. OLED Display_1 no
  3. Raspberry Pi Pico board_1 no
  4. Data Cable_1 no
  5. Connecting Wires_8 no

Circuit

Steps

  1. Make sure the components are working properly.
  2. Ultrasonic Sensor board VCC, GND connected to VBus, GND of Raspberry Pi Pico Board.
  3. Connect Ultrasonic sensor Board echo, trigger pin to the Raspberry Pi Pico Board GP2, GP3 pin.
  4. OLED board VCC, GND connected to 3V3 (OUT), GND of Raspberry Pi Pico Board.
  5. OLED board SCL, SDA connected to GP16, GP17 of Raspberry Pi Pico Board.
  6. Check the Python program.
  7. Check the Electrical Circuit.
  8. Run the Python program.

Python Program

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import utime
trigger = Pin(3, Pin.OUT)
echo = Pin(2, Pin.IN)
def ultrasonnic():
    timepassed=0
    trigger.low()
    utime.sleep_us(2)
    trigger.high()
    utime.sleep_us(5)
    trigger.low()
    while echo.value() == 0:
        signaloff = utime.ticks_us()
    while echo.value() == 1:
        signalon = utime.ticks_us()
    timepassed = signalon - signaloff
    return timepassed
WIDTH  = 128                                            # oled display width
HEIGHT = 64                                            # oled display height
i2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=200000)       # Init I2C using pins GP8 & GP9 (default I2C0 pins)
print("I2C Address      : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c))                   # Display I2C config
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)                  # Init oled display
 # Clear the oled display in case it has junk on it.
oled.fill(0)
# Add some text
oled.text("CIRCUIT DIGEST",5,8)
oled.text("INTERFACING THE",5,30)
oled.text("ULTRASONNIC",28,40)
oled.text("SENSOR",50,50)
# Finally update the oled display so the image & text is displayed
oled.show()
utime.sleep(4)
while True:
    oled.fill(0)
    measured_time = ultrasonnic()     
    distance_cm = (measured_time * 0.0343) / 2
    distance_cm = round(distance_cm,2)
    oled.text("<ObjectDistance>",0,8)
    oled.text(">> "+str(distance_cm)+" cm",2,25)
    oled.show()
    utime.sleep(1)