Things of Internet Notes
Things of Internet Notes
Aim:
To interface LED, switch and buzzer with Raspberry pi.
Description :
Procedure :
Terminal Launch :
1. Open terminal.
2. Launch IDLE by typing.
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl + N
4. Type the code.
5. Save the code by FILE > SAVE or Ctrl + S.
6. To run your code RUN>RUN or Ctrl + F5.
Pin Diagram :
Code :
Button Press :
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP)
try:
while True:
button_state = GPIO.input(23)
if button_state == False:
GPIO.output(11,True)
GPIO.output(13,True)
print('Button Pressed...')
time.sleep(0.2)
else:
GPIO.output(13,False)
GPIO.output(11,False)
print('Button released')
except:
GPIO.cleanup()
Output :
Test Case – 1:
Even count :
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP)
count=0
try:
while True:
button_state = GPIO.input(23)
if button_state == False:
count = count + 1
if(count%2==0):
GPIO.output(11,True)
GPIO.output(13,True)
print(count)
time.sleep(1)
else:
GPIO.output(13,False)
GPIO.output(11,False)
time.sleep(1)
except:
GPIO.cleanup()
Output :
Test Case – 2 :
LED blink multiple times for single click :
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP)
try:
while True:
button_state = GPIO.input(23)
if button_state == False:
for i in range(0,8):
GPIO.output(11,True)
GPIO.output(13,True)
time.sleep(0.2)
GPIO.output(13,False)
GPIO.output(11,False)
time.sleep(0.2)
except:
GPIO.cleanup()
Output :
Test Case – 3 :
Alternate LED glow :
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP)
try:
while True:
button_state = GPIO.input(23)
if button_state == False:
for i in range(0,5):
GPIO.output(11,True)
GPIO.output(13,True)
time.sleep(1)
GPIO.output(13,False)
GPIO.output(11,False)
time.sleep(1)
GPIO.output(15,True)
GPIO.output(13,True)
time.sleep(1)
GPIO.output(15,False)
GPIO.output(13,False)
time.sleep(1)
except:
GPIO.cleanup()
Output :
Result :
Thus the implementation of the LED, switch and buzzer with Raspberry Pi
and interface board using python has been successfully completed.
AIM: To design an IoT application to illustrate the working of PIR in movement detection.
COMPONENTS NEEDED:
• Raspberry Pi/Arduino.
• HC-SR04 Module
• Jumper wires.
PROCEDURE:
1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN or Ctrl+F5.
7. Connect VCC to Pin 2 (VCC)
8. Connect GND to Pin 6 (GND)
9. TRIG to Pin 12 (GPIO18)
10. Connect ECHO to GPIO 24.
CODE:
while GPIO.input(ECHO)==0:
pulse_start = time.time()
while GPIO.input(ECHO)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration x 17150
distance = round(distance, 2)
print "Distance:",distance,"cm"
GPIO.cleanup()
OUTPUT:
RESULT:
Thus designed an application using PIR sensor and measured the distance.
COMPONENTS NEEDED:
• Raspberry Pi/Ardino.
• Traffic light sensor
• Jumper wires.
• Power supply.
PROCEDURE:
1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN>RUN or Ctrl+F5.
7. Connect three pins to GPIO 12 ,GPIO 16 and GPIO 23
8. Connect button to GPIO 19.
9. Connect ground to PIN 3
CODE:
try:
def lightTraffic(led1, led2, led3, delay ):
GPIO.output(led1, 1)
Print(“GREEN”)
time.sleep(delay)
GPIO.output(led1, 0)
GPIO.output(led2, 1)
Print(“YELLOW”)
time.sleep(delay)
GPIO.output(led2, 0)
GPIO.output(led3, 1)
Print(“RED”)
time.sleep(delay)
GPIO.output(led3, 0)
GPIO.setmode(GPIO.BCM)
ledGreen = 16
ledYellow = 12
ledRed = 23
GPIO.setup(ledGreen, GPIO.OUT)
GPIO.setup(ledYellow, GPIO.OUT)
GPIO.setup(ledRed, GPIO.OUT)
while True:
lightTraffic(ledGreen, ledYellow, ledRed, 1)
except KeyboardInterrupt:
print "You've exited the program"
finally:
GPIO.cleanup()
OUTPUT:
RESULT:
AIM:
COMPONENTS NEEDED:
● Raspberry Pi/Ardino.
● Interface board.
● Jumper wires.
● Power supply.
PROCEDURE:
1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN>RUN or Ctrl+F5.
7. Connect LED to pin GPIO 21 .
8. Connect ground to PIN 3
CODE:
Print(“DECREASING”)
for x in range(100,0,-1):
Print(x)
pwm.ChangeDutyCycle(x)
sleep(0.01)
# If keyboard Interrupt
except KeyboardInterrupt:
pass
pwm.stop
GPIO.cleanup()
OUTPUT:
RESULT:
AIM:
To control the rotation of a servo motor.
COMPONENTS NEEDED:
● Raspberry Pi/Ardino.
● Interface board.
● SJ 90
● Power supply.
PROCEDURE:
1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN>RUN or Ctrl+F5.
7. Connect orange wire to pin GPIO 21.
8. Connect red wire to GCC
9. Connect brown wire to ground
CODE:
print(“180 degree”)
time.sleep(1) # sleep 1 second
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()
OUTPUT:
RESULT:
The servo motor working was connected and rotated.
AIM:
COMPONENTS NEEDED:
● Raspberry Pi/Ardino.
● Interface board.
● Jumper wires.
● Power supply.
PROCEDURE:
1. Open Terminal
2. Launch IDLE IDE by typing
3. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
4. Type the code
5. Save the code by FILE>SAVE or Ctrl+S
6. To run your code RUN>RUN or Ctrl+F5.
7. Connect LED1 to pin GPIO 37.
8. Connect LED2 to pin GPIO 38.
CODE:
OUTPUT:
…led on
led off…
…led on
led off…
…led on
led off…
…led on
led off…
RESULT:
AIM:
COMPONENTS NEEDED:
● Raspberry Pi/Ardino.
● Interface board.
● Jumper wires.
● Power supply.
PROCEDURE:
9. Open Terminal
10. Launch IDLE IDE by typing
11. After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
12. Type the code
13. Save the code by FILE>SAVE or Ctrl+S
14. To run your code RUN>RUN or Ctrl+F5.
15. Connect LED1 to pin GPIO 37.
16. Connect LED2 to pin GPIO 38.
CODE:
import RPi.GPIO as GPIO
TouchPin = 11
LedPin = 12
def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output
GPIO.setup(TouchPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led
def loop():
while True:
if GPIO.input(TouchPin) == GPIO.LOW:
print ('Touch off')
GPIO.output(LedPin, GPIO.LOW) # led off
else:
print ('Touch on')
GPIO.output(LedPin, GPIO.HIGH) # led on
def destroy():
GPIO.output(LedPin, GPIO.HIGH) # led off
GPIO.cleanup() # Release resource
OUTPUT:
Touch off
Touch on
Touch off
Touch on
Touch off
Touch on
Touch off
Touch on
RESULT:
Thus understood the data collected from touch sensor.
AIM : To write a C program for the implementation of interfacing the \ DHT sensor with ESP32
to detect the room temperature and humidity.
DESCRIPTION :
The ESP32 kit, when integrated with the Arduino IDE, offers a powerful and accessible platform
for microcontroller development. At its core, the ESP32 boasts a dual-core processor, onboard
Wi-Fi, and Bluetooth capabilities, making it a versatile choice for IoT projects. This integration
simplifies programming and shields users from complex low-level tasks. The Arduino IDE offers
a rich ecosystem of libraries and examples that expedite project development. Moreover, it
provides essential features like the Serial Monitor for debugging, a straightforward code editor,
and hassle-free code uploads to the ESP32 board. Whether you’re a novice or an expert, this
combination empowers you to swiftly build innovative applications, connect to the internet, and
utilize a wide array of sensors and peripherals.
PROCEDURE:
• Connect the GPIO 4 of the ESP32 kit with the IO pin in the DHT sensor using the jumper
wires.
• Connect the Ground pin of the ESP32 kit with the GND Pin in the DHT sensor using the
jumper wires.
• Connect the +3.3v pin in the ESP32 kit with the +3.3v pin in the DHT sensor using the
jumper wires.
CIRCUIT DIAGRAM:
CODE :
#include “DHT.h”
#define DHTPIN 4 // Digital pin connected to the DHT sensor #define DHTTYPE DHT11
// DHT 11
DHT dht(DHTPIN, DHTTYPE);
Void setup()
{
Serial.begin(9600);
Serial.println(“DHT11 test!”);
pinMode(5,OUTPUT);
dht.begin();
}
Void loop()
{
Float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
If (isnan(h) || isnan(t))
{
Serial.println(“Failed to read from DHT sensor!”);
return;
}
Serial.println(“**************”);
Serial.print(“Humidity: “);
Serial.println(h);
Serial.print(“Temperature: “);
Serial.println(t);
RESULT :
Thus the implementation of interfacing the ESP32 kit with the DHT sensor to detect the current
room temperature and humidity has been successfully completed.
PIN CONFIGURATION:
ESP32
GPIO 2 BUZZER
CODE:
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error
Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#define BUZZER 2 BluetoothSerial SerialBT;
// Handle received and sent messages String message = "";
char incomingChar; void setup() {
pinMode(BUZZER, OUTPUT);
Serial.begin(115200);
SerialBT.begin("ESP32"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
if (SerialBT.available()){
char incomingChar = SerialBT.read(); if (incomingChar != '\n'){
message += String(incomingChar);
}
else{ message = "";
}
Serial.write(incomingChar);
}
// Check received message and control output accordingly if (message =="on"){
digitalWrite(BUZZER, HIGH);
}
else if (message =="off"){
digitalWrite(BUZZER, LOW);
}
delay(20);
}
OUTPUT:
RESULT: Thus buzzer control using Bluetooth has been implemented successfully.
CODE:
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) ||
!defined(CONFIG_BLUEDROID_ENABLED)
#errorBluetooth is not enabled! Please run `make menuconfig` to and enable it#endif
void loop() {
if (Serial.available()) { SerialBT.write(Serial.read());
if (SerialBT.available()) { Serial.write(SerialBT.read());
delay(20);
OUTPUT:
RESULT: Thus communication with ESP32 through Bluetooth has been implemented
successfully
TFT DISPLAY
PIN CONFIGURATION:
ESP32 TFT
GND GND
GPIO 12 CS
GPIO 14 RES
GPIO 13 A0
GPIO 21 SDA
3.3V VCC
CODE:
#define TFT_RST 14
#define TFT_DC 13
#define TFT_SCLK 22
#define TFT_MOSI 21
void setup(void) {
Serial.println("Initializing...");
tft.setTextWrap(true);
void loop()
{ tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ST7735_RED);
tft.setTextSize(2);
tft.println("Hello!");
delay(2000);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(2);
delay(1000);
tft.setTextColor(ST7735_GREEN);
tft.setTextSize(3);
tft.println("BYE!");
delay(2000);}
OUTPUT: