Ultrasonic Sensor for Water Level

Image.png
Image.png
Image.png
COMPONENTS:
-Arduino Uno
-Buzzer
-Relay
-Ultrasonic SR04

CODE:
#include <NewPing.h>
int Buzzer = 13;
int Relay = 10;
int val=0;
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
  Serial.begin(9600); // Open serial monitor at 9600 baud to see ping results
pinMode(Buzzer,OUTPUT); //Setup Buzzer pin as output pin
pinMode(Relay,OUTPUT); //Setup Relay pin as output pin
digitalWrite(Relay,LOW);
}
void loop() {
  delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  int sensorValue = uS / US_ROUNDTRIP_CM;
  Serial.print(“Ping: “);
  Serial.print(sensorValue); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println(“cm”);
  if (sensorValue < 15 and sensorValue !=0) {
digitalWrite(Buzzer,LOW);
delay(1000);
digitalWrite(Relay,LOW); // Pump OFF
  }
  if (sensorValue > 200 and sensorValue !=0) {
digitalWrite(Buzzer,HIGH);
delay(1000);
digitalWrite(Buzzer,LOW);
delay(1000);
digitalWrite(Relay,HIGH); // Pump ON
  }
}

Touch Sensor

Image.png
Image.png
COMPONENTS:
-Arduino Uno
-Buzzer
-KY-036 Touch Sensor

CODE:
int buzzer = 13;
int sensorPin = 2;
void setup ()
{
  pinMode (sensorPin, INPUT) ;
  pinMode (buzzer, OUTPUT);
  Serial.begin(9600);
}
void loop ()
{
int sensorValue = digitalRead(sensorPin);
  if (sensorValue == HIGH)
  {
    digitalWrite (buzzer, HIGH);
    Serial.println(sensorValue);
  }
  else
  {
    digitalWrite (buzzer, LOW);
    Serial.println(sensorValue);
  }
}

Hall Magnetic Sensor

Image.png
 
COMPONENTS:
-Arduino Uno
-KY-003  or KY-035 or KY-024 Hall Magnetic Sensor
KY-003 is better, KY-024 is the best

-Buzzer

CODE:
int buzzer = 13;
int sensorPin = A0;
int state = 0;
void setup ()
{
  pinMode (sensorPin, INPUT) ;
  pinMode (buzzer, OUTPUT);
  Serial.begin(9600);
}
void loop ()
{
state = analogRead(sensorPin);
  if (state < 500)
  {
    digitalWrite (buzzer, HIGH);
    Serial.println(state);
  }
  else
  {
    digitalWrite (buzzer, LOW);
    Serial.println(state);
  }
  delay(400);
}

Knock Sensor

Image.png
Image.png
COMPONENTS:
-Arduino Uno
-KY-031 Knock Switch
-Buzzer

CODE:
int buzzer = 13;
int sensorPin = 2;
void setup ()
{
  pinMode (sensorPin, INPUT) ;
  pinMode (buzzer, OUTPUT);
  Serial.begin(9600);
}
void loop ()
{
int vibration = digitalRead(sensorPin);
  if (vibration == LOW)
  {
    digitalWrite (buzzer, HIGH);
    Serial.println(vibration);
  }
  else
  {
    digitalWrite (buzzer, LOW);
    Serial.println(vibration);
  }
}

Reed Switch Sensor

SOURCE:
Image.png
Image.png
COMPONENTS:
-Arduino Uno
-KY-025 or KY-021 Reed Switch
NOTE:
KY-025 is better
-Buzzer

CODE:
int buzzer = 13;
int sensorPin = A0;
int sensorValue = 0;
void setup ()
{
  pinMode (sensorPin, INPUT) ;
  pinMode (buzzer, OUTPUT);
  Serial.begin(9600);
}
void loop ()
{
  sensorValue = analogRead(sensorPin);
  if (sensorValue < 50)
  {
    digitalWrite (buzzer, HIGH);
    Serial.println(sensorValue);
  }
  else
  {
    digitalWrite (buzzer, LOW);
    Serial.println(sensorValue);
  }
}

