IOT Algo
IOT Algo
3. b. Display Random Numbers Over 4 Digit 7-Segment Display Using Raspberry pi.
# Import the RPi.GPIO library to control the Raspberry Pi's GPIO pins
import RPi.GPIO as GPIO
# Import the time library to introduce delays
import time
# Set the GPIO mode to use physical pin numbering (BOARD mode)
GPIO.setmode(GPIO.BOARD)
# Set up GPIO pin 18 as an output pin
GPIO.setup(18, GPIO.OUT)
Hardware Requirements :
a. Four LEDs
b. Four Resistors
c. Eight Jumper Wires
d. BreadBoard
Connection : Connect resistors and leds horizontally
Connect jumper wires to longer(positive)
leg of led to GPIO pins and
shorter (negative) pin to Ground pins according to code
while True:
# Get the current date and time
now = datetime.datetime.now()
hour = now.hour # Get the current hour
minute = now.minute # Get the current minute
second = now.second # Get the current second
# Create a list representing the current time in the format [HH, HH, MM, MM]
currenttime = [int(hour/10), hour%10, int(minute/10), minute%10]
while True:
# Generate a random 4-digit number in the format [AB, CD]
currenttime = [random.randint(0, 9), random.randint(0, 9), random.randint(0, 9),
random.randint(0, 9)]
# Pause for 1 second before updating the display with another random number
time.sleep(1)
4. Raspberry pi Based Oscilloscope.
Hardware Requirements :
1. ADS1115 ADC
2. Four Jumper Wires
Connection :
Steps/Prerequisites:
Step 1: Enable I2C
Run the following command from the terminal:
$ sudo raspi-config
In the configuration panel, select "Interface Options," then select "I2C" and enable it.
# Main loop
while True:
value = adc.get_last_result() # Read the last result from the ADC
print('Channel 0: {0}'.format(value)) # Print the ADC value to the console
time.sleep(0.5) # Pause for 0.5 seconds
val.append(int(value)) # Add the ADC value to the list
drawnow(makeFig) # Update the plot using the makeFig function
plt.pause(0.1) # Pause for 0.1 seconds to update the plot
cnt = cnt + 1 # Increment the counter
if cnt > 50:
val.pop(0)
# Remove the oldest ADC value from the list if it exceeds 50 values
5. Controlling Raspberry Pi Using Telegram.
Hardware Requirements :
a. Three LEDs
b. Three Resistors
c. Six Jumper Wires
d. Phone with telegram
Connection :
Connection :
Prerequisites/Workaround:
sudo apt update
sudo apt upgrade
pip install picamera
pip3 install picamera
sudo apt-get install python-picamera.
sudo apt-get install python3-picamera.
sudoraspi-config
Select Enable camera and Enable it
sudo reboot
To verify connection:
raspistill -o test.jpg
To connect the Pi Camera:
Insert the Ribbon cable of Pi Camera into camera slot,
slightly pull up the tabs of the connector at RPi board
and insert the Ribbon cable into the slot,
then gently push down the tabs again to fix the ribbon cable
# Import necessary libraries
import time
import picamera
try:
# Start the camera preview (displaying on the screen)
camera.start_preview()
# Set the baud rate for communication with the RFID reader to 9600
ser.baudrate = 9600
# Call the read_rfid function to read RFID data and store it in the 'id' variable
id = read_rfid()
# Read 12 bytes of data from the RFID reader and decode it as UTF-8
id = data.read(12).decode('utf-8')
except KeyboardInterrupt:
# Close the serial connection when the script is interrupted (e.g., with Ctrl+C)
data.close()