Skip to main content

Posts

Featured

Practical use of ultrasonic Sensor with ATMEGA328P and Raspberry PI

Practical use of Ultrasonic Sensor SR04 with ATMEGA328P and Raspberry PI Introduction I2C is a two-wire bus that is designed to be simple, reliable, and energy-efficient. It is often used to connect microcontrollers, sensors, and other peripherals. I2C is also widely used for communication between microcontrollers and external memory. In this article, we present an alternative to directly using the Raspberry PI GPio to control external devices. I2C makes it possible to consume external data using this communication method. We use an Arduino UNO as a slave I2C device, controlling the HC-SR04 Ultrasonic Sensor, and a Raspberry PI B+ as a master I2C device, consuming the Sensor Data. In addition, the code for both the ATMEGA328P and Raspberry PI B+ has been included. Connection Diagram ​ ​ Raspberry as I2C Master Code #!/usr/bin/env python ​ from smbus2 import SMBus , i2c_msg import time import struct ​ # bus = smbus.SMBus(1) ​ address = 0x0A ​ def read_float_from_arduino ( addres...

Latest Posts