Line Tracking Sensor

Image.png
Image.png
COMPONENTS:
-Arduino Uno
-KY-033 Line Tracing Sensor
-Buzzer

CODE:
int buzzer = 13;
int Sensor = A0;
int sensorValue = 0;
void setup () {
  pinMode (buzzer, OUTPUT);
  Serial.begin (9600);
}
void loop () {
  sensorValue = analogRead (Sensor);
  if (sensorValue < 50&& sensorValue < 500)
  {
  digitalWrite (buzzer, HIGH);
  Serial.println (sensorValue, DEC);
  }
  else (sensorValue > 500&& sensorValue > 1023);
  {
  digitalWrite (buzzer, LOW);
  Serial.println (sensorValue, DEC);
  }
}

Obstacle Avoidance Sensor

Image.png
Image.png
COMPONENTS:
-Arduino Uno
-KY-032 Obstacle Avoidance Sensor
NOTE: GND pin as shown on the picture is the correct one. Mine is printed on the opposite direction
-Buzzer
-RGB LED

CODE:
int Buzzer = 3;
int AvoidancePin = 4; // define the obstacle avoidance sensor interface
int RedLed = 5 ;
int GreenLed = 6 ;
int val ;// Value High or LOW.
// here i set up the tones, you can change them @ void loop.
int tones[] = {261, 277, 293, 311, 329, 349, 369, 392, 415, 440, 466, 493, 523 ,554};
//              1    2    3    4    5    6    7    8    9    10   11   12   13   14
// You can add more tones but i added 14. Just fill in what tone you would like to use, @ void loop you see ” tone(Buzzer, tones[12]); ” below,  digitalWrite(Buzzer, HIGH);
// here you can change the tones by filling in a number between 1 and 14
void setup ()
{
  Serial.begin (9600);
  pinMode (RedLed, OUTPUT) ;
  pinMode (GreenLed, OUTPUT) ;
  pinMode (Buzzer, OUTPUT) ;
  pinMode (AvoidancePin, INPUT) ;// define the obstacle avoidance sensor output interface
}
void loop ()
{
  val = digitalRead (AvoidancePin) ;// Reading from the AvoidancePin
  if (val == HIGH)
  {
    digitalWrite (RedLed, LOW);
    digitalWrite (GreenLed, HIGH);
    digitalWrite (Buzzer, LOW);
    noTone(Buzzer);
    delay(100);
  }
  else
  {
    digitalWrite (RedLed, HIGH);
    digitalWrite (GreenLed, LOW);
    digitalWrite (Buzzer, HIGH);
    tone(Buzzer, tones[6]);//You can change the tone choosing from 1 to 14.
    delay(100);
  }
}

Temperature and Humidity Sensor

20171228 15.46
lcd
20171228 16.26
COMPONENTS:
-Arduino Uno
-LCD i2c
-DHT Humidity Sensor

Open Arduino IDE
Go to Sketch/Include Library/Add .ZIP Library and open LiquidCrystal_I2C.zip file
-Download and install DHT library from
CODE:
//DHT11 Sensor:
#include “DHT.h”
#define DHTPIN 2     // what digital pin we’re connected to
#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);
//I2C LCD:
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
// Set the LCD I2C address
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
  lcd.begin(16, 2);
  Serial.println(“Temp and Humidity Sensor Test”);
  dht.begin();
}
void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  lcd.clear();
  // set the cursor to (0,0):
  lcd.setCursor(0, 0);
  // print from 0 to 9:
  lcd.print(“Temp: “);
  lcd.print(t);
  lcd.print((char)223);
  lcd.print(“C”);
  // set the cursor to (16,1):
  lcd.setCursor(0, 1);
  lcd.print(“Humidity: “);
  lcd.print(h);
  lcd.print(“%”);
  delay(1000);
  Serial.print(“Temp: “);
  Serial.print(t);
  Serial.print(“C, Humidity: “);
  Serial.print(h);
  Serial.println(“%”);
}

