Skip to content

Instantly share code, notes, and snippets.

View sarful's full-sized avatar

Mr. Sarful hassan sarful

View GitHub Profile
<h1>Problem</h1>
You want to connect external electronics to your Raspberry Pi but don’twant to accidentally damage or break it and How to Keeping Your Raspberry Pi Safe.
<h3>Solution</h3>
Obey these simple rules to reduce the risk of damaging your Raspberry Pi when using the GPIO connector
<ul>
<li>Do not put more than 3.3V on any GPIO pin being used as an input.</li>
<li>Do not draw more than 16mA per output and keep the total for all</li>
<li>outputs below 50mA in total for an older 26-pin Raspberry Pi, and below 100mA on a 40-pin Raspberry Pi.</li>
<li>When using LEDs, 3mA is enough to light a red LED reasonably brightly with a 470Ω series resistor.</li>
<li>Do not poke at the GPIO connector with a screwdriver or any metal object when the Pi is powered up.</li>
@sarful
sarful / LED Chase Effect
Created June 5, 2020 12:54
:LED Chase Effect
byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Create
array for LED pins
int ledDelay = 65; // delay
between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
void setup() {
for (int x=0; x<10; x++) { // set all
pins to output
# Import libraries
import RPi.GPIO as GPIO
import time
# Set GPIO numbering mode
GPIO.setmode(GPIO.BOARD)
# Set pin 11 as an output, and define as servo1 as PWM pin
GPIO.setup(32,GPIO.OUT)
servo1 = GPIO.PWM(32,50) # pin 11 for servo1, pulse 50Hz
# Import libraries
import RPi.GPIO as GPIO
import time
# Set GPIO numbering mode
GPIO.setmode(GPIO.BOARD)
# Set pin 11 as an output, and set servo1 as pin 11 as PWM
GPIO.setup(22,GPIO.OUT)
servo1 = GPIO.PWM(22,50) # Note 11 is pin, 50 = 50Hz pulse
@sarful
sarful / Servo_Test.py
Last active June 2, 2020 03:33
SERVO TEST1
# Import libraries
import RPi.GPIO as GPIO
import time
# Set GPIO numbering mode
GPIO.setmode(GPIO.BOARD)
# Set pin 11 as an output, and set servo1 as pin 11 as PWM
GPIO.setup(32,GPIO.OUT)
servo1 = GPIO.PWM(32,50) # Note 11 is pin, 50 = 50Hz pulse
@sarful
sarful / Arduino Workshop-– Interactive Traffic Lights
Created May 30, 2020 15:33
Arduino Workshop-– Interactive Traffic Lights
int carRed = 12; // assign the car lights
int carYellow = 11;
int carGreen = 10;
int pedRed = 9; // assign the pedestrian lights
int pedGreen = 8;
int button = 2; // button pin
int crossTime = 5000; // time allowed to cross
unsigned long changeTime = 0; // time last pedestrian cycle
completed
void setup() {
create table attendance(
id INT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
user_id INT UNSIGNED NOT NULL,
clock_in TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ( id )
);
create table users(
id INT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
rfid_uid VARCHAR(255) NOT NULL,
import time
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import mysql.connector
db = mysql.connector.connect(
host="localhost",
#!/usr/bin/env python
import time
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="username",
passwd="your_password",
#!/usr/bin/env python
import time
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="username",
passwd="123",