PiClock/Documentation/Overview.md at master · n0bel/PiClock · GitHub
Download
RetroPi
Set up controls
Soldering, rewiring, heat shrink, exposure risk, grounding wire, voltmeter, simple and complex electrical issues, power supplies, batteries, power vs encoder, programming with voltage in mind, Bread board, alligator clips, rainbow cables, switches, resistors, capacitors,
CABLE AND HARNESS SPLICES (nasa.gov)
Is from this following resource
Inspectors (nasa.gov)
For our ending point to our electrical exploration we want to make a Weather Station to track the current weather on raspberry pi, Throughout this whole exploration we started with raspberry pi and we are also going to end with it.
Rasberry Pi Weather Station Final Goal Documentation
Testing
Tasks completed so far/info
Brainstorming
Coding
We want a app simple yet effective, it should have all the basic information a normal weather app has and maybe we will code some additional functionality to it if we have time.
We did a little bit of research and it appears
That we will be able to code a weather station on raspberry pi.
This is a simple raspberry pi weather station
This one is more similar to the one we are making
We can use a software on rasberry pi Called Thonny (Python)
Our other option is Geany1 Programming editor but that one was Might not be as good for coding a weather station
We have managed to run super tux2
Managed to connect the sensors but they wont work yet
We have managed to give the sensors power and make them run but we cannot communicate with them ( we cant ask/ see the info and the sensors cant send the info yet)
We have managed to make a sample code for the weather station. We haven't been able to get it to work yet because we do not have the necessary drivers and/or have incorrect code.
We are using Grove sensors, no one else has used them yet so we don’t even know if they
Will work for a weather station.
FIRST CODE ITERATION
import time
import math
from smbus2 import SMBus
import bme280
Day 1:
We spent all of today planning out what we should do and made subplans. We decided that we would do a more software-oriented project.
Day 2:
We started by getting some materials and researching them. We faced some issues with the os opening up even after we gave our raspberry pi power supply and a connnection to the HDMI port. We tried a second screen and it powered on but it was just a white screen.
Day 3:
We got the screen going and tried to fix something that was not broken. When the screen turned on, it displayed rainbow which we thought was an error. After a little while of waiting, turns out it was an error. The SD might have been corrupted. We might need to rescreen the SD card.
Day 4:
We finally turned it on. We accessed the internet.
Day 5:
We upgraded to a raspberry pi 4. We added a fan to the box to increase air flow. Raspberry pi 4 was a lot smoother. We also researched how to develop a program.
Day 6:
We researched how to develop a program and even got a program on raspberry 4. It was a simple helloworld program but it didn’t run. We even tried downloading excel and teams so it made it easier to access stuff. We even tried installing windows because linux was confusing but decided not to.
Day 7:
We tried to start developing the app. We asked chatgpt on what to do and it suggested some website we could go to to start the project but they were both paid. We decided to just start with visual studio code. We also found a video online that shows a simple html project that can help us. We also decided that a website was good enough.
Day 8:
We researched some more
Day 9:
We are setting up github so that we can start coding. We also finalized the ui design. We decided code.org was easier so we began uploading a csv file of the inventory into code.org so that we can start coding.
Day 10:
I made some good progress on code.org and Srihari made some progress watching youtube videos about different sites and ways we can code in case code.org doesn't work.
Day 11:
We kept making more progress
Day 12:
I finally finished the first best draft on code.org. I also finished the project.
Day 14:
Ideas:
Roomba between legs of table
Computer that tells you inventory
Computer that help you tell what an object you are looking for
Press a button to announce something to the class (goggles, headphones)
We decided to combine 2, 3, and 4 options together and make a software-like thing that can help the students/whoever uses the classroom. We also thought about adding a screensaver.
Materials: sus
Raspberry Pi
Monitor & Mouse (possibly touchscreen)
Wires
Laptop (to code)
External Camera for object recognition
Goal: Write a program that can run on raspberry pi 4.
Language: C and C++ but can run java.
HDMI monitors says NO SIGNAL [SOLVED] - Raspberry Pi Forums - We're trying to find some solutions from this raspberry pi forum
IMP
Grove Starter Kit for IoT based on Raspberry Pi | Seeed Studio Wiki
Video to help us start on the website
JavaScript Project | Create Product Search Engine/Bar/Filter in JavaScript
Create a Search Bar & Filter Table using JavaScript in Hindi
Create Search Bar Or Filter By JavaScript || With Source Code
Make a Search Bar with React (with API Calls) | Beginners Tutorial
Check: React Search Filter Tutorial Beginner to Advanced
Plan
Inventory
At first I had trouble setting up the Raspberry Pi OS. It had the default command prompt OS installed but I later had to get the Raspbian OS installed to get access to the internet and other things. Then I ran a set of commands to update the web browsers and the OS which were required to get the weather station working on the Raspberry Pi 3b+.
After finishing up with the updates, I used the command prompt to set the directory to the 'Downloads' folder.
I then cloned a GitHub link which had all the code needed to setup the Pi-Weather-Station. A new directory 'pi-weather-station' was created in the 'Downloads' folder
I moved into the directory and ran a command to import NodeSource which is a repository which contains packages for distributing Node.js binaries.
After finishing up with that I ran a command to install node.js which is a JavaScript runtime environment. It did not download properly due to an upgrade issue so I ran some commands to update it and then installed it.
I ran a command to start it and then it worked but with a lot of screen flickering which I assume to be a hardware issue.
It then asked
for the API keys of the Map, Weather and, Geolocation
We entered all the APIs. It shows the weather, time, and location but the map does not work properly.
10.28:
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import time
Define GPIO pins for the motor and other constants
MOTOR_PIN = 18
ALLOWED_TAG_ID = 1234567890 # Replace with the ID of the allowed tag
MOTOR_RUN_TIME = 5 # Adjust this to control how long the motor runs in seconds
try:
while True:
print("Hold a card near the reader")
id, text = reader.read()
print("ID: {0}\nText: {1}".format(id, text))
if id == ALLOWED_TAG_ID:
print("Access granted! Turning on the motor...")
GPIO.output(MOTOR_PIN, GPIO.HIGH)
# Let the motor run for a specified duration
time.sleep(MOTOR_RUN_TIME)
# Turn off the motor
GPIO.output(MOTOR_PIN, GPIO.LOW)
print("Motor turned off.")
else:
print("Access denied!")
finally:
GPIO.cleanup()
_____-
10.29:
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import time
import pygame
from pygame.locals import *
Define GPIO pins for the motor and other constants
MOTOR_PIN = 18
ALLOWED_TAG_ID = 1234567890 # Replace with the ID of the allowed tag
MOTOR_RUN_TIME = 5 # Adjust this to control how long the motor runs in seconds
pygame.init()
screen = pygame.display.set_mode((320, 240)) # Set your screen resolution
pygame.display.set_caption("RFID Access Control")
font = pygame.font.Font(None, 36) # Define the font
Function to display a message on the screen
def display_message(message):
screen.fill((0, 0, 0)) # Set background to black
text = font.render(message, True, (0, 255, 0)) # Green text
text_rect = text.get_rect(center=(160, 120)) # Center the text
screen.blit(text, text_rect)
pygame.display.flip() # Update the display
try:
while True:
display_message("Hold a card near the reader")
id, text = reader.read()
display_message(f"ID: {id}\nText: {text}")
if id == ALLOWED_TAG_ID:
display_message("Access granted! Turning on the motor...")
GPIO.output(MOTOR_PIN, GPIO.HIGH)
time.sleep(MOTOR_RUN_TIME)
GPIO.output(MOTOR_PIN, GPIO.LOW)
display_message("Motor turned off.")
time.sleep(2) # Display the message for 2 seconds
else:
display_message("Access denied!")
time.sleep(2) # Display the message for 2 seconds
finally:
pygame.quit()
GPIO.cleanup()
10.29
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import time
import pygame
from pygame.locals import *
Define GPIO pins for the motors, button, and other constants
MOTOR_PIN = 18
MOTOR2_PIN = 19
ALLOWED_TAG_ID = 1234567890 # Replace with the ID of the allowed tag
MOTOR_RUN_TIME = 5 # Adjust this to control how long the motors run in seconds
BUTTON_PIN = 17 # GPIO pin for the button
pygame.init()
screen = pygame.display.set_mode((320, 240)) # Set your screen resolution
pygame.display.set_caption("RFID Access Control")
font = pygame.font.Font(None, 36) # Define the font
Function to display a message on the screen
def display_message(message):
screen.fill((0, 0, 0)) # Set background to black
text = font.render(message, True, (0, 255, 0)) # Green text
text_rect = text.get_rect(center=(160, 120)) # Center the text
screen.blit(text, text_rect)
pygame.display.flip() # Update the display
Function to turn the second motor on for 5 seconds
try:
while True:
display_message("Hold a card near the reader")
id, text = reader.read()
display_message(f"ID: {id}\nText: {text}")
if id == ALLOWED_TAG_ID:
display_message("Access granted! Turning on the motor...")
GPIO.output(MOTOR_PIN, GPIO.HIGH)
time.sleep(MOTOR_RUN_TIME)
GPIO.output(MOTOR_PIN, GPIO.LOW)
display_message("Motor turned off.")
time.sleep(2) # Display the message for 2 seconds
else:
display_message("Access denied!")
time.sleep(2) # Display the message for 2 seconds
# Check if the button is pressed to control the second motor
if GPIO.input(BUTTON_PIN) == GPIO.LOW:
display_message("Button pressed! Turning on the second motor...")
turn_motor2_on()
display_message("Second motor turned off.")
class Ultrasonic
{
public:
Ultrasonic(int pin);
void DistanceMeasure(void);
double microsecondsToCentimeters(void);
double microsecondsToInches(void);
private:
int this_pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger.
long duration;// the Pulse time received;
};
Ultrasonic::Ultrasonic(int pin)
{
this_pin = pin;
}
/Begin the detection and get the pulse back signal/
void Ultrasonic::DistanceMeasure(void)
{
pinMode(this_pin, OUTPUT);
digitalWrite(this_pin, LOW);
delayMicroseconds(2);
digitalWrite(this_pin, HIGH);
delayMicroseconds(5);
digitalWrite(this_pin,LOW);
pinMode(this_pin,INPUT);
duration = pulseIn(this_pin,HIGH);
}
/The measured distance from the range 0 to 400 Centimeters/
double Ultrasonic::microsecondsToCentimeters(void)
{
return duration/29.0/2.0;
}
/The measured distance from the range 0 to 157 Inches/
double Ultrasonic::microsecondsToInches(void)
{
return duration/74.0/2.0;
}
Ultrasonic ultrasonic(2);
void setup()
{
Serial.begin(9600);
}
void loop()
{
double RangeInInches;
double RangeInCentimeters;
ultrasonic.DistanceMeasure();// get the current signal time;
RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches;
RangeInCentimeters = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters
Serial.println("The distance to obstacles in front is: ");
Serial.print(RangeInInches);//0~157 inches
Serial.println(" inch");
Serial.print(RangeInCentimeters);//0~400cm
Serial.println(" cm");
delay(1000);
}
/
YF‐ S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy: www.hobbytronics.co.uk
/
volatile int flow_frequency; // Measures flow sensor pulsesunsigned
int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
Config Pi
OctoPrint.org - Download & Setup OctoPrint Uses browser for master pi Needs slave pi to be connected to internet
Master needs IP of slave
Slave needs Octopi installed Also needs USB connector to the printer
OctoPi wont work for us with no USB prot on printer
Download Octopi to microSD using RaspPi imager for slave
RetroPie OS setup GitHub link: https://github.com/RetroPie/RetroPie-Setup
Quick start guide reference :https://www.pishop.us/raspberry-pi-projects/retropie-quick-start-guide/
Set up Octopi on browser For Master Pi
Another one https://www.petrockblock.com/2012/07/22/retropie-setup-an-initialization-script-for-retroarch-on-the-raspberry-pi/
Connect to 3D printer Only 1
viewer Robotics
Verify Connection
PiClock/Documentation/Overview.md at master · n0bel/PiClock · GitHub
Download RetroPi
Set up controls
Soldering, rewiring, heat shrink, exposure risk, grounding wire, voltmeter, simple and complex electrical issues, power supplies, batteries, power vs encoder, programming with voltage in mind, Bread board, alligator clips, rainbow cables, switches, resistors, capacitors,
CABLE AND HARNESS SPLICES (nasa.gov) Is from this following resource
Inspectors (nasa.gov)
For our ending point to our electrical exploration we want to make a Weather Station to track the current weather on raspberry pi, Throughout this whole exploration we started with raspberry pi and we are also going to end with it.
Rasberry Pi Weather Station Final Goal Documentation
Testing
Tasks completed so far/info
Brainstorming
Coding
We want a app simple yet effective, it should have all the basic information a normal weather app has and maybe we will code some additional functionality to it if we have time.
We did a little bit of research and it appears That we will be able to code a weather station on raspberry pi.
This is a simple raspberry pi weather station
This one is more similar to the one we are making
We can use a software on rasberry pi Called Thonny (Python)
Our other option is Geany1 Programming editor but that one was Might not be as good for coding a weather station
We have managed to run super tux2
Managed to connect the sensors but they wont work yet
We have managed to give the sensors power and make them run but we cannot communicate with them ( we cant ask/ see the info and the sensors cant send the info yet)
We have managed to make a sample code for the weather station. We haven't been able to get it to work yet because we do not have the necessary drivers and/or have incorrect code.
We are using Grove sensors, no one else has used them yet so we don’t even know if they Will work for a weather station.
FIRST CODE ITERATION
import time import math from smbus2 import SMBus import bme280
Define the I2C bus number
I2C_BUS = 1
Define the address of the BME280 sensor
BME280_ADDRESS = 0x76
Initialize the SMBus for the given I2C bus number
bus = SMBus(I2C_BUS)
Initialize the BME280 sensor
calibration_params = bme280.load_calibration_params(bus, BME280_ADDRESS)
Get the temperature, humidity, and pressure from the BME280 sensor
def get_sensor_data(): data = bme280.sample(bus, BME280_ADDRESS, calibration_params) temperature = data.temperature humidity = data.humidity pressure = data.pressure return temperature, humidity, pressure
Calculate altitude based on pressure
def calculate_altitude(pressure, sea_level_pressure=101325): altitude = 44330 * (1.0 - math.pow(pressure / sea_level_pressure, 0.1903)) return altitude
def main(): try: while True:
Read temperature, humidity, and pressure
if name == "main": main()
https://wiki.seeedstudio.com/Grove-Barometer_Sensor-BME280/
We figured out that these se
Start-up
Day 1: We spent all of today planning out what we should do and made subplans. We decided that we would do a more software-oriented project.
Day 2: We started by getting some materials and researching them. We faced some issues with the os opening up even after we gave our raspberry pi power supply and a connnection to the HDMI port. We tried a second screen and it powered on but it was just a white screen.
Day 3: We got the screen going and tried to fix something that was not broken. When the screen turned on, it displayed rainbow which we thought was an error. After a little while of waiting, turns out it was an error. The SD might have been corrupted. We might need to rescreen the SD card.
Day 4: We finally turned it on. We accessed the internet.
Day 5: We upgraded to a raspberry pi 4. We added a fan to the box to increase air flow. Raspberry pi 4 was a lot smoother. We also researched how to develop a program.
Day 6: We researched how to develop a program and even got a program on raspberry 4. It was a simple helloworld program but it didn’t run. We even tried downloading excel and teams so it made it easier to access stuff. We even tried installing windows because linux was confusing but decided not to.
Day 7: We tried to start developing the app. We asked chatgpt on what to do and it suggested some website we could go to to start the project but they were both paid. We decided to just start with visual studio code. We also found a video online that shows a simple html project that can help us. We also decided that a website was good enough.
Day 8: We researched some more
Day 9: We are setting up github so that we can start coding. We also finalized the ui design. We decided code.org was easier so we began uploading a csv file of the inventory into code.org so that we can start coding.
Day 10: I made some good progress on code.org and Srihari made some progress watching youtube videos about different sites and ways we can code in case code.org doesn't work.
Day 11: We kept making more progress
Day 12: I finally finished the first best draft on code.org. I also finished the project.
Day 14:
Ideas: Roomba between legs of table Computer that tells you inventory Computer that help you tell what an object you are looking for Press a button to announce something to the class (goggles, headphones)
Ideas Usability Usefulness Material Total Roomba 3 4 2 9 Computer inventory 3 4 4 11 Computer object-recognition 3 4 4 11 Button 4 3 4 11 1-4
We decided to combine 2, 3, and 4 options together and make a software-like thing that can help the students/whoever uses the classroom. We also thought about adding a screensaver.
Materials: sus Raspberry Pi Monitor & Mouse (possibly touchscreen) Wires Laptop (to code) External Camera for object recognition
Goal: Write a program that can run on raspberry pi 4. Language: C and C++ but can run java.
https://studio.code.org/projects/applab/1EePZ54Cp36S29Kli3z3vVKuJbBTCuUiDGS2lPYx6Zk
Research and notes: https://opensource.com/resources/raspberry-pi#:~:text=The%20Raspberry%20Pi%20operates%20in,suite%20of%20open%20source%20software - its main supported operating system, Pi OS, is open source and runs a suite of open source software.
HDMI monitors says NO SIGNAL [SOLVED] - Raspberry Pi Forums - We're trying to find some solutions from this raspberry pi forum
IMP Grove Starter Kit for IoT based on Raspberry Pi | Seeed Studio Wiki
Video to help us start on the website JavaScript Project | Create Product Search Engine/Bar/Filter in JavaScript Create a Search Bar & Filter Table using JavaScript in Hindi Create Search Bar Or Filter By JavaScript || With Source Code Make a Search Bar with React (with API Calls) | Beginners Tutorial
https://github.com/ShaunHalverson/InventoryManagementC-/blob/main/Form1.cs
Check: React Search Filter Tutorial Beginner to Advanced
Plan
Inventory
At first I had trouble setting up the Raspberry Pi OS. It had the default command prompt OS installed but I later had to get the Raspbian OS installed to get access to the internet and other things. Then I ran a set of commands to update the web browsers and the OS which were required to get the weather station working on the Raspberry Pi 3b+. After finishing up with the updates, I used the command prompt to set the directory to the 'Downloads' folder. I then cloned a GitHub link which had all the code needed to setup the Pi-Weather-Station. A new directory 'pi-weather-station' was created in the 'Downloads' folder I moved into the directory and ran a command to import NodeSource which is a repository which contains packages for distributing Node.js binaries.
After finishing up with that I ran a command to install node.js which is a JavaScript runtime environment. It did not download properly due to an upgrade issue so I ran some commands to update it and then installed it. I ran a command to start it and then it worked but with a lot of screen flickering which I assume to be a hardware issue. It then asked for the API keys of the Map, Weather and, Geolocation
We entered all the APIs. It shows the weather, time, and location but the map does not work properly.
10.28: import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 import time
Define GPIO pins for the motor and other constants
MOTOR_PIN = 18 ALLOWED_TAG_ID = 1234567890 # Replace with the ID of the allowed tag MOTOR_RUN_TIME = 5 # Adjust this to control how long the motor runs in seconds
Set up the GPIO mode
GPIO.setmode(GPIO.BCM) GPIO.setup(MOTOR_PIN, GPIO.OUT)
Initialize the RFID reader
reader = SimpleMFRC522()
try: while True: print("Hold a card near the reader") id, text = reader.read() print("ID: {0}\nText: {1}".format(id, text))
finally: GPIO.cleanup()
_____- 10.29: import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 import time import pygame from pygame.locals import *
Define GPIO pins for the motor and other constants
MOTOR_PIN = 18 ALLOWED_TAG_ID = 1234567890 # Replace with the ID of the allowed tag MOTOR_RUN_TIME = 5 # Adjust this to control how long the motor runs in seconds
Set up the GPIO mode
GPIO.setmode(GPIO.BCM) GPIO.setup(MOTOR_PIN, GPIO.OUT)
Initialize the RFID reader
reader = SimpleMFRC522()
Initialize pygame for the graphical display
pygame.init() screen = pygame.display.set_mode((320, 240)) # Set your screen resolution pygame.display.set_caption("RFID Access Control") font = pygame.font.Font(None, 36) # Define the font
Function to display a message on the screen
def display_message(message): screen.fill((0, 0, 0)) # Set background to black text = font.render(message, True, (0, 255, 0)) # Green text text_rect = text.get_rect(center=(160, 120)) # Center the text screen.blit(text, text_rect) pygame.display.flip() # Update the display
try: while True: display_message("Hold a card near the reader") id, text = reader.read() display_message(f"ID: {id}\nText: {text}")
finally: pygame.quit() GPIO.cleanup()
10.29 import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 import time import pygame from pygame.locals import *
Define GPIO pins for the motors, button, and other constants
MOTOR_PIN = 18 MOTOR2_PIN = 19 ALLOWED_TAG_ID = 1234567890 # Replace with the ID of the allowed tag MOTOR_RUN_TIME = 5 # Adjust this to control how long the motors run in seconds BUTTON_PIN = 17 # GPIO pin for the button
Set up the GPIO mode
GPIO.setmode(GPIO.BCM) GPIO.setup(MOTOR_PIN, GPIO.OUT) GPIO.setup(MOTOR2_PIN, GPIO.OUT) GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Initialize the RFID reader
reader = SimpleMFRC522()
Initialize pygame for the graphical display
pygame.init() screen = pygame.display.set_mode((320, 240)) # Set your screen resolution pygame.display.set_caption("RFID Access Control") font = pygame.font.Font(None, 36) # Define the font
Function to display a message on the screen
def display_message(message): screen.fill((0, 0, 0)) # Set background to black text = font.render(message, True, (0, 255, 0)) # Green text text_rect = text.get_rect(center=(160, 120)) # Center the text screen.blit(text, text_rect) pygame.display.flip() # Update the display
Function to turn the second motor on for 5 seconds
def turn_motor2_on(): GPIO.output(MOTOR2_PIN, GPIO.HIGH) time.sleep(MOTOR_RUN_TIME) GPIO.output(MOTOR2_PIN, GPIO.LOW)
try: while True: display_message("Hold a card near the reader") id, text = reader.read() display_message(f"ID: {id}\nText: {text}")
finally: pygame.quit() GPIO.cleanup()
Pin-layout Overviews
Highly Integrated Design MCU, LCD, WIFI, BT, IMU, Microphone, Speaker, microSD Card, Light Sensor, 5-Way Switch, Infrared Emitter (IR 940nm), Crypto-authentication Ready
Powered by Microchip ATSAMD51P19 ARM Cortex-M4F core running at 120MHz(Boost up to 200MHz) 4 MB External Flash, 192 KB RAM
Comprehensive Protocol Support SPI, I2C, I2S, ADC, DAC, PWM, UART(Serial)
Powerful Wireless Connectivity (supported only by Arduino) Powered by Realtek RTL8720DN Dual Band 2.4Ghz / 5Ghz Wi-Fi (802.11 a/b/g/n) BLE / BLE 5.0
USB OTG Support USB Host USB Client
Software Support Arduino MicroPython ArduPy AT Firmware
https://github.com/microsoft/IoT-For-Beginners/blob/main/1-getting-started/lessons/1-introduction-to-iot/wio-terminal.md
For software download - (Scroll down to software) - https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/
Detecting range: 3cm-4m
Best in 30 degree angle
Electronic brick compatible interface
5VDC power supply
Breadboard friendly
Dual transducer
Arduino library ready
include "Arduino.h"
class Ultrasonic { public: Ultrasonic(int pin); void DistanceMeasure(void); double microsecondsToCentimeters(void); double microsecondsToInches(void); private: int this_pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger. long duration;// the Pulse time received; }; Ultrasonic::Ultrasonic(int pin) { this_pin = pin; } /Begin the detection and get the pulse back signal/ void Ultrasonic::DistanceMeasure(void) { pinMode(this_pin, OUTPUT); digitalWrite(this_pin, LOW); delayMicroseconds(2); digitalWrite(this_pin, HIGH); delayMicroseconds(5); digitalWrite(this_pin,LOW); pinMode(this_pin,INPUT); duration = pulseIn(this_pin,HIGH); } /The measured distance from the range 0 to 400 Centimeters/ double Ultrasonic::microsecondsToCentimeters(void) { return duration/29.0/2.0; } /The measured distance from the range 0 to 157 Inches/ double Ultrasonic::microsecondsToInches(void) { return duration/74.0/2.0; }
Ultrasonic ultrasonic(2); void setup() { Serial.begin(9600); } void loop() { double RangeInInches; double RangeInCentimeters; ultrasonic.DistanceMeasure();// get the current signal time; RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches; RangeInCentimeters = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters Serial.println("The distance to obstacles in front is: "); Serial.print(RangeInInches);//0~157 inches Serial.println(" inch"); Serial.print(RangeInCentimeters);//0~400cm Serial.println(" cm"); delay(1000); }
/ YF‐ S201 Water Flow Sensor Water Flow Sensor output processed to read in litres/hour Adaptation Courtesy: www.hobbytronics.co.uk /
volatile int flow_frequency; // Measures flow sensor pulsesunsigned
int l_hour; // Calculated litres/hour unsigned char flowsensor = 2; // Sensor Input unsigned long currentTime; unsigned long cloopTime;
void flow () // Interrupt function
{ flow_frequency++; }
void setup() { pinMode(flowsensor, INPUT); digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up Serial.begin(9600); attachInterrupt(0, flow, RISING); // Setup Interrupt sei(); // Enable interrupts currentTime = millis(); cloopTime = currentTime; }
void loop () { currentTime = millis();// Every second, calculate and print litres/hour if(currentTime >= (cloopTime + 1000)) { cloopTime = currentTime; // Updates cloopTime // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour flow_frequency = 0; // Reset Counter Serial.print(l_hour, DEC); // Print litres/hour Serial.println(" L/hour"); } }
Hall Effect Sensor
Turbine Wheel with magnet
Compact, Easy to Install
High Sealing Performance
High Quality Hall Effect Sensor
RoHS Compliant
void setup() { Serial.begin(9600); }
void loop() { int value; value = analogRead(0); Serial.println(value); }
capacity g 500g
Output sensitivity mv/v 0.5±0.1
Nonlinearty %.F.S 0.05
Hysteresis %F.S 0.05
Repeatability %F.S 0.05
Creep(30min) %.F.S 0.05
Temperature effect on sensitivity %F.S/10℃ 0.05
Temperature effect on zero %F.S/10℃ 0.05
Zero Balance %F.S ±0.5
Input resistance Ω(ohms) 1120±10
Output resistance Ω(ohms) 1000±10
Insulation resistance MΩ(ohms) ≥2000
Recommended excitation voltage v 5v
Method of Connecting wire red: Exc + black: Exc –
green: Sig + white:Sig -
Long range
Wide angle
Low consumption
DC 3.0-5.5V power supplier
Input Voltage: DC3.0-5.5V
Current: 100uA(max)
Detecting distance: 9m(max)
Output signal: 0,3 VCC (Output high when motion detected)
Sentry Angle: 120°
Connector:3Pin 2.54mm pitch
Size: L36W26H21(mm)
/***/ /macro definitions of PIR motion sensor pin and LED pin/
define PIR_MOTION_SENSOR 8//Use pin 8 to receive the signal from the module
define LED 4//the Grove - LED is connected to D4 of Arduino
void setup() { pinsInit(); }
void loop() { if(isPeopleDetected())//if it detects the moving people? turnOnLED(); else turnOffLED(); } void pinsInit() { pinMode(PIR_MOTION_SENSOR, INPUT); pinMode(LED,OUTPUT); } void turnOnLED() { digitalWrite(LED,HIGH); } void turnOffLED() { digitalWrite(LED,LOW); } /***/ /Function: Detect whether anyone moves in it's detecting range/ /Return:-boolean, ture is someone detected./ boolean isPeopleDetected() { int sensorValue = digitalRead(PIR_MOTION_SENSOR); if(sensorValue == HIGH)//if the sensor value is HIGH? { return true;//yes,return ture } else { return false;//no,return false } }
Compact
High performance
High output
Easy to mount on PCB
Widely applicable
Timing sensors
Edge sensors
Micro floppy disc drivers
Level sensors of liquid