Capacitance Meter

Image.png
COMPONENTS:
-Arduino Uno
-LCD i2c
-1x Resistor 10k ohm
-1x Resistor 220 ohm
Open Arduino IDE

Go to Sketch/Include Library/Add .ZIP Library and open LiquidCrystal_I2C.zip file

CODE:
//LCD config
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);  //sometimes the adress is not 0x3f. Change to 0x27 if it dosn’t work.
#define analogPin      0
#define chargePin      13
#define dischargePin   8
#define resistorValue  10000.0F  //Remember, we’ve used a 10K resistor to charge the capacitor
unsigned long startTime;
unsigned long elapsedTime;
float microFarads;
float nanoFarads;
void setup(){
  pinMode(chargePin, OUTPUT);
  digitalWrite(chargePin, LOW);
  lcd.init();
  lcd.backlight();
}
void loop(){
  digitalWrite(chargePin, HIGH);
  startTime = micros();
  while(analogRead(analogPin) < 648){
  }
  elapsedTime= micros() – startTime;
  microFarads = ((float)elapsedTime / resistorValue) ;
  if (microFarads > 1){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(“SCALE:  0.1uF-4F”);
    lcd.setCursor(0,1);
    lcd.print(microFarads);
    lcd.setCursor(14,1);
    lcd.print(“uF”);
    delay(500);
  }
  else{
    nanoFarads = microFarads * 1000.0;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(“SCALE:  0.1uF-4F”);
    lcd.setCursor(0,1);
    lcd.print(nanoFarads);
    lcd.setCursor(14,1);
    lcd.print(“nF”);
    delay(500);
  }
  digitalWrite(chargePin, LOW);
  pinMode(dischargePin, OUTPUT);
  digitalWrite(dischargePin, LOW);     //discharging the capacitor
  while(analogRead(analogPin) > 0){
  }//This while waits till the capaccitor is discharged
  pinMode(dischargePin, INPUT);      //this sets the pin to high impedance
  lcd.setCursor(0,0);
  lcd.print(“DISCHARGING…..”);
  lcd.setCursor(0,1);
}
PROBLEMS:
1. Code above only allow to test capacitor from 0.1-4000uf.
Below 0.1uf it won’t be accurate.
I don’t know yet, how to modify above code to accept capacitor below 0.1uf based on below code.
http://electronoobs.com/images/Arduino/tut_10/Arduino_capacitance_meter_all_in_one.zip

Heart Beat Sensor

Image.png

COMPONENTS:
-1x Arduino
-1x Heart Beat Sensor

CODE:
————————————————————-
1) This shows a live human Heartbeat Pulse.
2) Live visualization in Arduino’s Cool “Serial Plotter”.
3) Blink an LED on each Heartbeat.
4) This is the direct Pulse Sensor’s Signal.
5) A great first-step in troubleshooting your circuit and connections.
6) “Human-readable” code that is newbie friendly.”
*/
// Variables
int sensorPin = A0; // Pulse Sensor connected to ANALOG PIN 0
int led = 13; // The on-board Arduino LED
int Signal; // holds the incoming raw data. Signal value can range from 0-1023
int Threshold = 550; // Determine which Signal to “count as a beat”, and which to ingore.
// The SetUp Function:
void setup() {
pinMode(sensorPin,INPUT);
pinMode(led,OUTPUT); // pin that will blink to your heartbeat!
Serial.begin(9600); // Set’s up Serial Communication at certain speed.
}
// The Main Loop Function
void loop() {
Signal = analogRead(sensorPin); // Read the PulseSensor’s value.
// Assign this value to the “Signal” variable.
Serial.println(Signal); // Send the Signal value to Serial Plotter.
if(Signal > Threshold){ // If the signal is above “550”, then “turn-on” Arduino’s on-Board LED.
digitalWrite(led,HIGH);
} else {
digitalWrite(led,LOW); // Else, the signal must be below “550”, so “turn-off” this LED.
}
delay(10);
}