Expno8,9,10,11 Cs3691-Embedded Systems and Iot
Expno8,9,10,11 Cs3691-Embedded Systems and Iot
Expno8,9,10,11 Cs3691-Embedded Systems and Iot
EXP NO:
INTERFACING SENSORS WITH RASPBERRY PI
DATE
AIM:
To interface the IR sensor and Ultrasonic sensor with Raspberry Pico.
1 Thonny IDE 1
2 Raspberry Pi Pico Development Board 1
3 Jumper Wires few
4 Micro USB Cable 1
5 IR Sensor 1
6 Ultrasonic sensor 1
PROCEDURE
CS3691 EMBEDDED SYSTEMS AND IOT
CONNECTIONS:
PROGRAM:
IR Sensor:
from machine import Pin
from time import sleep
buzzer=Pin(16,Pin.OUT)
ir=Pin(15,Pin.IN)
while True:
ir_value=ir.value()
if ir_value== True:
print("Buzzer OFF")
buzzer.value(0)
else:
print("Buzzer ON")
buzzer.value (1)
sleep(0.5)
CS3691 EMBEDDED SYSTEMS AND IOT
CONNECTIONS:
ULTRASONIC SENSOR:
from machine import Pin, PWM
import utime
trigger = Pin(14, Pin.OUT)
echo = Pin(15, Pin.IN)
buzzer = Pin(16, Pin.OUT)
def measure_distance():
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()
while True:
dist = measure_distance()
print(f"Distance : {dist} cm")
if dist <= 10:
buzzer.value(1)
utime.sleep(0.01)
else:
buzzer.value(0)
utime.sleep(0.01)
utime.sleep(0.5)
CS3691 EMBEDDED SYSTEMS AND IOT
RESULT:
CS3691 EMBEDDED SYSTEMS AND IOT
AIM:
To write and execute the program to Communicate between Arduino and Raspberry PI
using any wireless medium (Bluetooth)
1 Thonny IDE 1
2 Raspberry Pi Pico Development Board 1
3 Arduino Uno Development Board 1
4 Jumper Wires few
5 Micro USB Cable 1
6 Bluetooth Module 2
PROCEDURE
CS3691 EMBEDDED SYSTEMS AND IOT
CONNECTIONS:
PROGRAM:
MASTER
ARDUINO:
#include<SoftwareSerial.h>
SoftwareSerial mySerial(2,3); //rx,tx
void setup() {
mySerial.begin(9600);
}
void loop() {
mySerial.write('A');
delay(1000);
mySerial.write('B');
delay(1000);
}
CS3691 EMBEDDED SYSTEMS AND IOT
CONNECTIONS:
SLAVE
RASPBERRY PI PICO
from machine import Pin, UART
uart = UART(0, 9600)
led = Pin(16, Pin.OUT)
while True:
if uart.any() > 0:
data = uart.read()
print(data)
if "A" in data:
led.value(1)
print('LED on \n')
uart.write('LED on \n')
elif "B" in data:
led.value(0)
print('LED off \n')
uart.write('LED off \n')
CS3691 EMBEDDED SYSTEMS AND IOT
RESULT:
CS3691 EMBEDDED SYSTEMS AND IOT
EXP NO:
CLOUD PLATFORM TO LOG THE DATA
DATE
AIM:
To set up a cloud platform to log the data from IoT devices.
1 Blynk Platform 1
CLOUD PLATFORM-BLYNK:
Blynk is a smart platform that allows users to create their Internet of Things applications without the
need for coding or electronics knowledge. It is based on the idea of physical programming & provides
a platform to create and control devices where users can connect physical devices to the Internet and
control them using a mobile app.
Step 1: Visit blynk.cloud and create a Blynk account on the Blynk website. Or you can simply sign
in using the registered Email ID.
Step 3: Give any name to the Template such as Raspberry Pi Pico W. Select ‘Hardware Type’ as
Other and ‘Connection Type’ as WiFi.
Select the device from a template that you created earlier and also give any name to the device. Click
on Create.
A new device will be created. You will find the Blynk Authentication Token Here. Copy it as it is
necessary for the code.
CS3691 EMBEDDED SYSTEMS AND IOT
From the widget box drag a switch and place it on the dashboard screen.
CS3691 EMBEDDED SYSTEMS AND IOT
Step 6:
On the switch board click on Settings and here you need to set up the Switch. Give any title to it and
Create Datastream as Virtual Pin.
Configure the switch settings as per the image below and click on create.
CS3691 EMBEDDED SYSTEMS AND IOT
With this Blynk dashboard set up, you can now proceed to program the Raspberry Pi Pico W board
to control the LED.
Step 7:
CS3691 EMBEDDED SYSTEMS AND IOT
To control the LED with a mobile App or Mobile Dashboard, you also need to setup the Mobile
Phone Dashboard. The process is similarly explained above.
Install the Blynk app on your smartphone The Blynk app is available for iOS and Android. Download
and install the app on your smartphone. then need to set up both the Mobile App and the Mobile
Dashboard in order to control the LED with a mobile device. The process is explained above.
RESULT:
CS3691 EMBEDDED SYSTEMS AND IOT
EXP NO: Log Data using Raspberry PI and upload it to the cloud
DATE platform
AIM:
To write and execute the program Log Data using Raspberry PI and upload it to the cloud
platform
PROCEDURE
CS3691 EMBEDDED SYSTEMS AND IOT
CONNECTIONS:
PROGRAM:
from machine import Pin, I2C, ADC
from utime import sleep_ms
from pico_i2c_lcd import I2cLcd
import time
import network
import BlynkLib
adc = machine.ADC(4)
i2c=I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR=i2c.scan()[0]
lcd=I2cLcd(i2c,I2C_ADDR,2,16)
wlan = network.WLAN()
wlan.active(True)
wlan.connect("Wifi_Username","Wifi_Password")
BLYNK_AUTH = 'Your_Token'
"Connection to Blynk"
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
lcd.clear()
CS3691 EMBEDDED SYSTEMS AND IOT
while True:
ADC_voltage = adc.read_u16() * (3.3 / (65536))
temperature_celcius = 27 - (ADC_voltage - 0.706)/0.001721
temp_fahrenheit=32+(1.8*temperature_celcius)
print("Temperature in C: {}".format(temperature_celcius))
print("Temperature in F: {}".format(temp_fahrenheit))
lcd.move_to(0,0)
lcd.putstr("Temp:")
lcd.putstr(str(round(temperature_celcius,2)))
lcd.putstr("C ")
lcd.move_to(0,1)
lcd.putstr("Temp:")
lcd.putstr(str(round(temp_fahrenheit,2)))
lcd.putstr("F")
time.sleep(5)
blynk.virtual_write(3, temperature_celcius)
blynk.virtual_write(4, temp_fahrenheit)
blynk.log_event(temperature_celcius)
blynk.run()
time.sleep(5)
RESULT: