Skip to content

Instantly share code, notes, and snippets.

@isaiah7p
Last active October 16, 2019 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaiah7p/b0586b3353e01105f2eaf911c09fadc9 to your computer and use it in GitHub Desktop.
Save isaiah7p/b0586b3353e01105f2eaf911c09fadc9 to your computer and use it in GitHub Desktop.
Reference Links
https://www.arduino.cc/reference/en/
1 ) Analog Signals
Read / Write
> Variable Resistors
> Led output < working with brightness
https://www.arduino.cc/reference/en/
analogRead()
analogWrite()
Accelerometer > 3 analog signals .
2) Digital Signal Read and Write
> Led On and Off as output
> Switch read as input
digitalRead()
pinMode()
> DHT 11 sensor - library
Google for "dht arduino library"
https://github.com/adafruit/DHT-sensor-library
https://github.com/adafruit/Adafruit_Sensor
3) I2C based Signal
> Sensor library <mpu6050>
Accelerometer Value
Gyroscope angles
>> https://github.com/jarzebski/Arduino-MPU6050
> LCD display i2c based .
https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
4) SPI Based Signals
> Nokia 5110
https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
5) Serial based
> sim based
https://www.elecrow.com/wiki/images/2/20/SIM800_Series_AT_Command_Manual_V1.09.pdf
https://github.com/cristiansteib/Sim800l
> GPS based Comunication .
https://github.com/mikalhart/TinyGPS
> Bluetooth Based - BLE Vs Bluetooth v4
6) PWM based
> Read data from Analog pins and write the value to Digital Pins .
---------------------------------------------------------------------------
7) Virtual Pins
> Some Virtual Values from Cloud and retrive them on Device .
-----------------------------------------------------------------------------
8) Servo Motors :
> 0 -180 degress
9) Relays <Control Electrical Appliances >
< digitalWrite() >
10) Solenoids :
Door lock
Control with relay and seperate power supply
Motor Driver
11) Water Flow meter :
no of litres of fluid which has passed through it
<Interrupt based >
https://github.com/sekdiy/FlowMeter
@isaiah7p
Copy link
Author

int pin=12;
void setup() {
// put your setup code here, to run once:
pinMode(pin,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(pin,HIGH);
delay(500);
digitalWrite(pin,LOW);
delay(500);
for(int i=0;i<255;i++){
analogWrite(pin, i);
delay(50);
}
delay(1000);

  for(int j=255;j>0;j--){
  analogWrite(pin, j);
  delay(50);
}
delay(1000);

}

@isaiah7p
Copy link
Author

// digital read and digital write values
int pin=12;
int inPin = 2;
int val = 0;
void setup() {
// put your setup code here, to run once:
pinMode(pin,OUTPUT);
pinMode(inPin,INPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

val=digitalRead(inPin);
Serial.println(val);
digitalWrite(pin,val);
delay(500);

}

@isaiah7p
Copy link
Author

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"
#include "pitches.h"
#define DHTPIN 2 // what digital pin we're connected to
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

if(t>30){
for (int thisNote = 0; thisNote < 8; thisNote++) {

// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);

}
}

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}

@isaiah7p
Copy link
Author

// pitches.h

/*************************************************

  • Public Constants
    *************************************************/

#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978

@isaiah7p
Copy link
Author

void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}

void loop() {
float sensor_volt;
float sensorValue;

sensorValue = analogRead(A2);
sensor_volt = sensorValue/1024*5.0;

// Serial.print(sensorValue);
Serial.print("sensor_volt = ");
Serial.print(sensor_volt);

if(sensor_volt>1){
    digitalWrite(13,HIGH);
    delay(2000);
     digitalWrite(13,LOW);
     delay(2000);
  }
Serial.println("V");
delay(1000);

}

@isaiah7p
Copy link
Author

// https://learn.adafruit.com/getting-started-with-myoware-muscle-sensor/code

void setup(){

Serial.begin(9600);

}
void loop(){
//Serial.println("Loop ");

int muscleSensorVal = analogRead(A10);

Serial.println(muscleSensorVal);
delay(1);

}

@isaiah7p
Copy link
Author

/* Sweep
by BARRAGAN http://barraganstudio.com
This example code is in the public domain.

modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo,myservo1,myservo2; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(7); // attaches the servo on pin 9 to the servo object
}

void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment