Skip to content

Instantly share code, notes, and snippets.

View futureshocked's full-sized avatar

Peter Dalmaris futureshocked

View GitHub Profile
@futureshocked
futureshocked / potentiometer.ino
Created January 7, 2020 00:28
This sketch reads the value of a potentiometer and controls the brightness of an LED
int potentiometerPin = 0;
int ledPin = 11;
int potentiometerVal = 0;
void setup()
{
Serial.begin(9600); // setup serial
}
void loop()
@futureshocked
futureshocked / button.ino
Created January 6, 2020 23:50
This sketch reads the state of a button (pressed or unpressed) and turns on an LED when the button is pressed.
/*
Pushbutton sketch a switch connected to pin 2 lights the LED on pin 13
*/
const int ledPin = 13; // choose the pin for the LED
const int inputPin = 2; // choose the input pin (for a
// pushbutton)
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
@futureshocked
futureshocked / bme280_sensor.ino
Created January 6, 2020 05:59
This sketch uses a BME280 sensor to report temperature, humidity, and atmospheric pressure.
#include <Wire.h> //*Include the Wire library which allows to use the I2C interface*
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h> //*library to easily take readings from the sensor*
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; //*Declare the bpm variable, an easy to remember reference for the device*
unsigned long delayTime;
@futureshocked
futureshocked / pir_sensor.ino
Created January 6, 2020 05:54
This sketch reads the state of a PIR sensor
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
@futureshocked
futureshocked / distance.ino
Created January 6, 2020 05:49
This sketch uses an ultrasonic distance sensor to calculate the distance between the sensor and an object in front of it
#define trigPin 13
#define echoPin 12
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
@futureshocked
futureshocked / analog_acceleration.ino
Created January 6, 2020 05:44
With this sketch your Arduino can detect acceleration using an analog accelerometer
int x, y, z;
void setup()
{
Serial.begin(9600); // sets the serial port to 9600
}
void loop()
{
x = analogRead(0); // read analog input pin 0
@futureshocked
futureshocked / tilt.ino
Created January 6, 2020 05:39
Use this sketch to detect when your Arduino is tilted. Connect a tilt sensor to Analog pin 0 (A0)
int out;
void setup()
{
Serial.begin(9600); // sets the serial port to 9600
}
void loop()
{
out = analogRead(0); // read analog input pin 0
@futureshocked
futureshocked / light-sensor.ino
Created January 6, 2020 05:14
This sketch reads the light intensity values from a photo-resistor connected to pin A0 of an Arduino.
// the setup function runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
@futureshocked
futureshocked / line_sensor.ino
Created January 6, 2020 04:59
This sketch implements a simple line sensor for the Arduino
// Line Sensor Breakout - Analog
int out;
void setup()
{
Serial.begin(9600); // sets the serial port to 9600
}
void loop()
{
@futureshocked
futureshocked / fade_led.ino
Last active January 6, 2020 04:06
This sketch makes an LED connected to Arduino pin 9 to fade on and off
int led = 9; // the pin that the LED is attached to
int brightness = 0; // the bigger this number, the brighter the LED is
int fadeAmount = 5; // the bigger this number, the faster the the LED will fade on or off
// the setup routine runs once when you press reset:
void setup() {
pinMode(led, OUTPUT); // declare pin 9 to be an output:
}
// the loop routine runs over and over again forever: